0

I have several intersecting semitransparent polygons, which divides the canvas on some number of other polygons of different colors. Here is an example with 3 triangles:

enter image description here

How I can calculate the number of areas of the different colors created by this intersection? In the presented picture there are 2 grey areas; 3 red; 3 green; 1 blue; 1 violet (red and blue triangles intersection); 1 olive (red and green triangles intersection); 1 teal blue (green and blue triangles intersection). Is it possible to adopt for this purpose Sutherland-Hodgman clipping algorithm that allowing to find the polygon that is the intersection between two arbitrary polygons?

  • 1
    google histogram... you just count distinct colors - special colors like background (gray) and edges (black) see [Image histogram meaning](https://stackoverflow.com/a/43933262/2521214) and links there especially this one [Effective gif/image color quantization?](https://stackoverflow.com/a/30265253/2521214) which does what you need to do – Spektre Jun 26 '19 at 02:43
  • I'm not sure I understood how it could help me... – Филипп Цветков Jun 26 '19 at 09:29
  • 1
    @Spektre: "you just count distinct colors" is not sufficient. It just tells you the number of different colors, but not the number of areas. You need to complement that with a step of labelling (i.e. assigning a color index to every pixel) and count the connected components they form. Of course, this assumes that working in image space is allowed. Erasing the areas by seed filling until all pixels are erased is another possibility. –  Jun 26 '19 at 18:58
  • 1
    @YvesDaoust You;re right I see it now the same color is counted more than once ... so color segmentation is the way ... (flood fill each yet non recolored area until no such pixel is left ... counting how many times the flood fill was called) – Spektre Jun 27 '19 at 06:45
  • Ok I'll try to use flood fill, but I think it will be slow – Филипп Цветков Jun 28 '19 at 21:10

0 Answers0