Grabcut foreground problem
Grabcut works on the method that we define the pixel of our image as sure foreground or sure background in our mask. And then try to iterate to see the result.
In my case when I define certain pixel as background it takes that properly but when I define a certain pixel as foreground it changes the result to background(black).
Any possible reason why this is happening :
for(int x=419;x<438;x++){
for(int y=317;y<456;y++){
result.get(x,y,buffer);
buffer[0] = 1;
result.put(x,y,buffer);
}
}
Imgproc.grabCut(srcImage,result,rect,new Mat(),new Mat(),10,Imgproc.GC_INIT_WITH_MASK);
Which gives that blackish mark in middle of the face as you can see (same result for hair part which I marked as sure background value of 0). Any possible reason why its happening?
i'm only guessing, but try to set it to: GC_PR_FGD (3), not 1
@berak They are already 3 in there. When I do Mat.get(x,y) I get a byte array having 3 values. Can you please tell what are these values as in 3 channels? Are these 3 color channels RGB and the value signifies intensity of that channel or something else?
"I get a byte array having 3 values." only the 1st channel is used for a uchar(?) image, you're safe to ignore the other 2
@berak Okay, and the value defines the intensity right?
yes. in the grabcut mask, that is 0,1,2,3 (same as the flags, iirc)
@berak Yeah, and in grabcut it is strange to see when I change my value from 3(Probable foreground) to 1(foreground) in the mask it makes it background.