Ask Your Question

How do I use this image as a mask to perform segmentation?

asked 2020-02-07 06:48:45 -0500

tsabbir96 gravatar image

updated 2020-02-07 06:49:26 -0500

Hello I have this image:


i want to use this black and white image as a mask to segment the clouds from this RGB image :


However I am having some problem achieving this, as the black and white image is not in binary form. when i print the values of the image it prints some compex number. please kindly have a look at this attached image:


Please could you help me by showing a way on how to use this weird black and white image as a mask to segment clouds from the RGB image that I have attached?

btw I am a student and I am really really new to image processing. I Would appreciate your help a lot. Thank you.

edit retag flag offensive close merge delete


it prints some compex number

no, it's the first and last 20 numbers from your "mask", which is is floating point format

berak gravatar imageberak ( 2020-02-07 07:54:23 -0500 )edit

so if i see "2.4444e-1" such type of numbers, they are basically floating point numbers, yes?

tsabbir96 gravatar imagetsabbir96 ( 2020-02-07 08:27:38 -0500 )edit

yes. how did you acquire it, btw ? (unusual format)

berak gravatar imageberak ( 2020-02-07 08:52:08 -0500 )edit

I generated it from a DNN. I trained a DNN to output black and white images of the clouds. I used the same DNN mentioned in this github: then i used the trained model to predict the output which is the black and white image I attached

tsabbir96 gravatar imagetsabbir96 ( 2020-02-07 08:56:26 -0500 )edit

^^ awesome ;)

berak gravatar imageberak ( 2020-02-07 09:09:18 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2020-02-07 08:44:50 -0500

berak gravatar image

updated 2020-02-07 08:47:42 -0500

the most common way to get a binary image is thresholding :

# assume, "gray" is your "mask" image above
thr, bin = cv2.threshold(gray, 0.1, 255.0, cv2.THRESH_BINARY);
print("threshold: ",thr)

(to use OTSU, you need to convert / scale to uint8 first !)

image description

then you can mask out the unwanted parts:

# assume, "img" is the bgr cloud img
# images did not have same size, thus:
mask = cv2.resize(mask, (img.shape[1], img.shape[0]))
result = cv2.bitwise_or(img, img, mask=mask);

image description

edit flag offensive delete link more


Your piece of white cloud cropped out. Not accurately.

supra56 gravatar imagesupra56 ( 2020-02-11 08:00:04 -0500 )edit

yea, image sizes did not match, ad-hoc threshold value, etc.

(i guess, this is more to show, you can threshold float images w/o conversion)

berak gravatar imageberak ( 2020-02-11 08:07:42 -0500 )edit

Question Tools

1 follower


Asked: 2020-02-07 06:48:45 -0500

Seen: 1,353 times

Last updated: Feb 07 '20