Add and remove salt-and-pepper noise and Gaussian noise, and compare:
I=imread('eight.tif'); % Read in the image
subplot (2,3,1),imshow(I); % Display the original image
title('original'); % Set the image title
J=imnoise(I,'salt & pepper',0.2); % Add salt and pepper noise with a noise density D of 0.2
subplot(2,3,2),imshow(J); % Display the processed image
< p>title('noise image'); % Set image titletext(-20,320,'Salt & Pepper Noise filter');% Add description text
h=; % Template matrix
h=h/8; % Generate filter normalized template
K=conv2(J,h); % Use mean template to filter the image
subplot(2,3,3),imshow(K,[]); % Display the processed image
title('filter image'); % Set the image title
< p>I2=imread('eight.tif'); % Read the imagesubplot(2,3,4),imshow(I2); % Display the original image
title ('original'); % Set the image title
J2=imnoise(I2,'gaussian',0.2); % Add Gaussian noise with a mean of 0 and a variance of 0.2
subplot (2,3,5),imshow(J2); % Display the processed image
title('noise image'); % Set the image title
text(-20,320, 'gaussian Noise filter'); % Add description text
h=; % Template matrix
h=h/8; % Generate filter normalized template
< p>K2=conv2(J2,h); % Use the mean template to filter the imagesubplot(2,3,6),imshow(K2,[]); % Display the processed image
p>title('filter image'); % Set the image title
Histogram equalization
I = imread('tire.tif'); % Read the image
J = h
isteq(I); % Histogram equalization
imshow(I) % Display the original image
figure, imshow(J) % Display the processed image
figure; imhist(I,64) % original image histogram
figure; imhist(J,64) % processed image histogram