Vous êtes sur la page 1sur 7

img = imread();

size(img)
imshow('C:\Users\awill anurang misra\Desktop\vaibhav\vaibhav\a.jpg')

%Actually, a color image is a combined image of 3 grayscale images. So, we can display
the individual RGB components of the image using the following script:
subplot(131);
imagesc(img(:,:,1));
title('Red');
subplot(132);
imagesc(img(:,:,2));
title('Green');
subplot(133);
imagesc(img(:,:,3));
title('Blue');
colormap gray
%imadjust() adjust image intensity values. It maps the values in intensity image of an input

to new values in output image. This increases the contrast of the output image.
img = imread('C:\Users\awill anurang misra\Desktop\vaibhav\vaibhav\a.jpg');
gray = rgb2gray(img);
imshow(gray);
>> img = imread('C:\Users\awillanurang misra\Desktop\vaibhav\vaibhav\a.jpg');
gray = rgb2gray(img);
adj_img = imadjust(gray, [0.3,0.7],[]);
subplot(121);
imshow(gray);
title('input');
subplot(122);
imshow(adj_img);
title('adjusted');

To save your new blue image, use the imwrite() command:


imwrite(blue_img, 'Blue4_BerkeleyTower.png', 'png');

im2bw() converts the grayscale image to a binary image. We'll use the adjusted image.
img = imread('ImageProcessing_1/Rachmaninoff.jpg');
gray = rgb2gray(img);
adj_img = imadjust(gray, [0.3,0.7],[]);
bw_img = im2bw(adj_img);
subplot(121);
imshow(adj_img);

title('input image');
subplot(122);
imshow(bw_img);
title('binary image');

Deblurring Images Using a Wiener Filter


Open this Example

This example shows how to use Wiener deconvolution to deblur images. Wiener deconvolution can be useful when the point-spread
function and noise level are either known or estimated.
Read Image

I = im2double(imread('cameraman.tif'));
imshow(I);
title('Original Image (courtesy of MIT)');

Simulate a Motion Blur


Simulate a blurred image that you might get from camera motion. Create a point-spread function, PSF, corresponding to the linear
motion across 31 pixels (LEN=31), at an angle of 11 degrees (THETA=11). To simulate the blur, convolve the filter with the
image using imfilter.

LEN = 21;
THETA = 11;
PSF = fspecial('motion', LEN, THETA);
blurred = imfilter(I, PSF, 'conv', 'circular');
imshow(blurred);
title('Blurred Image');

Restore the Blurred Image


The simplest syntax for deconvwnr is deconvwnr(A, PSF, NSR), where A is the blurred image, PSF is the pointspread function, and NSR is the noise-power-to-signal-power ratio. The blurred image formed in Step 2 has no noise, so we'll use 0
for NSR.

wnr1 = deconvwnr(blurred, PSF, 0);


imshow(wnr1);
title('Restored Image');

Simulate Blur and Noise


Now let's try adding noise.

noise_mean = 0;
noise_var = 0.0001;
blurred_noisy = imnoise(blurred, 'gaussian', ...
noise_mean, noise_var);
imshow(blurred_noisy)
title('Simulate Blur and Noise')

Restore the Blurred and Noisy Image: First Attempt


In our first restoration attempt, we'll tell deconvwnr that there is no noise (NSR = 0). When NSR = 0, the Wiener restoration filter
is equivalent to an ideal inverse filter. The ideal inverse filter can be extremely sensitive to noise in the input image, as the next
image shows:

wnr2 = deconvwnr(blurred_noisy, PSF, 0);


imshow(wnr2)
title('Restoration of Blurred, Noisy Image Using NSR = 0')

The noise was amplified by the inverse filter to such a degree that only the barest hint of the man's shape is visible.
Restore the Blurred and Noisy Image: Second Attempt
In our second attempt we supply an estimate of the noise-power-to-signal-power ratio.

signal_var = var(I(:));
wnr3 = deconvwnr(blurred_noisy, PSF, noise_var / signal_var);
imshow(wnr3)
title('Restoration of Blurred, Noisy Image Using Estimated NSR');

Simulate Blur and 8-Bit Quantization Noise


Even a visually imperceptible amount of noise can affect the result. Let's try keeping the input image in
instead of converting it to double.

uint8 representation

I = imread('cameraman.tif');
class(I)
ans =
uint8
If you pass a uint8 image to imfilter, it will quantize the output in order to return another uint8 image.

blurred_quantized = imfilter(I, PSF, 'conv', 'circular');


class(blurred_quantized)
ans =
uint8
Restore the Blurred, Quantized Image: First Attempt
Again, we'll try first telling deconvwnr that there is no noise.

wnr4 = deconvwnr(blurred_quantized, PSF, 0);


imshow(wnr4)
title('Restoration of blurred, quantized image using NSR = 0');

Restore the Blurred, Quantized Image: Second Attempt


Next, we supply an NSR estimate to deconvwnr.

uniform_quantization_var = (1/256)^2 / 12;

signal_var = var(im2double(I(:)));
wnr5 = deconvwnr(blurred_quantized, PSF, ...
uniform_quantization_var / signal_var);
imshow(wnr5)
title('Restoration of Blurred, Quantized Image Using Computed NSR');

Vous aimerez peut-être aussi