# HSV colormap

조회 수: 11 (최근 30일)
Zeeshan 2011년 11월 24일
Just need to get a description of the following code. Actually an expert send me full length of codes however I am unable to understand these bits as I am unfamiliar with image processing. Kindly describe me if possible what this code means. Specially I have confusion in the 3rd and 5th line of the code
Ihsv = rgb2hsv(I);
S = Ihsv(:,:,2) .* ( (Ihsv(:,:,1) < 0.2) | (Ihsv(:,:,1) > 0.6) );
s=sort(S(:));
max_sat_ref = s( round(0.98*length(s)) );

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

### 답변 (2개)

Amith Kamath 2011년 11월 24일
When you convert a RGB image to HSV, in the 3rd dimension, the 'layers' in the image are hue, saturation and value in that order. So line 3 multiplies elementwise, the saturation with 1 if the hue for that pixel is either less than 0.2 or greater than 0.6, and 0 otherwise. Line 4 sorts the elements of S in ascending order, and hence you get a vector of length m*n, where your image is m by n. Now what line 5 does is it looks for the element of s which is 98% of the highest, and this value depends on the saturation value in those pixels that are selected by line 3. This is then stored in max_sat_ref!
##### 댓글 수: 2없음 표시없음 숨기기
Zeeshan 2011년 11월 24일
Thanks fpr your reply. However I am still bit confuse about the line 3. :
S = Ihsv(:,:,2) .* ( (Ihsv(:,:,1) < 0.2) | (Ihsv(:,:,1) > 0.6) );
What I understand from this line that in HSV (A, B,C) means A= Hue, B= Saturation and C= Value
why we put "2" in the start hsv and why we put "1" in the second and third hsv
Walter Roberson 2011년 11월 24일
For what-ever reason, the code wants to set the saturation to 0 at any location for which the hue is in the range 0.2 to 0.6, and to keep the original saturation for the points for which the hue is outside that range (i.e., is less than 0.2 or greater than 0.6)
We do not know the purpose of the original code so we cannot tell you _why_ it is doing this; we can only tell you what the effect of the code is.

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

Image Analyst 2011년 11월 25일
(Ihsv(:,:,1) < 0.2) | (Ihsv(:,:,1) > 0.6)
basically gives you a map of red and purple areas of your image. Hues less than 0.2 are red and greater than 0.6 are violet to purple to red. Exactly zero is pure red.
Then it's taking the saturation or chroma component which is the second layer and masking it by the red/purple areas because it multiplies the saturation image by the red/purple mask. So essentially you're getting a saturation image of ONLY the red and purple areas but not of any other hues. Saturation (also called chroma) is like how "pure" the color is. Pure red is highly saturated while pink is less saturated and gray has a saturation of zero. A vivid, deep blue is highly saturated while sky blue is less saturated and gray in not saturated. I'm not sure exactly what they plan on doing with this because you didn't share much code after that.
By the way HSV, LCH, RGB, and HSI are not "color maps" - but "color spaces."

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

### 카테고리

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

### Community Treasure Hunt

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

Start Hunting!

Translated by