image processing problem in Salt and Pepper noise

조회 수: 21 (최근 30일)
Mohammad abu aqoulah
Mohammad abu aqoulah 2020년 6월 1일
답변: Image Analyst 2020년 6월 1일
i try to add Salt and Pepper noise after that try to use median filter to denoise it in this code but has a problem
code ;
I = imread('PicQ1.png');
figure ,imshow(I)
J = imnoise(I,'salt & pepper',0.05);
figure ,imshow(J)
M = medfilt2(J);
imshowpair(J,M,'montage')
--------------------------------------------
the proplem shown in pic attached

답변 (2개)

Image Analyst
Image Analyst 2020년 6월 1일
A better method is to use a modified median filter where you only replace the noise pixels with the median, not ALL pixels. This will prevent blurring and shape changing.

Sugar Daddy
Sugar Daddy 2020년 6월 1일
편집: Sugar Daddy 2020년 6월 1일
You are feeding a coloured image which is three dimensional ( RGB) while medfilt2 needs 2D data.
For example
I = imread('cameraman.tif');%default image
figure ,imshow(I);
J = imnoise(I,'salt & pepper',0.05);
M = medfilt2(J);% Now this will work because I is a gray scaled image
imshowpair(J,M,'montage')
Either change your rgb image to grayscale or apply medfilt2 on all three colours sequentialy
see the answer of image analyst below about how to apply median filter on coloured image
  댓글 수: 2
Mohammad abu aqoulah
Mohammad abu aqoulah 2020년 6월 1일
i try this code and work
clc
clear all
close all
I = imread('PicQ3.jpg');
subplot(2,2,1); imshow(I),title ('Original image')
J = imnoise(I,'salt & pepper',0.05);
subplot(2,2,2);imshow(J), title('Salt and Pepper" noise')
for (i=1:3)
M(:,:,i) = medfilt2(J(:,:,i),[3,3]);
end
subplot(2,2,3);imshow(M),title('after filtering')
Sugar Daddy
Sugar Daddy 2020년 6월 1일
If your issue is resolved please accept the answer

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

카테고리

Help CenterFile Exchange에서 Image Processing Toolbox에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by