Ask Your Question

Revision history [back]

Separate Color regions using Open CV

I have a set of vector images of same object:

Outline Image 1

Outline Image 1

Outline Image 2

Outline Image 2

Fill Image

Fill Image

What I want to do is identify background, all outlines and all fill areas based on color values and save the information in another file (may be an image). And then provide a tool that will allow the end user to customize the icon however they want by assigning custom colors to all these areas.

What I have done:

I have separated colors and assigned them categories from 0-1 (e.g. 0 to background, 0.1 to first outline and so on), created another image and assigned these categories to alpha channel of the respective pixels. And then in my custom image generation tool, I check for those categories to identify regions and assign them new colors.

Problem:

The main (or I think the only) problem is the smoothing pixels (pixels that blend between two colors).

  • At first I planned to group the smoothing pixels to the outline color and then apply smoothing after the final image made by image generation tool. with single outline color it worked fine, but with multiple outline colors (as in "Outline Image 2") I am unable to find a decent solution to figure out how to categorize those pixels with there respective outline category. (Obviously the same problem comes up if I merge smoothing pixels with fill colors)
  • Then I decided to assign separate category to smoothing pixels, but then I was unable to figure out what two colors should be used to calculate the smoothing value for the selected smoothing pixel.
    • e.g. In "Fill Image" a smoothing pixel can lie between outline and background, and outline and fill color, but when reading those pixels I cannot tell the two colors surrounding the pixel.
  • I have also tried reading hue value from HSV image hoping that the smoothing pixels might have same hue as any of the two colors but to no use. smoothing pixels have separate hue value.

Question

  1. Is there any way to resolve this smoothing pixels problem?
  2. Is there any other way to achieve the end goal? (Other than the ones I have tried)