1

I used semantic segmentation to color code the different elements in an image shown below. enter image description here

enter image description here

In Python, I want to crop the original image into many small images based on the colors of the second image, so that the sofa becomes one cropped part, the lamp becomes one.etc. The overlap of the pillows on the sofa can be ignored. Say I have a 3D array of an image, I want to separate that array into the individual colored sections, and apply the coordinate of those elements in cropping the original image. How should I achieve this?

Steven Oh
  • 382
  • 3
  • 14
  • 2
    What did you try so far? Where are you stuck? Are you able to detect/identify the colored areas? This could be achieved by applying approaches called ["image segmentation"](https://en.wikipedia.org/wiki/Image_segmentation). As there are many different ways to identify these areas you should provide more details about the approach/tools you chose. – albert Jul 28 '21 at 15:08
  • @albert I am using an open sourced code, which outputs the second image (color coded one). The code is quite long but I will attach the function that does the image processing part. – Steven Oh Jul 28 '21 at 15:18

1 Answers1

1

You can do it like this:

  • find the number of unique colours in the segmented image - see here
  • iterate over that list of colours making that colour white and everything else black, then findContours() to get the bounding box and save the contents of that bounding box as a PNG.
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432