6
$\begingroup$

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.

$\endgroup$
3
  • $\begingroup$ Classify ? Are you implementing it ? You can post the code as it is related. $\endgroup$
    – Sektor
    Apr 12 '14 at 19:11
  • $\begingroup$ @Sektor, Classify is a new function in v10 $\endgroup$ Apr 12 '14 at 20:20
  • $\begingroup$ @SimonWoods Yeah, he just did not specify .. :) $\endgroup$
    – Sektor
    Apr 12 '14 at 21:14
14
$\begingroup$

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

$\endgroup$
1
  • $\begingroup$ nice and short! $\endgroup$
    – chris
    Apr 12 '14 at 20:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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