Detecting shapes in an image

I dont know what kind of algorithm you use to detect the shapes. Just adapt it in a way that it uses color information as well, to distinguish different colors with same brightness. One way might be to use your current algorithm individually on each of the 3 color channels and to fuse the 3 individual results to a common result in the end or in between.

For example, if your algorithm is:

  1. use sobel magnitude on grayscale image => img_sobel
  2. threshold img_sobel => img_thresh
  3. find contours in img_thresh

Then you could adapt it by:

  1. use sobel magnitude on R channel => r_sobel
  2. use sobel magnitude on G channel => g_sobel
  3. use cobel magnitude on B channel => b_sobel
  4. combine them by e.g. full_sobel = r_sobel + g_sobel + b_sobel or by full_sobel = max_per_pixel(r_sobel, g_sobel, b_sobel)
  5. threshold full_sobel => img_thresh
  6. find contours in img_thresh

But this is just an example. It depends on your actually used algorithm, how to adapt it for color images.

1 Like