Extract small regions from a PIL image python

Viewed 85

enter image description here

I have a PIL image in python as shown and I want to extract each of the small red regions separately into a jpeg format. So from this file, I'm expecting file1.jpg, file2.jpg, etc.

How can I obtain each sub-regions in each different file?

1 Answers

PIL doesn't really excel at that. I would consider using:

  • OpenCV findContours(), or
  • scikit-image regionprops(), or
  • ImageMagick Connected Components, or
  • Python wand bindings to ImageMagick as above
Related