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

1 回表示 (過去 30 日間)
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:
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:
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 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 Center および File ExchangeHistograms についてさらに検索


Community Treasure Hunt

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

Start Hunting!

Translated by