# How can I create a noise reduction code?

2 ビュー (過去 30 日間)
Mutlu Fatih Tutkun 2021 年 5 月 20 日

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!

Translated by