Ask Your Question

Background subtraction using single image

asked 2013-06-12 18:55:23 -0600

arablau gravatar image

Hi Everyone,

I'm working on a project where I am photographing products like this purse below. image description

I want to remove the background and have been trying a few methods but wanted to know what the community thinks is best practice.

I've been playing with different amounts of blurring, thresholding, dilating and eroding but I am not sure what combination of these measures will yield the best results.

The best I can do so far is this: image description

What are your thoughts?

Thank you all!

edit retag flag offensive close merge delete


remove background? there's no background, just a white background?

Shaban gravatar imageShaban ( 2013-06-12 22:30:35 -0600 )edit

Yes, I want to remove the peach background and make all of those pixels true white. I am playing around with eroding and dilating and filtering but don't know if there is a better way to get just the object.

arablau gravatar imagearablau ( 2013-06-13 17:15:40 -0600 )edit

Could you please share your code? I'm looking for something similar and it would be great to get a good starting point

sockeqwe gravatar imagesockeqwe ( 2014-09-20 14:07:00 -0600 )edit

i am also interested in the code

zombodotcom gravatar imagezombodotcom ( 2018-11-05 23:06:09 -0600 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2013-07-31 17:49:10 -0600

I will apply a threshold on your image, with threshold function with THRESH_TOZERO parameter. All pixel with a value greter than your threshold will be set to 0. Therefore, you will have a mask to copy only the non-zero pixel. If you want to "protect" white zone in your object, try to use findContours) and drawContours) to draw a mask of your object. The difficult part will be the threshold setting...

edit flag offensive delete link more

Question Tools


Asked: 2013-06-12 18:55:23 -0600

Seen: 2,157 times

Last updated: Jul 31 '13