What is an efficient algorithm for finding the number of shapes in a binary image?

For a binary image , I'm interested in a way to efficiently count the number of individual shapes present in an image. Also, as a related question, how can I fit each figure that is present in the image in a square?

Welcome pseudo code.

+3
source share
3 answers

I cannot answer in the second half, but if the first half defines the “shape” as continuous pixels of a certain color, this is what I do. Maintain an array for the entire image, indicating which pixels were "visible." (Bool [,] will do the trick in C # -speak.)

. , .

, , "-", .

. , . , ( ). - , . . , .

, . - . .

, , , . .

( , , .)

+6
+3

Make blobing image data, you will get each shape with all the pixels and extents [RECT shapes]

If your image has a shape inside the shape, then the buildup will be processed as separate shapes.

If you need a code, send me an email, we will be happy to share it.

+3
source

Source: https://habr.com/ru/post/1773774/


All Articles