image defect in grabcut
The grabcut algorithm is giving me a defect in the image segmentation. The input image is:
The result is:
Basic code for grabcut:
border_offset = 10
bgdModel = np.zeros((1, 65), np.float64)
fgdModel = np.zeros((1, 65), np.float64)
rect = (border_offset,border_offset,img_size[0]-border_offset,img_size[1]-border_offset)
cv.grabCut(img,mask,rect,bgdModel,fgdModel,3,cv.GC_INIT_WITH_RECT)
Changing the border offset results in smaller or larger defects. The defect is always in the bottom right corner.
When I change the size of the image the result is different but not correct. The border is rough and the image is clipped.
Any suggestions ?
Small remark: it must be fully automated, so no user interaction with drawing masks.
This image has reduced contrast which makes your task more difficult. The edge itself has attraction, so foreground may "snap" or "stick" to it at close proximity. Give the subject in the photo more generous space from the edges (padding) when you shoot... assuming that there is a solid continuous field and no additional clutter. You could also use copyMakeBorder to extend the background gesture.
Be careful that INIT_WITH_RECT can't clip your irregular-shaped foreground, not at all. You may consider INIT_WITH_MASK and use with general corner samples - as is commonly used with a greenscreen solution. Or combine with inrange..? Also, percentage-based offset would work better at extreme photo resolution ranges. Go Lakers!