'How to split segmented image into sub images

I would like to ask if there is a way to split segmented image into sub-images?

I want to extract each object in predicted image into separate image.

To visualize what I would like to achieve:

from:

enter image description here

to have each of these in separate file:

enter image description here

just so each separate object in image can be viewed on its own.

Here is an sample image to download:

sample



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source