So I have the following image:
Now I wish to find the center point of each individual disconnected shape. I would also like to find the width and height if possible.
I'm using Java and the java.awt.image package but even just a general solution to this problem would help.
My own idea is to:
- Iterate through and find the first white pixel.
- Perform BFS from that pixel marking the white pixels it finds with the number 1.
- Once finished, continue iterating through the image stopping at the first white pixel with no assigned/marked number.
- Once it finds this, perform BFS and mark all pixels found with the number 2.
- Lather, rinse and repeat. I mean... continue doing this until end of the image.
- The number you are up to is the number of distinct shapes.
BUT this seems a bit intensive and i would then have to find the center, width and height. Is there a simpler way? Any ideas?