Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using OpenCV Python, How would you make all black pixels transparent, and then overlay it over original image

I'm trying to make a colored mask, white. And my idea is to:

  • make black pixels transparent in the mask
  • merge the two images
  • crop images

so then my original masked area will be white. What kind of OpenCV python code/methods would I need?

Like so:

Original

Original

Mask

Mask

Desired result (mocked up - no green edges)

Desired result (mocked up - no green edges)

Instead of

Instead of

like image 432
jmhead Avatar asked Jun 04 '15 03:06

jmhead


1 Answers

I suppose to do a color threshold to get the mask itself. The result I got in a first quick and dirty attempt with Hue 43-81, Saturation 39-197 and Brightness from 115-255 is: enter image description here

The next step is a whole fill algorithm to fill the inside of the mask. Note that also one small area to the right is selected.

enter image description here

The next step is a substraction of the two results (mask-filled_mask):

enter image description here

Again fill the wholes and get rid of the noisy pixels with binary opening:

enter image description here

Last mask the image with the created mask.

enter image description here

Every step can be adjusted to yield optimal results. A good idea is to try the steps out (for example with imageJ) to get your workflow set up and then script the steps in python/openCV.

Refer also to http://fiji.sc/Segmentation.

like image 62
Dschoni Avatar answered Sep 21 '22 13:09

Dschoni