image defect in grabcut

asked 2020-09-03 04:33:52 -0600

Bouwy gravatar image

updated 2020-09-03 08:31:11 -0600

The grabcut algorithm is giving me a defect in the image segmentation. The input image is:

image description

The result is:

image description

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 ?

image description

Small remark: it must be fully automated, so no user interaction with drawing masks.

edit retag flag offensive close merge delete

Comments

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!

kpachinger gravatar imagekpachinger ( 2020-09-03 13:05:40 -0600 )edit