Grabcut foreground problem

asked 2017-07-10 07:19:17 -0600

arqam gravatar image

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?

image description

edit retag flag offensive close merge delete

Comments

i'm only guessing, but try to set it to: GC_PR_FGD (3), not 1

berak gravatar imageberak ( 2017-07-10 08:01:01 -0600 )edit

@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?

arqam gravatar imagearqam ( 2017-07-10 08:17:03 -0600 )edit

"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 gravatar imageberak ( 2017-07-10 08:28:04 -0600 )edit

@berak Okay, and the value defines the intensity right?

arqam gravatar imagearqam ( 2017-07-10 09:11:25 -0600 )edit

yes. in the grabcut mask, that is 0,1,2,3 (same as the flags, iirc)

berak gravatar imageberak ( 2017-07-10 09:16:28 -0600 )edit

@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.

arqam gravatar imagearqam ( 2017-07-10 14:35:01 -0600 )edit