# How to denoise an image

4 views (last 30 days)
Maaz Madha on 3 Dec 2021
Commented: DGM on 3 Dec 2021
I am trying to denoise an image and so far have done this
As a res
%J=rgb2gray(I);
J=im2gray(I);
figure(1);
imhist(I);
ylim([0 1*10^4])
figure(2)
imhist(II)
ylim([0 1*10^4])
%% Median filter
average_1=fspecial('average',[3,3]);
filtered_image2=imfilter(I(250:end),average_1);
figure(5)
imhist(filtered_image2)
ylim([0 1*10^4])
%% Gaussian filter
G=imgaussfilt3(filtered_image2);%(I_filtered);
figure(4)
imhist(G)
ylim([0 1*10^4])
figure(5)
imshow(G)
%% Sharpening an image
% b=imsharpen(KK);
% figure(6)
% imhist(b)
% ylim([0 1*10^4])
% figure(7)
% imshow(b)
As a result, my processed image is (first_filter) but it is still not good and I wanted to know what I am doing wrong or how can I better improve it to come as close to the original.

DGM on 3 Dec 2021
This isn't a median filter. It's an average filter, and it's working on some arbitrary vectorized section of the image. Applying a 2D filter to a vector isn't going to accomplish anything of use here.
average_1=fspecial('average',[3,3]);
filtered_image2=imfilter(I(250:end),average_1);
If you want to do median filtering, try doing median filtering.
% Median filter
fs = 10;
medfiltpict = zeros(size(noisypict),class(noisypict));
for c = 1:size(noisypict,3)
% medfilt2() can't handle RGB
medfiltpict(:,:,c) = medfilt2(noisypict(:,:,c),[fs fs]);
end
imshow(noisypict)
imshow(medfiltpict)
##### 2 CommentsShowHide 1 older comment
DGM on 3 Dec 2021
Increasing the resolution isn't going to get you anything other than a bigger blurry image. You can try to mess around with imsharpen() to recover some edge emphasis, but I doubt that's going to be much help. You can try to use weiner2() instead of medfilt2().
The image looks like it's been upscaled about 400% after the noise was added, so you'll have to bear in mind that the information it represents is commensurate with a very tiny image.
noisypict = imnoise(cleanpict,'gaussian',0,0.005);
% Median filter
fs = 4;
outpict = zeros(size(noisypict),class(noisypict));
for c = 1:size(noisypict,3)
outpict(:,:,c) = medfilt2(noisypict(:,:,c),[fs fs]);
%outpict(:,:,c) = wiener2(noisypict(:,:,c),[fs fs]); % maybe mess with a weiner filter instead
end
outpict = imsharpen(outpict); % maybe mess with that
imshow(outpict)