vendredi 3 avril 2015

Parsing distinct regions on image with specific background color

If you have an image with a black background, with various things on it, how can you "parse" the individual things out?


My wish would be to parse graphics as different "regions" if they are separated from other regions by at least a pixel of solid background color. So, in the image below, 10 "graphics regions". (The gray area with black dots is considered a single region, so is the pink dot with a white dot inside of it.)


Then, maybe, text if they are separated further, perhaps by at least 6 pixels. So, in the image below, 6 "text regions". I realize I may have to separate regions if apart from another region by 1 pixel, recognize text after, and re-join them.


Once I have the regions separated (manually for now) I'm doing well identifying what they are and OCR'ing the text. Just want to be able to automatically detect the regions.


Only thing I've come up with so far is having a 2D array of booleans (for each pixel) marking whether each pixel has been parsed. Then, going through each, and when hitting one that isn't background color, trying to step in each direction until hitting a background color. (Toggling the array of Booleans along the way.) Wondering if there's a better way, or a discussion of doing something like this. Speed is quite important.


Photoshop sort of has something like this implemented. If you have a layer with some transparent pixels, control-left-clicking it selects the regions with "marching ants". And, it's a tight selection of the regions, not just a rectangle around them. My image isn't really any different, just with pure black pixels instead of transparent ones.


Doesn't really make a difference to me whether background colored pixels wholly contained by non-background are considered part of the region or not.


Want to start with this... non parsed


...And basically wind up with this parsed


Aucun commentaire:

Enregistrer un commentaire