# How can I create a noise reduction code?

조회 수: 1(최근 30일)
Mutlu Fatih Tutkun 2021년 5월 20일
답변: Prateek Rai 2021년 10월 12일
I studying in this code but it doesn't run. We can see only original picture. How can we fixed it?
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]);

댓글을 달려면 로그인하십시오.

### 답변(1개)

Prateek Rai 2021년 10월 12일
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 = 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]);
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!