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!

 채택된 답변

Image Analyst
Image Analyst 2014년 8월 7일

0 개 추천

See my demo, attached.

댓글 수: 9

Joshua Jorel Lee
Joshua Jorel Lee 2014년 8월 7일
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 2014년 8월 7일
편집: Image Analyst 2014년 8월 12일
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 2014년 8월 8일
편집: Joshua Jorel Lee 2014년 8월 8일
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 2014년 8월 8일
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 2014년 8월 12일
How would you handle those 0 valued h and s values?
Image Analyst
Image Analyst 2014년 8월 12일
Just ignore them. What needs to be "handled" about them?
Joshua Jorel Lee
Joshua Jorel Lee 2014년 8월 12일
편집: Joshua Jorel Lee 2014년 8월 12일
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 2014년 8월 12일
Adjust the scale factor and add 1. See my edited comment above.
Joshua Jorel Lee
Joshua Jorel Lee 2014년 8월 13일
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.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by