Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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: http://reference.wolfram.com/mathematica/example/AnalyzeSegmentedCellsInAnImage.html

but I couldn't get it to work.

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

outlines = 
  ComponentMeasurements[
    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 at 19:11
    
@Sektor, Classify is a new function in v10 –  Simon Woods Apr 12 at 20:20
    
@SimonWoods Yeah, he just did not specify .. :) –  Sektor Apr 12 at 21:14
add comment

1 Answer 1

up vote 11 down vote accepted

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

image = Import["http://i.stack.imgur.com/GjN95.jpg"];

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 at 20:08
add comment

Your Answer

 
discard

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.