how to denoising rgb image?

2 visualizaciones (últimos 30 días)
majid
majid el 10 de En. de 2022
Comentada: Bjorn Gustavsson el 11 de En. de 2022
hello i have a question about rgb image denoising. I have a noisy image and when i apply the filter ; the color of image is chang.i want to know why it is happen and how can i get rid of it it? here is my codes and results: clear all clc
exfilt={'*.jpg;*.png'};
[filename,filepath]= uigetfile(exfilt,'pick an image file!');
I=imread ([filepath filename]);
figure,imshow(I);
colormap(jet(256));colorbar;
title('Overlay Image');
[rows, columns, numberOfColorBands] = size(I);
%%adding noise
%speckle noise
SI=imnoise(I,'speckle',0.5);
% adding salt and pepper noise or shot noise
Shot_noise = imnoise(I, "salt & pepper", 0.50);
% total noise
noisy_image=I+SI+Shot_noise;
figure
subplot(1, 4, 1);
imshow(noisy_image);
title('noisy Image1');
% Extract the individual red, green, and blue color channels.
redChannel = noisy_image(:, :, 1);
greenChannel = noisy_image(:, :, 2);
blueChannel = noisy_image(:, :, 3);
% Display the noisy channel images.
subplot(1, 4, 2);
imshow(redChannel);
title('Noisy1 Red Channel');
subplot(1, 4, 3);
imshow(greenChannel);
title('Noisy1 Green Channel');
subplot(1, 4, 4);
imshow(blueChannel);
title('Noisy1 Blue Channel');
%%multiple level median image processing technique
k=2;
hwin=2*k+1;
im_redChannel= padarray(redChannel, [k k],'replicate'); % 'zero-padding'
im_greenChannel= padarray(greenChannel, [k k],'replicate'); % 'zero-padding'
imblueChannel= padarray(blueChannel, [k k],'replicate'); % 'zero-padding'
% imshow(im);
n=5;
[row,col] = size(im_redChannel);
% X Mask
x_diag_up=zeros(hwin,hwin);
x_diag_up(1:n+1:n*n)=1;
x_diag_down=zeros(hwin,hwin);
x_diag_down(n:n-1:n*n-1)=1;
%plus Mask
plus_up=zeros(hwin,hwin);
plus_up(:,3)=1;
plus_right=zeros(hwin,hwin);
plus_right(3,:)=1;
x_diag_up_find =find(x_diag_up); % x pixel positions
x_diag_down_find=find(x_diag_down); % x pixel positions
plus_up_find=find(plus_up); % + pixel position
plus_right_find=find(plus_right); % + pixel position
for p=1:row-4
for q=1:col-4
w_redChannel=im_redChannel(p:p+(hwin-1),q:q+(hwin-1));%sliding window / filter
sw_redChannel=w_redChannel(:)'; %sliding window elements
x_diag_up_val=w_redChannel(x_diag_up_find)';
x_diag_down_val=w_redChannel(x_diag_down_find)';
plus_up_val=w_redChannel(plus_up_find)';
plus_right_val=w_redChannel(plus_right_find)';
c_val=w_redChannel(13);
%Original pixel/ center pixel of the window/filter
M1=(median(x_diag_up_val));
M2=(median(x_diag_down_val));
M3=(median( plus_up_val));
M4=(median(plus_right_val));
median_val=[M1,M2,M3,M4];
minimum=min(median_val);
maximum=max(median_val);
M5=ceil(c_val);
Res_med=[minimum,maximum,M5];
out_redChannel(p,q)=(median(Res_med));
end
end
for p=1:row-4
for q=1:col-4
w_greenChannel=im_greenChannel(p:p+(hwin-1),q:q+(hwin-1));%sliding window / filter
sw_greenChannel=w_greenChannel(:)'; %sliding window elements
x_diag_up_val1=w_greenChannel(x_diag_up_find)';
x_diag_down_val1=w_greenChannel(x_diag_down_find)';
plus_up_val1=w_greenChannel(plus_up_find)';
plus_right_val1=w_greenChannel(plus_right_find)';
c_val1=w_greenChannel(13);
%Original pixel/ center pixel of the window/filter
MM1=(median(x_diag_up_val1));
MM2=(median(x_diag_down_val1));
MM3=(median( plus_up_val1));
MM4=(median(plus_right_val1));
median_val1=[MM1,MM2,MM3,MM4];
minimum1=min(median_val1);
maximum1=max(median_val1);
MM5=ceil(c_val1);
Res_med1=[minimum1,maximum1,MM5];
out_greenChannel(p,q)=(median(Res_med1));
end
end
for p=1:row-4
for q=1:col-4
w_blueChannel=imblueChannel(p:p+(hwin-1),q:q+(hwin-1));%sliding window / filter
sw_blueChannel=w_blueChannel(:)'; %sliding window elements
x_diag_up_val2=w_blueChannel(x_diag_up_find)';
x_diag_down_val2=w_blueChannel(x_diag_down_find)';
plus_up_val2=w_blueChannel(plus_up_find)';
plus_right_val2=w_blueChannel(plus_right_find)';
c_val2=w_blueChannel(13);
%Original pixel/ center pixel of the window/filter
MMM1=(median(x_diag_up_val2));
MMM2=(median(x_diag_down_val2));
MMM3=(median( plus_up_val2));
MMM4=(median(plus_right_val2));
median_val2=[MMM1,MMM2,MMM3,MMM4];
minimum2=min(median_val2);
maximum2=max(median_val2);
MMM5=ceil(c_val2);
Res_med2=[minimum2,maximum2,MMM5];
out_blueChannel(p,q)=(median(Res_med2));
end
end
restored_image = cat(3, out_redChannel, out_blueChannel, out_greenChannel);
figure
subplot(131)
imshow(I)
title(" Original image");
subplot(132)
imshow(noisy_image)
title(" noisy image");
subplot(133)
imshow(restored_image)
title(" restored image");

Respuesta aceptada

Bjorn Gustavsson
Bjorn Gustavsson el 10 de En. de 2022
Well nothing but a simple goof. You simply swapped the green and blue channels in this line:
restored_image = cat(3, out_redChannel, out_blueChannel, out_greenChannel);
Try:
restored_image = cat(3, out_redChannel, out_greenChannel, out_blueChannel);
That should be it.
HTH
  2 comentarios
majid
majid el 11 de En. de 2022
thankyou very much
Bjorn Gustavsson
Bjorn Gustavsson el 11 de En. de 2022
Glad it solved your problem.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Image Filtering and Enhancement en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by