hist() function: Error using .* Error in hist (line 78)

조회 수: 3 (최근 30일)
Marco
Marco 2013년 10월 30일
답변: Image Analyst 2013년 10월 30일
When trying to generate with the HIST function a histogram I get an error message and do not know what I have to modify in my simple data analysis approach in order to prevent this. The error message is:
Error using .*
Integers can only be combined with integers of the same class, or scalar doubles.
Error in hist (line 78)
xx = miny + binwidth*(0:x);
I load a TIF image into MATLAB 2013b (not having the Image Processing Toolbox, simply the MATLAB ore program, WinXP 32 bit) and receive the myimage variable of type "512x512x3 uint8"
myimage = imread(filename);
Trying to show a histogram produces the error message:
hist(myimage)
I then separated individual color channels to the variables R, G, and B, which result of type "512x512 uint8":
R= myimage(:,:,1);
G= myimage(:,:,2);
B= myimage(:,:,3);
Trying to show the histogram for one of these variables also produces the error message:
hist(R)
I tried to resample the content of a variable into a vector of type "262144x1 uint8", but still receive the same error message
test=R(:); hist(test)
Sorting then didn´t help neither:
test=sort(test); hist(test)
Neither worked finally changing the type of the variable:
test=int16(test); hist(test)
test=int8(test); hist(test)
What do I have to do, please, in order to get a histogram of the values of a color channel drawn, and especially, where am I not using the hist() function correctly? I am pretty sure that I do not completely understand what the error message wants to hint me to.

채택된 답변

Kevin Claytor
Kevin Claytor 2013년 10월 30일
It seems as though hist() prefers floating point values (single or double). Try;
hist(double(R(:))) % Histogram of red channel
Also, note that hist operates column-wise;
hist(double(R)) % column-wise histogram
  댓글 수: 1
Marco
Marco 2013년 10월 30일
Thanks, this indeed works and solved my problem!

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

추가 답변 (1개)

Image Analyst
Image Analyst 2013년 10월 30일
If you have the Image Processing Toolbox, use imhist(). But you can only use it on one color channel at a time.

카테고리

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

제품

Community Treasure Hunt

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

Start Hunting!

Translated by