Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have an image that has various characters hand drawn in it, like numbers and letters. I'm trying to partition each character into it's own image so I can run it through Classify[] and identify them one at a time (since TextRecognize[] doesn't work well on individual characters). My images look like this: enter image description here

That's a bunch of 1's for putting into Classify[]. So it should be pretty easy to partition each one, but I'm not sure what the best way to do it is. I tried adapting this example:

but I couldn't get it to work.

characters = 
   DeleteBorderComponents[Binarize[a, {0, .7}]], {"Area"}, 
   100 < #1 < 1000 &];

outlines = 
    ImageMultiply[a, characters], {"BoundingBox"}][[All, 2]];

Show[a, Graphics[{Red, Thick, Circle @@ # & /@ outlines}]];

This just returns a slightly lighter version of the original image with no red anywhere.

share|improve this question
Classify ? Are you implementing it ? You can post the code as it is related. – Sektor Apr 12 '14 at 19:11
@Sektor, Classify is a new function in v10 – Simon Woods Apr 12 '14 at 20:20
@SimonWoods Yeah, he just did not specify .. :) – Sektor Apr 12 '14 at 21:14
up vote 14 down vote accepted

You can use ImageTrim to extract the bounding boxes from the image.

image = Import[""];

m = MorphologicalComponents@Binarize@ColorNegate@MinFilter[image, 1];   
m = SelectComponents[m, "Elongation", # > 0.8 &];    
c = ComponentMeasurements[{m, image}, "BoundingBox"];

ImageTrim[image, #] & /@ c[[All, 2]]

enter image description here

share|improve this answer
nice and short! – chris Apr 12 '14 at 20:08

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.