How to solve this error?

71 views (last 30 days)
Shaila parvin
Shaila parvin on 16 Mar 2014
Commented: Sakshi Singh on 26 Apr 2021
I use R2013a. When I run this code it shows some errors. The code is:
% read two images
Im1 = imread('a.jpg');
Im2 = imread('b.jpg');
% convert images to type double (range from from 0 to 1 instead of from 0 to 255)
Im1 = im2double(Im1);
Im2 = im2double(Im2);
% Calculate the Normalized Histogram of Image 1 and Image 2
hn1 = imhist(Im1)./numel(Im1);
hn2 = imhist(Im2)./numel(Im2);
% Calculate the histogram error
f = sum((hn1 - hn2).^2);
f %display the result to console
The error is:
Error using imhist
Expected input number 1, I or X, to be
Error in imhist>parse_inputs (line 277)
'int32'}, ...
Error in imhist (line 59)
[a, n, isScaled, top, map] =
Error in similar (line 10)
hn1 = imhist(Im1)./numel(Im1);
Can anyone please help me to solve this?

Answers (2)

Dishant Arora
Dishant Arora on 16 Mar 2014
Your image must be a RGB image, See what it says:
imhist only excepts grayscale and indexed image not 3d images
  1 Comment
Prasad Kalane
Prasad Kalane on 16 Mar 2014
Check weather following commands run separately or not... >> I = imread('a.jpg'); >> imhist(I)
If not then convert it to gray

Sign in to comment.

Saira on 30 Mar 2020
How to solve this error?
Error using imwrite
(line 420)
Expected DATA to be one of these types: numeric, logical. Instead its type was vision.CascadeObjectDetector.
Error in Trainingcode (line 38)
imwrite(Mouth,strcat('E:\SVM\JAFFE Local Features\', int2str(i),int2str(j), '.tiff'));
Sakshi Singh
Sakshi Singh on 26 Apr 2021
convert your input into logical value.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by