HSV colormap

2 visualizaciones (últimos 30 días)
Zeeshan
Zeeshan el 24 de Nov. de 2011
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)) );

Respuestas (2)

Amith Kamath
Amith Kamath el 24 de Nov. de 2011
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 comentarios
Zeeshan
Zeeshan el 24 de Nov. de 2011
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
Walter Roberson el 24 de Nov. de 2011
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.

Iniciar sesión para comentar.


Image Analyst
Image Analyst el 25 de Nov. de 2011
(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."

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by