title: How to apply opencv background subtraction to an image
body: <p>I am trying to apply <code>cv2.createBackgroundSubtractorMOG()</code> to this Image:</p>
  
  <p><a href="https://i.stack.imgur.com/4jHZ5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4jHZ5.png" alt="enter image description here"></a></p>
  
  <p>to eliminate all background brightness and only leave the two bright objects in the middle for further analysis. Is this the right approach for this task? If not, how would I do that?</p>
  
  <pre><code>import cv2
  
  img = cv2.imread('image.png')
  sharp_img = cv2.createBackgroundSubtractorMOG().apply(img)
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/artur/Desktop/test.py", line 4, in &lt;module&gt;
      sharp_img = cv2.createBackgroundSubtractorMOG().apply(img)
  AttributeError: module 'cv2.cv2' has no attribute 'createBackgroundSubtractorMOG
  </code></pre>
  
  <p><strong>Edit</strong>:</p>
  
  <p>MOG does not seem to work.</p>
  
  <p>Code:</p>
  
  <pre><code>import cv2
  img = cv2.imread('image.png')
  sharp_img = cv2.bgsegm.createBackgroundSubtractorMOG().apply(img)
  cv2.imwrite('image2.png', sharp_img)
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>Traceback (most recent call last):
    File "/home/artur/Desktop/test.py", line 4, in &lt;module&gt;
      sharp_img = cv2.bgsegm.createBackgroundSubtractorMOG().apply(img)
  AttributeError: module 'cv2.cv2' has no attribute 'bgsegm'
  </code></pre>
  
  <p>MOG2 seems to work but with no satisfying result:</p>
  
  <p>Code:</p>
  
  <pre><code>import cv2
  img = cv2.imread('image.png')
  sharp_img = cv2.createBackgroundSubtractorMOG2().apply(img)
  cv2.imwrite('image2.png', sharp_img)
  </code></pre>
  
  <p>Output Image:</p>
  
  <p><a href="https://i.stack.imgur.com/XdVno.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XdVno.png" alt="enter image description here"></a></p>
  
  <p>I tried to play around with the args of the MOG2 Method from the docs but with no change.</p>