HSV colormap
3 次查看(过去 30 天)
显示 更早的评论
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
I=imread(finalname);
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)) );
0 个评论
回答(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 个评论
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."
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Purple 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!