We had a similar problem given in the IM forum
viewtopic.php?f=1&t=11705
Their were a couple of solutions including the (slow) script
http://www.imagemagick.org/Usage/scripts/segment_image
This would divide your image into three masks, the background black part, and two foreground white objects.
An API of C version can be made much faster, as the shell script version needs
to process the image from scratch multiple times until no more parts are found. That can take some time.
Another similar script is
http://www.imagemagick.org/Usage/scripts/divide_vert
This looks for lines of constant horizontal color, and divided the image either
into segments of two or more colors, or alternating horizontal segments of constant and non-constant colors.
I developed it to allow text images to be sub-divided into separate 'lines'
of text so that the space between those lines can be adjusted, or removed.
It was also good for the automatic deletion of text label that was optionally present UNDER a photo.
It could easily be modified to...
- horizontally divide up an image,
- equally divide the solid color regions into two passing them to the previous and next segments.
- use of a 'fuzz' factor or other statistical variance test to determine if a line is a single or multi-colored.
- repeatally sub-divide vertically, then horizontally, then vertically again, and so on, until no more sub-divisions are found. Such a script
would allow for automatic sub-division of GIF animation into sections, or into image blocks for a HTML image-map.
I'd love to see both these scripts converted into MagickCore Library functions
as image segmentation methods.
If you have any modifications, ideas or other solitions to this image segmentation problem, please include them here.