I try to write a program to crop background from an image.

This is a sample of my training data. I have images with and without a background. (manually cropped)

The background is always similar (changes of light and so on. Sometimes people on random places.)

The object is always on the same place but not always the same (there are different models).

Can someone give me an advice how I can solve this Problem? What is the right way to do something like this???

lern data


  • 1
    $\begingroup$ What is the size of your dataset? $\endgroup$ Dec 5 '16 at 7:55
  • $\begingroup$ about 2000 images $\endgroup$
    – Dawid Cz
    Dec 5 '16 at 7:57
  • 1
    $\begingroup$ Usually, people use a background subtraction technique. The most basic technique is to compute the average frame and then compare against each frame. But there are much more sophisticated techniques. Packages like opencv come with lots of background subtraction implementations. $\endgroup$ Dec 8 '16 at 22:30
  • $\begingroup$ That´s what I need. Thx I`ll check it. $\endgroup$
    – Dawid Cz
    Dec 9 '16 at 7:48
  • $\begingroup$ I have found here something like this stackoverflow.com/questions/17884526/… $\endgroup$
    – Dawid Cz
    Dec 10 '16 at 12:00

This is indeed a simple problem if tried to be tackled using semantic segmentation. Semantic segmentation itself is a computer vision problem that could be understood as an extension of object detection and could be understood as follows:

detection and segmentation

Using semantic segmentation done using a network called as UNET, the model could be trained for the required image and then it can be extended to find the boundary of the required object and finally extract it. UNET architecture could be understood using the following diagram:


UNET's are generally used to create mask that could be XOR with the actual image and the background of the image could be subtracted easily.

Completely explaining image segmentation using UNET or any other technique falls beyond the limit of the answer and thus a better explanation could be found in this article

If you want the practical implementation/codes of the same, they could be found here on kaggle kernels of the following contests:

  1. TGS Salt Identification Challenge
  2. Carvana Image Masking Challenge

The task you are trying to perform is called semantic segmentation (or pixel-wise segmentation). There exists extensive literature on the subject and numerous tutorials/online resources to get you started, such as this one

Fully convolutional networks (FCN) popularized the core components of state-of-the-art semantic segmentation techniques. They have since evolved into numerous superior, yet related, networks, many of which are covered in the link above.

Although the linked website is quite comprehensive, it does not mention mask rcnn, which has performed very well and at relatively fast speeds (~5 fps). It is definitely worth exploring!


You can use fully convolutional neural nets for image segmentation. Check out the kernels in the kaggle competition: Carvana Image Masking Challenge .

Also check out Fully Convolutional Neural Network


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.