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

2 visualizaciones (últimos 30 días)
Marco
Marco el 30 de Oct. de 2013
Respondida: Image Analyst el 30 de Oct. de 2013
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.

Respuesta aceptada

Kevin Claytor
Kevin Claytor el 30 de Oct. de 2013
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

Más respuestas (1)

Image Analyst
Image Analyst el 30 de Oct. de 2013
If you have the Image Processing Toolbox, use imhist(). But you can only use it on one color channel at a time.

Categorías

Más información sobre Histograms en Help Center y File Exchange.

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by