MATLAB Answers

How can I create a noise reduction code?

5 views (last 30 days)
Mutlu Fatih Tutkun
Mutlu Fatih Tutkun on 20 May 2021
Answered: Prateek Rai on 12 Oct 2021
I studying in this code but it doesn't run. We can see only original picture. How can we fixed it?
f=imread('C:\Users\MFT\Desktop\tst.gif');
imshow(f),title('original image');
g =imnoise(f,'gaussian',0,0.1);
figure,imshow(g),title('noisy image')
h = fspecial('unsharp');
j =imfilter(g,h);
figure,imshow(j),title(' linear filtered image')
k = filter2(fspecial('average',3),g)/255;
figure,imshow(k),title('FIR filtered image')
l = medfilt2(g,[3 3]);
figure,imshow(l),title(' median filtered image')
m = wiener2(g,[5 5]);
figure, imshow(m),title('adaptive filtered image')

Answers (1)

Prateek Rai
Prateek Rai on 12 Oct 2021
To my understanding, you have created a noise reduction code but cannot see the output image.
The error is probably coming in line 8 of your code i.e.
k = filter2(fspecial('average',3),g)/255;
It is because this filter is in return using conv2 on RGB image which is not supported. Hence, you need to convert the RGB image to gray then perform the operations.
The code would look like:
f = imread("peppers.png");
f = rgb2gray(f); %% converting to grayscale
imshow(f),title('original image');
g =imnoise(f,'gaussian',0,0.1);
figure,imshow(g),title('noisy image')
h = fspecial('unsharp');
j =imfilter(g,h);
figure,imshow(j),title(' linear filtered image')
k = filter2(fspecial('average',3),g)/255;
figure,imshow(k),title('FIR filtered image')
l = medfilt2(g,[3 3]);
figure,imshow(l),title(' median filtered image')
m = wiener2(g,[5 5]);
figure, imshow(m),title('adaptive filtered image')
You can refer to rgb2gray MathWorks Documentation page to learn more on converting RGB image or colormap to grayscale.

Community Treasure Hunt

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

Start Hunting!