Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to create a mask where from another Mat color condition

In an image Mat there are two color strokes. White and Black. (other colors also there)

In the mask that I need to create, the white stroke should be white and the black should be black.

The python code for that is :

 # newmask is the mask image I manually labelled
2 newmask = cv2.imread('newmask.png',0)
3 
4 # whereever it is marked white (sure foreground), change mask=1
5 # whereever it is marked black (sure background), change mask=0
6 mask[newmask == 0] = 0
7 mask[newmask == 255] = 1

So how can it be done it Java? Do I need to loop behind or anything?

click to hide/show revision 2
retagged

updated 2017-07-09 02:12:00 -0600

berak gravatar image

How to create a mask where from another Mat color condition

In an image Mat there are two color strokes. White and Black. (other colors also there)

In the mask that I need to create, the white stroke should be white and the black should be black.

The python code for that is :

 # newmask is the mask image I manually labelled
2 newmask = cv2.imread('newmask.png',0)
3 
4 # whereever it is marked white (sure foreground), change mask=1
5 # whereever it is marked black (sure background), change mask=0
6 mask[newmask == 0] = 0
7 mask[newmask == 255] = 1

So how can it be done it Java? Do I need to loop behind or anything?