How can I efficiently determine the boundaries of an image, specifically focusing on the non-white pixels using JavaScript algorithms?
For instance, how could I generate lists containing the x and y points corresponding to the boundary pixels of an object like this:
https://i.sstatic.net/ntSUp.png
It's important to note that the interior section should be included while any completely white areas within (like holes) should be excluded.
Therefore, the desired outcome would be two lists representing the x and y coordinates for constructing an object similar to this:
https://i.sstatic.net/h7DZy.png
Below is my current approach, which successfully handles concave objects but struggles with more complex shapes featuring convex sides.
Success with Concave Object
- jsfiddle: https://jsfiddle.net/bhc4qn87/
Challenges with Complex Object
- jsfiddle: https://jsfiddle.net/xdr9bt0w/
You can observe in the provided examples that the algorithm fails to accurately capture the inside of the more intricate, convex image.
The Question Persists
Hence, the question remains: what effective method can be employed to create a mask or outline of the image (excluding holes) that effectively covers the external regions of any complex/convex object where the background is white and the object components are colored? Thank you.