Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Mask in Grabcut algorithm Opencv

While going through the grabcut algorithm from here : http://docs.opencv.org/3.2.0/d8/d83/tutorial_py_grabcut.html I am interested in the second part of the algorithm where whichever background/foreground don't come correctly are then stroked manually with a particular color, and accordingly a mask is created. This is what we call as a part of matting process in image processing.

So I want to know about the parameter mask in grabcut. Suppose I have an image and I don't want hair in that image. So what will the mask contain for that image. (Here I am not considering rect version).

So if I stroke a part of hair with black color(any color), then how will I create the mask to pass in grabcut function.

Also, in here it says the following :

The mask is initialized by the function when mode is set to GC_INIT_WITH_RECT. Its elements may have one of following values:
GC_BGD defines an obvious background pixels.
GC_FGD defines an obvious foreground (object) pixel.
GC_PR_BGD defines a possible background pixel.
GC_PR_FGD defines a possible foreground pixel.

Which elements are they talking about in here. And the first line saying that mask is initialised when mode is set to GC_INIT_WITH_RECT is correct or should it be GC_INIT_WITH_MASK ?

If Java solution then, that will be best.

click to hide/show revision 2
retagged

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

berak gravatar image

Mask in Grabcut algorithm Opencv

While going through the grabcut algorithm from here : http://docs.opencv.org/3.2.0/d8/d83/tutorial_py_grabcut.html I am interested in the second part of the algorithm where whichever background/foreground don't come correctly are then stroked manually with a particular color, and accordingly a mask is created. This is what we call as a part of matting process in image processing.

So I want to know about the parameter mask in grabcut. Suppose I have an image and I don't want hair in that image. So what will the mask contain for that image. (Here I am not considering rect version).

So if I stroke a part of hair with black color(any color), then how will I create the mask to pass in grabcut function.

Also, in here it says the following :

The mask is initialized by the function when mode is set to GC_INIT_WITH_RECT. Its elements may have one of following values:
GC_BGD defines an obvious background pixels.
GC_FGD defines an obvious foreground (object) pixel.
GC_PR_BGD defines a possible background pixel.
GC_PR_FGD defines a possible foreground pixel.

Which elements are they talking about in here. And the first line saying that mask is initialised when mode is set to GC_INIT_WITH_RECT is correct or should it be GC_INIT_WITH_MASK ?

If Java solution then, that will be best.