2

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?

Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697

1 Answers1

6

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!


Community
  • 1
  • 1
Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
  • You can also point to some discussions about this topic so I can review them. I am interested in why there are so many different approaches and arguments towards each system, even in Medical imaging. To get an understanding why this system is better in some applications than Moreland is a target. I have an intuition that the choice of colors should not matter as long as the system is continuous. This RGB HUE can be about equal to Moreland (red-blue) -system. I have only seen this RGB system in Medical applications, which one evidence that this system works with HUE. I love the cylindrical form – Léo Léopold Hertz 준영 Feb 24 '15 at 09:26
  • 1
    @Masi I added extra discussion about the choice of colormaps. Note that the colour description and the colour choice are to different topics. Any colourmap (As the Moreland, or the jet) can be described using RGB, HSV ornything else. color description is performed to do maths with it, color choice is so the user can see it better. – Ander Biguri Feb 24 '15 at 09:48
  • Thank you for your addition! What is the name of the default colormap in Matlab R2014b. Is there any specification for it why it is chosen? – Léo Léopold Hertz 준영 Feb 24 '15 at 10:00
  • I have 1D ECG signal and its time-frequency plane in hot/jet -colormaps. I want to segment and count the number of different colors from the time-frequency plane of the hot/jet -colormap. I want to do first the analysis on jet -colormap. – Léo Léopold Hertz 준영 Feb 24 '15 at 10:03
  • 1
    @ The new colormap is called `parula`. If you follow the link I put in the question you can see why it was chosen. About the 1D ECG signal. It is of bad practise to use the visualization data (in jet colormap specially) for data analysis, as you are not going to obtain the real data out of it, just the visualization description of it. I HIGHLY reccomend you to use the original data, not the visualisation data, as your results won't be scientifically 100% correct. – Ander Biguri Feb 24 '15 at 10:14
  • @ Assume that you can return the original 99% of the original 1D signal from the time-frequency plane. The t-f plane also exposes nice frequency bands. Can you do such color calculations then on the t-f picture? Should I use the HUE method to count pixels in the t-f plot. How is the management of the uncertainty done? Let's assume for simplicity that you can return 100% of the 1D signal from t-f plane for simplicity. – Léo Léopold Hertz 준영 Feb 24 '15 at 10:25
  • @Masi Sorry I still don't understand the underlying problem. If you want to do any data analysis do not use color values. Assuming you could use them and that you'd start from The color values and you'd want to obtain the t-f values out of that, why don you use the dat of the colorbar you plotted next to the figure? you have a clear RGB->TF conversion. – Ander Biguri Feb 24 '15 at 10:33
  • Can you give an example how to do this "use the dat of the colorbar you plotted next to the figure - - you have a clear RGB->TF conversion." You mean to take a bandpass and plot that on a t-f figure. Can you give an example for this? – Léo Léopold Hertz 준영 Feb 24 '15 at 10:37
  • Another example can be to do this color-analysis from some geometric figure of the graph (etc the circle but also different shapes). How can you do this selection of the figure? Any graphical selection tool for this? And then lastly apply the t-f tool by color on the selection. – Léo Léopold Hertz 준영 Feb 24 '15 at 10:42
  • 1
    What I mean is: Do not use colours! 1.- convert all your data to real data, not colors. For that, use the colorbar. With `colomap('jet',500)` you can get the whole colormap. With that it should be straigthofrward to convert the data to single value. 2.-Then do whatever you want with the data – Ander Biguri Feb 24 '15 at 10:53