john not legend
john not legend

Reputation: 1

imhist matlab does not work

I am using MATLAB for image processing and when I run a simple example:

I=imread('img.png');
imhist(I)

it shows me this error: Error using imhist

Expected input number 1, I or X, to be two-dimensional.

Error in imhist>parse_inputs (line 278)
validateattributes(a,  {'double','uint8','int8','logical','uint16','int16','single','uint32', 
'int32'}, ...

Error in imhist (line 60)
[a, n, isScaled, top, map] = parse_inputs(varargin{:});

I am using an RGB image.

Upvotes: 0

Views: 487

Answers (1)

Jeru Luke
Jeru Luke

Reputation: 21203

imhist() would work only for gray scale images.

So first convert your RGB image to gray scale:

I=imread('img.png');
gray = rgb2gray(I);   #---Convert your image to gray scale

[Hist_Gray, x] = imhist(gray);    #---Obtain the histogram

plot(x, Hist_Gray, 'Gray');    #---Plot the histogram

Upvotes: 4

Related Questions