How to solve this error?

조회 수: 25 (최근 30일)
Shaila parvin
Shaila parvin 2014년 3월 16일
댓글: Sakshi Singh 2021년 4월 26일
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
two-dimensional.
Error in imhist>parse_inputs (line 277)
validateattributes(a,
{'double','uint8','int8','logical','uint16','int16','single','uint32',
'int32'}, ...
Error in imhist (line 59)
[a, n, isScaled, top, map] =
parse_inputs(varargin{:});
Error in similar (line 10)
hn1 = imhist(Im1)./numel(Im1);
Can anyone please help me to solve this?

답변 (2개)

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

댓글을 달려면 로그인하십시오.


Saira
Saira 2020년 3월 30일
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'));
  댓글 수: 2
Saira
Saira 2020년 3월 30일
My Code is working well on MATLAB 2015a but when I run it on MATLAB 2017a, I got this error.
Sakshi Singh
Sakshi Singh 2021년 4월 26일
convert your input into logical value.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Images에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by