Please Help I am trying to get my add noise to my color image and then filter it out. Filtered channels don't retain the original picture.
1 次查看(过去 30 天)
显示 更早的评论
function [Noise]=corrupt_it(MyImage);
MyImage = 'MainProjImage.tif'; % my image
I = imread(MyImage);%read the Image
mean_gauss = 0; %gaussian noise
var_gauss = 1000; %gaussian noise variance
J = imnoise(I,'gaussian',mean_gauss,var_gauss); % make some noise
Red=J;
Blue=J;
Green=J;
% only red channel
Red(:,:,2:3)=0;
%only blue channel
Blue(:,:,1)=0;
Blue(:,:,3)=0;
%only Green channel
Green(:,:,1:2)=0;
figure('name', 'Noise Corruption/Histogram');
subplot(4,3,1);imshow(Red); title('Red Gaussian Noise');%display noisy image.
subplot(4,3,2);imshow(Blue); title('Green Gaussian Noise');%display noisy image.
subplot(4,3,3);imshow(Green); title('Blue Gaussian Noise');%display noisy image.
%%Histogram
[yRed, x] = imhist(Red);
[yGreen, x] = imhist(Blue);
[yBlue, x] = imhist(Green);
subplot(4,3,4);plot(x, yRed, 'Red');axis([0 256 0 350]);title('Red Histogram');
subplot(4,3,5);plot(x, yGreen, 'Green');axis([0 256 0 350]);title('Green Histogram');
subplot(4,3,6);plot(x, yBlue, 'Blue');axis([0 256 0 350]);title('Blue Histogram');
%task 1C
B1 = imgaussfilt(Red,31.6227);
B2 = imgaussfilt(Blue,31.6227);
B3 = imgaussfilt(Green,31.6227);
subplot(4,3,7);imshow(B1); title('Filter Red Noise');
subplot(4,3,8);imshow(B2); title('Filter Green Noise');
subplot(4,3,9);imshow(B3); title('Filter Blue Noise');
red=B1(:,:,1);
blue=B2(:,:,2);
green=B3(:,:,3);
noisyImage(:,:,1)=red;
noisyImage(:,:,2)=green;
noisyImage(:,:,3)=blue;
noisyImage=uint8(noisyImage);
red1=noisyImage(:,:,1);
blue1=noisyImage(:,:,2);
green1=noisyImage(:,:,3);
FilterImage(:,:,1)=red1;
FilterImage(:,:,2)=blue1;
FilterImage(:,:,3)=green1;
FilterImage=uint8(FilterImage);
subplot(4,3,10);
imshow(FilterImage);
title('Filtered Image');
subplot(4,3,11);
imshow(I);
title('Original');
end
0 个评论
回答(1 个)
KALYAN ACHARJYA
2019-4-25
编辑:KALYAN ACHARJYA
2019-4-25
Change this one, beacuse Red. Green ..are not in grayscale, see in worksspace or whos Red
[yRed,x]=imhist(rgb2gray(Red));
[yGreen,x]=imhist(rgb2gray(Blue));
[yBlue, x]=imhist(rgb2gray(Green));
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!