1

I'm trying to make some cloud maps in python using opencv and I need to be able to cut-out the backgrounds of the thresholded images. However, I don't particularly know of a way to make the background transparent, leaving only the masked clouds behind.

So, I want to be able to take an image such as this: cloud mask And make the black background transparent, while leaving the clouds untouched. How would I do this?

jsull99
  • 25
  • 3

2 Answers2

0

I think you could do this by

  1. Creating a single channel GRAY image of your cloud image.
  2. Adding an alpha channel to your image.
  3. Copying the GRAY image to the alpha channel of your cloud image.

The following answer may be helpful for you, it is not a duplicate but is quite close and uses similar techniques.

python OpenCV - add alpha channel to RGB image

Jon Guiton
  • 1,360
  • 1
  • 9
  • 11
0

You need to do the following to make the background transparent.

  1. Load image and convert gray-scale.
  2. Threshold the image to create alpah mask.
  3. Split the source image to RGB channel.
  4. Now merge all 3 channel with alpha.

Refer this blog post for more information.

https://scode7.blogspot.com/2019/05/opencv-create-transparent-background.html

CodeDezk
  • 1,230
  • 1
  • 12
  • 40