I want to remove the background of this image to get the person only. I have thousand of images like this, basically, a person and a somewhat whitish background.
What I have done is to use edge detector like canny edge detector or sobel filter (from skimage
library). Then what I think possible to do is, whiten the pixels within the edges and blacken the pixels without. Afterwards, the original image can be mask to get the picture of the person only.
However, it's hard to get a closed boundary using canny edge detector. Result using Sobel filter is not that bad, however I don't how to proceed from there.
EDIT:
Is it possible to also remove the background between the right hand and the skirt and between hairs?
After obtaining your incomplete edges (as you have), you can run a closing morphology (a sequence of dilate and erode) (will have to set size and iterations based on needs/state of edges).
Now assuming that you have a constant edge all the way around the subject, use any type of fill algorithm (blob) to combine all points outside the edged object, then take the negative of that to give you the mask of the inside of the object.
If you wish to fill background not with a red color but make it transparent, you may add following lines to solution:
If you wish you may tweak some png compression parameters to make file smaller.
Image on a white background below. Or on a black one - http://imgur.com/a/4NwmH
Working example with vs2017.
Sets the red background but saves blue..
Also added the transperent example in.
How can I remove the girls body and leave only the dress in the picture? Any ideas?
The following code should get you started. You may want to play around with the parameters at the top of the program to fine-tune your extraction:
Ouput:
As an alternative, you can use neural networks like this one: CRFRNN.
It gives the result like this: