Search code examples
image-processingrgbscikit-imagelab-color-space

Image Processing: Separate Yellow and Blue Channels in Lab Color Space


I'm new to image processing, and I was given a task to separate the yellow (+ve values) and blue (-ve values) colors by a white edge from an image that contains only blue and yellow colors.

Unfortunately, I don't know how should I separate both colors.

Also, I cannot see any negative values in the pixels of the image which I got.

Unfortunately, I cannot use an advanced libraries such as OpenCv and most of the tutorials related to image processing on the Internet uses it.

the image I used

I converted the image from RGB to Lab color space. I'm using Python for this and scikit-image library and other useful packages.

I'll be glad if anyone could help by giving me any hints!

Thanks


Solution

  • You need to find a colourspace where the yellows and the blues are well separated. Splitting the channels, and assigning them across the page, in RGB colourspace (with R on the left, G in the centre and B on the right):

    RGB without edge detection:

    enter image description here

    RGB with edge detection:

    enter image description here

    that's not very good - the brighter tones of yellow where the material is catching the light are being treated like edges.

    Let's try Lab instead of RGB with L on the left, a in the centre and b on the right:

    Lab without edge detection:

    enter image description here

    Lab with edge detection:

    enter image description here

    Still not so good. Now let's try HSV colourspace, H on the left, S in the centre and V on the right:

    HSV without edge detection:

    enter image description here

    HSV with edge detection:

    enter image description here

    And hopefully you can see that H on the left nails it. That's because yellow is 60 degrees and blue is 240 degrees in this diagram so your two colours are diametrically opposed - or whatever hexagons have in place of a circle's diameter.

    Then you need to do edge detection, and fattening, then you can composite the white edge over the top of the yellow and blue flag by choosing a "lighten" blend mode where you choose the lighter pixel at each location in the images so that the white edges filter through the blue and yellow.