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

15 views (last 30 days)
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);

Answers (3)

Wayne King
Wayne King on 19 Jul 2014
Edited: Wayne King on 19 Jul 2014
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 on 20 Jul 2014
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 on 20 Feb 2020
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!