Find bitmap boundaries

0 votes
asked Sep 13, 2017 by ant

In a NxN array of bool values that represents a bitmap of a monochrome image, I need to find its rectangular boundaries (TopLeft, TopRight, BottomLeft, BottomRight coordinates). There is only one "image" in that NxN array and it's "continuous" - every next pixel is located at x+1 or x-1 or y+1 or y-1 relative to its neighbor.

The simplest algorithm I came up with is just to find first (upper-left) pixel (x,y) and then recursively probe four adjacent pixels (x+1, y), (x-1, y), (x, y+1), (x, y-1) and advance if any found..

Can you suggest something more efficient?

[EDIT] I'm looking for an algorithm that would be more efficient that a full scan. I.e. the boundary should be found with a minimal number of steps.

Thanks.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
Anti-spam verification:
To avoid this verification in future, please log in or register.
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...