Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
566 views
in Technique[技术] by (71.8m points)

matlab - To categorize jet colormap by pixels of some colors

Data

enter image description here

I want to categorize it by counting the following pixels through HSV (Hue-Saturation-Lightness)

  • dark blue
  • blue
  • green
  • yellow
  • red

To show RGB channels (source) without HSV

x = linspace(0,1, size(Map)(1));
  figure(Fignr) 
  lw = 4; 
  plot( x, Map(:,1),'color',[1,0,0],'linewidth',lw,
        x, Map(:,2),'color',[0,1,0],'linewidth',lw, 
        x, Map(:,3),'color',[0,0,1],'linewidth',lw,
        x, mean(Map,2),'color',[0.7,0.7,0.7],'o') 
  xlabel 'fraction' 
  ylabel 'intensity' 
end

where example showRGBchannels(1,summer(500)) gives

enter image description here

This is just an example about one mapping where you can see fractions of different colors Red, Green and Blue about one figure. However, the color map must be extended to colors yellow, green and dark blue too.

You can assume that

  • dark blue has value [0, 0.2)
  • blue [0.2, 0.4)
  • green [0.4, 0.6)
  • yellow [0.6, 0.8)
  • red [0.8, 1.0)

However, I think this is not way to go, since HSV can a good choice here. I was also recommended to use other colors than Rainbow for the visualization (continuous red-blue, publication here).

There are many implementations to separate colors and argumentation about which color seem to use. Let's focus here on RGB colors and their separation. Possibly, through HSV or any other appropriate method not mentioned.

How can you categorize and count the appropriate pixels i.e. colours of the first picture through HSV? Any classes and/or papers for it?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Note Before reading. You seem to be confusing the choice of colormap with colour segmentation. It is important to note:

  • Colormap: used for user-friendly visualization. You don't use the colours of a colormap as data, you use the original data. However human eyes see more friendly a colour picture than a grayscale picture for example. Therefore there are different ways to visualize data with different choice of visualization colours. If your data is single valued (e.g. the figure you described represents z=f(x,y), then use the z for your data analysis, not the colour representation of the z).
  • Colour representation: In case you have some data that represents colours (i.e. a picture of a potato), then you can describe this data in different colour spaces, such as RGB, HSB, Cie Lab, ... This are ways of describing the same data, some useful for certain mathematicla calculations, some for other (i.e. HSV is good to segment colours while CIElab is designed to find colours that are similar for the human eye)

EDIT: ADDITIONAL DISCUSSION ABOUT USING COLORMAPS

As a student working in medical imaging, I can tell that for sure colours are NOT used for segmentation, but the numerical values of data (usually single channel) itself. The use of different colourmaps its only for visualization pourposes.

There are a wide range of opinions in here, but generally centred in: The jet colormap is not clear enough (and its the most widely used!). The Moreland colormaps for example, rely in having a clear midpoint in the visualization, so it is clear for the user to see which values are above the average and which below.

Even Matlab is starting to agree with the idea of stop using the jet colormap, as the default colormap of matlab is not any-more jet (R2014b). Read more here.

Another opinion is that the jet colormap does not translate good to gryscale. Read more here.

However, note that all this discussion has ABSOLUTELY nothing to do with how the colour is described. You can describe any of the colormaps discussed about in RGB, HSV, CIE Lab* or any other colour representation you'd want.


Original answer

So, rather than giving you code (that you can fin in SO also) I will just put an small example of how the HSV space work. As you have seen, in RGB, separating colours by their numerical values seems to be not possible. Therefore some other colour space is needed.

One of the most common approaches is to use the HSV space.

enter image description here

As you can see in the picture, this space has 3 values. Hue (the angle), Saturation and Value. Among the three of them, they create a cylindrical coordinate system, that points you to an specific color. From the figure, you can notice that while S and V change the "brightness" and "amount of colour" -like parameters, HUE is the only one that actually changes the chroma of the colour. So all Reds are in the same range of H, inddependently of the values of S and V.

See in the next figure a slice of this cylinder:

enter image description here

We can conclude from this image, that all yellow coloured values are around 30-90 degrees of H.

This information and the smart use of Matlab functions such as rgb2hsv should get you going in the right direction.

HINT: You want to do something with that 360-0 transaction for red coloured values.

Good luck!



与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...