13

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.

xzczd
  • 65,995
  • 9
  • 163
  • 468
Hayashi Yoshiaki
  • 906
  • 4
  • 11

1 Answers1

16

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

Hayashi Yoshiaki
  • 906
  • 4
  • 11