Answers.Body: <p>In image segmentation the target is actually an image, with the same dimensions as the input, where each pixel has a label depending on which class it represents. It is not uncommon for such a dataset to have a &quot;background&quot; class that essentially consists of the pixels not belonging to any other class. If not you can always group together classes typically associated with background (e.g. &quot;sky&quot;, &quot;cloud&quot;, &quot;grass&quot;, &quot;mountain&quot;, etc.) to form the class &quot;background&quot;. Likewise you could group all other possible classes of interest (e.g. &quot;person&quot;, &quot;car&quot;, &quot;horse&quot;, etc.) into the class &quot;foreground&quot;. With this dataset you could train an image segmentation model that predicts if a pixel belongs to the background or the foreground, without actually classifying it into a &quot;person&quot; or a &quot;car&quot;.</p>
  <p>So suppose you want to make your own removal.ai, you could:</p>
  <ul>
  <li>find one or more <strong>diverse</strong> image segmentation datasets (it needs to be diverse so that it will work on any generic photo uploaded to the site)</li>
  <li>check all the unique classes in the labels</li>
  <li>group all classes associated with backgrounds into class 0 (i.e. &quot;background&quot; class)</li>
  <li>group all classes associated with foregrounds into class 1 (i.e. &quot;foreground&quot; class)</li>
  <li>train an image segmentation model with these two classes</li>
  <li>profit</li>
  </ul>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-01-04T00:39:25.130Z
Answers.LastActivityDate: 2021-01-04T00:39:25.130Z
Answers.UserDisplayName: Djib2011
Answers.Body: <p>Background removal is technically known as image matting. It is similar to segmentation, but it is a regression problem. The objective is to predict the alpha matte, which separates the foreground and background. Simply adding the predicted alpha matte as the fourth channel to the RGB image removes the background.</p>
  <p>The model architecture is mostly an encoder-decoder model. The encoder extracts features and compresses them in the latent space, while the decoder constructs the alpha channel.</p>
  <p>Since it is a challenging problem, most solutions require additional input along with the RGB image. The most common one is a trimap. The Deep Image Matting paper (Xu, N., Price, B., Cohen, S., &amp; Huang, T., 2017) is one of the major studies and it proposes such a solution. However, trimap is a significant limitation since it requires human annotation.</p>
  <p>To eliminate the trimap requirement, a model can be trained with only an RGB image, but the quality significantly decreases. Another solution is training two neural networks. The first one predicts a coarse alpha matte, and the second one returns a sharper alpha matte, <a href="https://ai.googleblog.com/2022/01/accurate-alpha-matting-for-portrait.html" rel="nofollow noreferrer">as done in Google's Pixel 6 phones</a>.</p>
  <p>Another trimap-free solution is designing a model with one encoder and two decoders. The decoders predict a semantic mask and a detailed map simultaneously. GFM (Li, J., Zhang, J., Maybank, S. J., &amp; Tao, D. (2020).) and MODNet (Ke, Z., Sun, J., Li, K., Yan, Q., &amp; Lau, R. W. (2020).) are two related studies.</p>
  <p>For more in-depth information on both traditional and deep learning solutions, you can refer to my blog post: <a href="https://withoutbg.com/resources/how-automatic-image-background-removal-works" rel="nofollow noreferrer">https://withoutbg.com/resources/how-automatic-image-background-removal-works</a></p>
  <p>Disclosure: I built <a href="https://withoutbg.com/" rel="nofollow noreferrer">withoutbg.com</a>, a background removal tool, powered by deep learning.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-02-28T22:29:59.700Z
Answers.LastActivityDate: 2023-03-01T09:35:33.633Z
Answers.LastEditDate: 2023-03-01T09:35:33.633Z
Answers.UserDisplayName: Imran Kocabiyik
Body: <p>I'm well aware of the inner workings of CNN models for object detection, and although I've not worked on a semantic segmentation problem I can imagine how it works.</p>
  <p>With these types of models, we need to say &quot;segment out the humans&quot;, or &quot;segment out the X&quot;. But what about when I say something like &quot;segment out the subject of this photo, whatever it happens to be&quot;. For example, see this service: <a href="https://removal.ai/" rel="nofollow noreferrer">https://removal.ai/</a></p>
  <p>Without too much imagination I might guess that they apply a multiclass segmentation model and just show any foreground pixels, no matter what class they belong to. So we'd hope that the subject is in one of the classes that the model was trained for, and that there are no other class instances in the image that shouldn't be captured. But is there a more general way?</p>
  
Tags: <computer-vision><image-segmentation>
Title: How does general image background removal AI work?
UserDisplayName: Alexander Soare
ThreadText: # How does general image background removal AI work?
  
  (Asked by: username_0 on 2020-12-31)
  
  I'm well aware of the inner workings of CNN models for object detection, and although I've not worked on a semantic segmentation problem I can imagine how it works.
  
  With these types of models, we need to say "segment out the humans", or "segment out the X". But what about when I say something like "segment out the subject of this photo, whatever it happens to be". For example, see this service: <https://removal.ai/>
  
  Without too much imagination I might guess that they apply a multiclass segmentation model and just show any foreground pixels, no matter what class they belong to. So we'd hope that the subject is in one of the classes that the model was trained for, and that there are no other class instances in the image that shouldn't be captured. But is there a more general way?
  
  **Tags:** computer-vision, image-segmentation
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2021-01-04. Score: 1
  
  In image segmentation the target is actually an image, with the same dimensions as the input, where each pixel has a label depending on which class it represents. It is not uncommon for such a dataset to have a "background" class that essentially consists of the pixels not belonging to any other class. If not you can always group together classes typically associated with background (e.g. "sky", "cloud", "grass", "mountain", etc.) to form the class "background". Likewise you could group all other possible classes of interest (e.g. "person", "car", "horse", etc.) into the class "foreground". With this dataset you could train an image segmentation model that predicts if a pixel belongs to the background or the foreground, without actually classifying it into a "person" or a "car".
  
  So suppose you want to make your own removal.ai, you could:
  
  * find one or more **diverse** image segmentation datasets (it needs to be diverse so that it will work on any generic photo uploaded to the site)
  * check all the unique classes in the labels
  * group all classes associated with backgrounds into class 0 (i.e. "background" class)
  * group all classes associated with foregrounds into class 1 (i.e. "foreground" class)
  * train an image segmentation model with these two classes
  * profit
  
  
  ---
  
  ### Answer by username_2 on 2023-02-28. Score: 0
  
  Background removal is technically known as image matting. It is similar to segmentation, but it is a regression problem. The objective is to predict the alpha matte, which separates the foreground and background. Simply adding the predicted alpha matte as the fourth channel to the RGB image removes the background.
  
  The model architecture is mostly an encoder-decoder model. The encoder extracts features and compresses them in the latent space, while the decoder constructs the alpha channel.
  
  Since it is a challenging problem, most solutions require additional input along with the RGB image. The most common one is a trimap. The Deep Image Matting paper (Xu, N., Price, B., Cohen, S., & Huang, T., 2017) is one of the major studies and it proposes such a solution. However, trimap is a significant limitation since it requires human annotation.
  
  To eliminate the trimap requirement, a model can be trained with only an RGB image, but the quality significantly decreases. Another solution is training two neural networks. The first one predicts a coarse alpha matte, and the second one returns a sharper alpha matte, [as done in Google's Pixel 6 phones](https://ai.googleblog.com/2022/01/accurate-alpha-matting-for-portrait.html).
  
  Another trimap-free solution is designing a model with one encoder and two decoders. The decoders predict a semantic mask and a detailed map simultaneously. GFM (Li, J., Zhang, J., Maybank, S. J., & Tao, D. (2020).) and MODNet (Ke, Z., Sun, J., Li, K., Yan, Q., & Lau, R. W. (2020).) are two related studies.
  
  For more in-depth information on both traditional and deep learning solutions, you can refer to my blog post: <https://withoutbg.com/resources/how-automatic-image-background-removal-works>
  
  Disclosure: I built [withoutbg.com](https://withoutbg.com/), a background removal tool, powered by deep learning.
  
  
  ---
  
  