title: How to remove seven low bits of a grayscale image using OpenCV
body: <p>I wrote a script to remove the seven least significant bits and only keep the MBS for each pixel of a gray-scale 8-bit image. To do this, I mask each pixel with <code>0b10000000</code>, but am not getting the expected output.</p>
  
  <pre><code>import cv2
  import numpy as np
  
  imageSource = 'input.jpg'
  original_img = cv2.imread(imageSource,cv2.COLOR_BGR2GRAY)
  cv2.imshow( "original", original_img )
  result = original_img &amp; 0b10000000
  cv2.imshow( "out", result )
  cv2.imwrite('out.jpg',result)
  cv2.waitKey(0)
  cv2.destroyAllWindows()
  </code></pre>
  
  <p>Original image:
  <a href="https://i.stack.imgur.com/r597Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/r597Y.png" alt="https://i.stack.imgur.com/r597Y.png"></a></p>
  
  <p>Output from my code:
  <a href="https://i.stack.imgur.com/fYM6f.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fYM6f.png" alt="enter image description here"></a></p>
  
  <p>Desired result:
  <a href="https://i.stack.imgur.com/d30SJ.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/d30SJ.jpg" alt="enter image description here"></a></p>