0
I = imread('data1.jpg');
imshow(I)
J = imnoise(I,'salt%pepper',0.02);
figure,imshow(J)
K = filter2(fspecial('average',3),J)/255;
figure,imshow(K)
L = medfilt2(J,[3,3]);
figure,imshow(L)

I got this error when I run above code

"??? Error using ==> imnoise>ParseInputs at 231
Unknown noise type: 'salt%pepper'.

Error in ==> imnoise at 85
  [a, code, classIn, classChanged, p3, p4] = ParseInputs(varargin{:});

Error in ==> noisetry at 3
J = imnoise(I,'salt%pepper',0.02);"
Cœur
  • 37,241
  • 25
  • 195
  • 267

1 Answers1

0

Is your image black&white? If not convert it to B&W (JBW = rgb2gray(I)) and it should work. Function filter works only for 2 dimensional images.

I = imread('image.jpg');
imshow(I);
J = imnoise(I,'salt & pepper',0.02);
figure,imshow(J);
JBW = rgb2gray(I);
K = filter2(fspecial('average',3),JBW)/255;
figure,imshow(K);
L = medfilt2(JBW,[3,3]);
figure,imshow(L);