My task is to acquire the frequency values of the H and S values of an image. Therefore, I'm trying to generate a HS histogram of an image. However, I looked up numerous sources and they all create the H and S histograms separately. To state my problem more clearly, how do I know the number of time the H and S values occur together as a pair? Can anyone point me to the right direction?
Thanks!

 Réponse acceptée

Image Analyst
Image Analyst le 7 Août 2014

0 votes

See my demo, attached.

9 commentaires

Joshua Jorel Lee
Joshua Jorel Lee le 7 Août 2014
Thanks! But I have a question. Are you specifically referring to the "Histogram of All Bands" portion of your code? From what I can tell, it's still getting the histogram of each of the H, S, and V values. What I need is a histogram that relates the H and S values, not their individual histograms.
I'm not sure if I'm making much sense, but what I plan to do is to characterize the color of an image based on those two values (H and S). So I need what my professor calls a HS histogram.
Image Analyst
Image Analyst le 7 Août 2014
Modifié(e) : Image Analyst le 12 Août 2014
You can create a 2D histogram by scanning the images
for col = 1 : columns
for row = 1 : rows
r = scaleFactor1 * h(row, column) + 1; % Arrays start at 1.
c = scaleFactor2 * s(row, column) + 1;
hist_hs(r, c) = hist_hs(r, c) + 1;
end
end
You might also like to look at the color frequency image: http://www.mathworks.com/matlabcentral/fileexchange/28164-color-frequency-image
Joshua Jorel Lee
Joshua Jorel Lee le 8 Août 2014
Modifié(e) : Joshua Jorel Lee le 8 Août 2014
I think that's just what I need. Thanks a lot! I assume that the scaleFactor would assume the maximum value from each of the channels?
Image Analyst
Image Analyst le 8 Août 2014
h and s are continuous. To get into an array, you have to digitize them. For example h and s goes from 0 to 1. If you want your 2D histogram image hist_hs to be 500 in the h direction and 300 in the s direction, you need to have scaleFactor1 be 500 and scaleFactor2 be 300. Of course you also have to preallocate hist_hs to be zeros(500,300) before the loop starts.
Joshua Jorel Lee
Joshua Jorel Lee le 12 Août 2014
How would you handle those 0 valued h and s values?
Image Analyst
Image Analyst le 12 Août 2014
Just ignore them. What needs to be "handled" about them?
Joshua Jorel Lee
Joshua Jorel Lee le 12 Août 2014
Modifié(e) : Joshua Jorel Lee le 12 Août 2014
Since you're using the h and s values as the locations for the frequency values in the new matrix, if I have a 0 value in my h or s vector, MATLAB won't allow the data to be stored.
Example: h(r,c) = 0 or s(r,c) = 0, then r or c will be 0. If I assign hist_hs(r,c), then MATLAB will throw an error.
Image Analyst
Image Analyst le 12 Août 2014
Adjust the scale factor and add 1. See my edited comment above.
Joshua Jorel Lee
Joshua Jorel Lee le 13 Août 2014
Thanks! I took the liberty of putting an if statement that would make the 0 values into 1 instead. Then I used a surf plot to see the result.

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by