Should I use HSV/HSB or RGB and why?

后端 未结 2 587
温柔的废话
温柔的废话 2020-12-19 12:19

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 de

2条回答
  •  囚心锁ツ
    2020-12-19 12:51

    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

提交回复
热议问题