-2

Input image

I need to group the region in green and get its coordinates, like this output image. How to do this in python?

Please see the attached images for better clarity

senthil
  • 21
  • 4
  • We cannot help you until you show what you've already tired – Jetman Dec 18 '18 at 11:46
  • SO expects some minimal research effort. Look into opencv please – user8408080 Dec 18 '18 at 11:47
  • i haven't stated anything regarding this. Basically i'm trying to identify image regions from document image. I trained a semantic segmentation model to do this and the input image is the model output. from the output i need to group those green regions which are actually images and get its coordinates. if the region is fully green (like green block) i can use connected components to get the region coordinates. but here since it has background color also visible( black color) CC is not working. IDK how to proceed further – senthil Dec 18 '18 at 11:51
  • Have you seen this: https://stackoverflow.com/questions/40527769/removing-black-background-and-make-transparent-from-grabcut-output-in-python-ope – Jetman Dec 18 '18 at 11:58
  • "I trained a semantic segmentation model"... show us the code. –  Dec 18 '18 at 12:14

1 Answers1

1

At first, split the green channel of the image, put a threshold on that and have a binary image. This binary image contains the objects of the green area. Start dilating the image with the suitable kernel, this would make adjacent objects stick to each other and become to one big object. Then use findcontour to take the sizes of all objects, then hold the biggest object and remove the others, this image would be your mask. Now you can reconstruct the original image (green channel only) with this mask and fit a box to the remained objects.

You can easily find the code each part.

MeiH
  • 1,763
  • 11
  • 17