Error in computing median filter and histogram equalization on an image. How can i solve it?
7 views (last 30 days)
Show older comments
I am trying to perform median filter on an image using simple median filter code like this
a = imread('1a.jpg');
figure; imshow (a)
b = imnoise(a,'salt & pepper',0.02);
figure; imshow (b)
c = medfilt2(b);
figure; imshow (c)
but i am getting this error:
Error using medfilt2
Expected input number 1, A, to be two-dimensional.
Error in medfilt2>parse_inputs (line 107)
validateattributes(a, ...
Error in medfilt2 (line 48)
[a, mn, padopt] = parse_inputs(varargin{:});
Error in medianFilter (line 11)
c = medfilt2(b);
Also when i tried to perform histogram equalization also using this code
a = imread('1a.jpg');
img_eq = histeq(a);
figure; imshow(img_eq);
I also get this error:
Error using histeq
Expected input number 1, I, to be two-dimensional.
Error in histeq (line 69)
validateattributes(a,{'uint8','uint16','double','int16','single'}, ...
Error in Histogramequalization (line 13)
img_eq = histeq(a);
How can i go about it pls.
Here are the two types of images i used.
0 Comments
Answers (1)
DGM
on 11 Dec 2024
Edited: DGM
on 13 Dec 2024
The image is a JPG, and most JPGs are RGB.
fname = 'https://www.mathworks.com/matlabcentral/answers/uploaded_files/280425/1a.jpg';
inpict = imread(fname); % RGB, uint8
size(inpict) % this is not a single-channel image
We can also look at metadata if that's not certain enough
S = imfinfo(fname);
S.ColorType % 24b RGB
S.NumberOfSamples % 3 channels
S.BitDepth % 8b x 3channels = 24b
If the image is nominally gray and is to be treated as gray, then just convert it using im2gray() (or rgb2gray() in older versions)
% the simple modern way
% im2gray() will convert RGB inputs and pass gray inputs
graypict1 = im2gray(inpict);
% but rgb2gray() will throw an error if it receives anything but a 3-ch image,
% so you have to do its input handling for it externally.
% if you're not going to use anything older than R2020b, just use im2gray().
if size(inpict,3) ~= 1
graypict2 = rgb2gray(inpict);
end
See also:
0 Comments
See Also
Categories
Find more on Image Filtering and Enhancement in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!