WARNING: I will assume the image is pure black and white, which does not appear to be the case! That can make segmentation much much harder as borders of segments could be regarded as having sub-pixel components! I have even seen some sement programs (such as autotrace raster to vector convertor) make each individual edge grey pixel a separate segment. I suggest you threshold the image first!
However I can not see three segments in your image, at least not without further processing! (using
morphology)
From the top level I can see at least 10 segments, two odd boxes and 8 individual letters.
If I segment inside borders too I get 30 black segments!
If I was segmenting white areas (the more common proposition for mask segmentation) I see 23 separate and distinct white segments.
If I segment all back and white areas, I get a total of 53 segments for this image!
If that is not wanted you need to describe your segments more fully!
At this time IM is short on built-in segmentation methods. They are planned but there are just not enough programmers willing to get their hands dirty.
I myself have a 'morphology labelling' algorithm planned that would label each white area with a separate grayscale color (segment index) and can join segments that are close to each other (not just a floodfill Z4 neighbourhood segmentation)
A Proof-of-concept segmentation script (using flood fll to mark and remove each segment as it found), is presented in IM
Examples Scripts Area...
http://www.imagemagick.org/Usage/scripts/
Look for "segment_image"
http://www.imagemagick.org/Usage/scripts/segment_image
This was developed as part of another very old IM discussions
http://imagemagick.org/discourse-server ... =1&t=11705
http://imagemagick.org/discourse-server ... =1&t=18283
Examples...
Input...
montage of all output images
The checkerbod is transparency, the red boxes are the 'trimed' image on its vitual canvas (the original image size), and represents the images rectanguar bounding box. If I flattened or mosaic all those images together I would get the original image again. This type of result (perhaps ignoring a specified background color) is the goal of a 'perfect' segmentation.
Other forms of segmentation is 'edge to edge lines' either just horizontally, vertiaclly, both, or any angle. Perhaps recursively, that is segment horizontal, then segment those vertically, then horizontally again.
On horozontal segmentation (dividing an image vertically) is given by the scripts (same directory as before)
divide_vert and divide_vert_bg
the later is faster but limited to a specific background color.