What is the meaning of this error (Using function medfilt2)

18 次查看(过去 30 天)
Hi I am using medfilt2 function but the error below is generated. May I know what is the problem here ?
TIA
---------------------------
I = imread('Moon.jpg');
J = imnoise(I, 'salt & pepper', 0.15);
L = medfilt2(J, [3 3]);
subplot(1,3,1); imshow(I); title('input image')
subplot(1,3,2); imshow(J); title('noisy image')
subplot(1,3,3); imshow(L); title('noisy image')
??? Error using ==> iptcheckinput
Function ORDFILT2 expected its first input, A, to be
two-dimensional.
Error in ==> ordfilt2>ParseInputs at 135
iptcheckinput(A, {'numeric','logical'},
{'2d','real'}, mfilename, 'A', 1);
Error in ==> ordfilt2 at 51
[A,order,domain,s,padopt,msg] =
ParseInputs(varargin{:});
Error in ==> medfilt2 at 53
b = ordfilt2(a, order, domain, padopt);

回答(3 个)

Wayne King
Wayne King 2014-7-19
编辑:Wayne King 2014-7-19
You're likely trying to input a RGB image (3-D) to medfilt2. If you enter
size(J)
what is returned?
If the last number is 3, then that is a RGB image.
You can use rgb2gray to turn J into a 2-D matrix suitable for medfilt2

Image Analyst
Image Analyst 2014-7-20
When I use standard demo image moon.tif (which is grayscale) instead of moon.jpg, it works fine. Try your demo with that standard image - it's probably using some image you go that was saved as RGB. By the way, your last title should read
title('Denoised Image')

Ramzan Shahid khan
Ramzan Shahid khan 2020-2-20
image J is in RGB of 3-D matrix but medfit2 takes 2-D. So first convert the J image into 2-D with rgb2gray(J) function, then it will work fine.

Community Treasure Hunt

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

Start Hunting!

Translated by