به میوه ها ،الف) فیلتر میانگین گیری روی رنگ آبی اعمال می کنیم نویز تصویر از نوع گوسی می باشد؟
در این برنامه تمامی رنگ ها ی تصویر ،یکی یکی استخراج نموده تا درک بهتری از استخراج رنگ حاصل شود .سپس روی تمامی رنگ ها تک به تک نویز اعمال و درنهایت فیلتر را اعمال نموده ایم.
برنامه متلب :
[left]clc;clear;close all;
rgbImage= imread('peppers.png');
% Get the dimensions of the image. numberOfColorBands should be = 3.
[rows, columns, numberOfColorBands] = size(rgbImage);
% Display the original color image.
subplot(3, 4, 1);imshow(rgbImage);title('Original color Image');
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
% Display the individual red, green, and blue color channels.
subplot(3, 4, 2);imshow(redChannel);title('Red Channel');
subplot(3, 4, 3);imshow(greenChannel);title('Green Channel');
subplot(3, 4, 4);imshow(blueChannel);title('Blue Channel');
% Generate a noisy image.
% each color channel so the noise may be colored.
noisyRGB = imnoise(rgbImage,'gaussian',0,0.01);
subplot(3, 4, 5);imshow(noisyRGB);title('Image with gaussian Noise');
% Extract the individual red, green, and blue color channels.
redChannel = noisyRGB(:, :, 1);
greenChannel = noisyRGB(:, :, 2);
blueChannel = noisyRGB(:, :, 3);
% Display the noisy channel images.
subplot(3, 4, 6);imshow(redChannel);title('Noisy Red Channel');
subplot(3, 4, 7);imshow(greenChannel);title('Noisy Green Channel');
subplot(3, 4, 8);imshow(blueChannel);title('Noisy Blue Channel');
% Median Filter the channels:
redMF = medfilt2(redChannel, [3 3]);
greenMF = medfilt2(greenChannel, [3 3]);
blueMF = medfilt2(blueChannel, [3 3]);
% Find the noise in the red.
noiseImage = (redChannel == 0 | redChannel == 255);
% Get rid of the noise in the red by replacing with median.
noiseFreeRed = redChannel;
noiseFreeRed(noiseImage) = redMF(noiseImage);
% Find the noise in the green.
noiseImage = (greenChannel == 0 | greenChannel == 255);
% Get rid of the noise in the green by replacing with median.
noiseFreeGreen = greenChannel;
noiseFreeGreen(noiseImage) = greenMF(noiseImage);
% Find the noise in the blue.
noiseImage = (blueChannel == 0 | blueChannel == 255);
% Get rid of the noise in the blue by replacing with median.
noiseFreeBlue = blueChannel;
noiseFreeBlue(noiseImage) = blueMF(noiseImage);
% Reconstruct the noise free RGB image
rgbFixed = cat(3, noiseFreeRed, noiseFreeGreen, noiseFreeBlue);
subplot(3, 4, 9);imshow(rgbFixed);title('Restored Image');
[/left]
خروجی برنامه :