13
$\begingroup$

I want to extract subimages from an image like below. There are 6 components in the image, I want to crop this image into 6 images in a way each individual image contain only 1 component. Can I automatically do it by Mathematica?

enter image description here

Thanks in advance.

$\endgroup$
5
  • 4
    $\begingroup$ ImagePartition[ ] or MorphologicalComponents[ ]? $\endgroup$ Mar 5, 2016 at 8:03
  • $\begingroup$ Welcome! Can you please elaborate? At the moment it is not clear what exactly you want to achieve. $\endgroup$
    – Yves Klett
    Mar 5, 2016 at 8:11
  • 1
    $\begingroup$ Look up ComponentMeasurements and ImageTrim in the documentation. $\endgroup$ Mar 5, 2016 at 8:59
  • 1
    $\begingroup$ @HayashiYoshiaki Look at this question $\endgroup$
    – martin
    Mar 5, 2016 at 9:00
  • $\begingroup$ There are 6 components in the image, I want to crop this image into 6 images in a way each individual image contain only 1 component. $\endgroup$ Mar 5, 2016 at 9:01

1 Answer 1

16
$\begingroup$

Thanks martin !!

SplitImage[image_] := Module[
  {m, components},
  m = MorphologicalComponents[image];
  components = 
   ComponentMeasurements[{m, image}, {"Area", "BoundingBox"},#1>100&];
  ImageTrim[image, #] & /@ components[[All, 2, 2]]
]

enter image description here

$\endgroup$

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.