Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should I use HSV/HSB or RGB and why?

I have to detect leukocytes cells in an image that contains another blood cells, but the differences can be distinguished through the color of cells, leukocytes have more dense purple color, can be seen in the image below.

What color methode I've to use RGB/HSV ? and why ?!

sample image:

Blood cells image

like image 295
Jaja Avatar asked May 04 '15 03:05

Jaja


2 Answers

Usually when making decisions like this I just quickly plot the different channels and color spaces and see what I find. It is always better to start with a high quality image than to start with a low one and try to fix it with lots of processing

In this specific case I would use HSV. But unlike most color segmentation I would actually use the Saturation Channel to segment the images. The cells are nearly the same Hue so using the hue channel would be very difficult.

hue, (at full saturation and full brightness) very hard to differentiate cells

enter image description here

saturation huge contrast

enter image description here

Green channel, actually shows a lot of contrast as well (it surprised me)

enter image description here

the red and blue channels are hard to actually distinguish the cells.

Now that we have two candidate representations the saturation or the Green channel, we ask which is easier to work with? Since any HSV work involves us converting the RGB image, we can dismiss it, so the clear choice is to simply use the green channel of the RGB image for segmentation.

edit

since you didn't include a language tag I would like to attach some Matlab code I just wrote. It displays an image in all 4 color spaces so you can quickly make an informed decision on which to use. It mimics matlabs Color Thresholder colorspace selection window

function ViewColorSpaces(rgb_image)
    % ViewColorSpaces(rgb_image)
    % displays an RGB image in 4 different color spaces. RGB, HSV, YCbCr,CIELab
    % each of the 3 channels are shown for each colorspace
    % the display mimcs the  New matlab color thresholder window
    % http://www.mathworks.com/help/images/image-segmentation-using-the-color-thesholder-app.html

    hsvim = rgb2hsv(rgb_image);
    yuvim = rgb2ycbcr(rgb_image);

    %cielab colorspace
    cform = makecform('srgb2lab');
    cieim = applycform(rgb_image,cform);

    figure();
    %rgb
    subplot(3,4,1);imshow(rgb_image(:,:,1));title(sprintf('RGB Space\n\nred'))
    subplot(3,4,5);imshow(rgb_image(:,:,2));title('green')
    subplot(3,4,9);imshow(rgb_image(:,:,3));title('blue')

    %hsv
    subplot(3,4,2);imshow(hsvim(:,:,1));title(sprintf('HSV Space\n\nhue'))
    subplot(3,4,6);imshow(hsvim(:,:,2));title('saturation')
    subplot(3,4,10);imshow(hsvim(:,:,3));title('brightness')

    %ycbcr / yuv
    subplot(3,4,3);imshow(yuvim(:,:,1));title(sprintf('YCbCr Space\n\nLuminance'))
    subplot(3,4,7);imshow(yuvim(:,:,2));title('blue difference')
    subplot(3,4,11);imshow(yuvim(:,:,3));title('red difference')

    %CIElab
    subplot(3,4,4);imshow(cieim(:,:,1));title(sprintf('CIELab Space\n\nLightness'))
    subplot(3,4,8);imshow(cieim(:,:,2));title('green red')
    subplot(3,4,12);imshow(cieim(:,:,3));title('yellow blue')

end

you could call it like this

rgbim = imread('http://i.stack.imgur.com/gd62B.jpg');
ViewColorSpaces(rgbim)

and the display is this

enter image description here

like image 128
andrew Avatar answered Oct 17 '22 15:10

andrew


in DIP and CV is this always a valid question

But it has no universal answer because each task is unique so use what is better suited for it. To choose correctly you need to know the pros/cons of each so here is some summary:

  1. RGB

    this is easy to handle and you can easyly access r,g,b bands. For many cases is better to check just single band instead of whole color or mix the colors to emphasize wanted feature or even dampening unwanted one. It is hard to compare colors in RGB due to intensity encoded into bands directly. To remedy that you can use normalization but that is slow (need per pixel sqrt). You can do arithmetics on RGB colors directly.

    Example of task better suited for RGB:

    • finding horizont in high altitude photo
  2. HSV

    is better suited for color recognition because CV algorithms using HSV has very similar visual perception to human perception so if you want to recognize areas of distinct colors HSV is better. The conversion between RGB/HSV takes a bit of time which can be for big resolutions or hi fps apps a problem. For standard DIP/CV tasks is this usually not the case.

    Example of task better suited for HSV:

    • Compare RGB colors

    Take a look at:

    • HSV histogram

    to see the distinct color separation in HSV. The segmentation of image based on color is easy on HSV. You can not do arithmetics on HSV colors directly instead need to convert to RGB and back

like image 24
Spektre Avatar answered Oct 17 '22 16:10

Spektre