title: How Can I A Threshold Image of a Salience Map?
body: <p>I currently have the salience map of an image below, the spectral saliency and fine grained saliency images are below obtained by the following code:</p>
  <pre><code>import cv2
  
  imgpath = r'Content Image.jpg'
  image = cv2.imread(imgpath)
  
  width = 350
  height = 450
  dim = (width, height)
   
  # resize image
  resized = cv2.resize(image, dim, interpolation = cv2.INTER_AREA)
  
  saliency = cv2.saliency.StaticSaliencySpectralResidual_create()
  (success, saliencyMap) = saliency.computeSaliency(resized)
  saliencyMap = (saliencyMap * 255).astype(&quot;uint8&quot;)
  cv2.imshow(&quot;Image&quot;, resized)
  cv2.imshow(&quot;Output&quot;, saliencyMap)
  cv2.waitKey(0)
  cv2.destroyAllWindows()
  
  saliency = cv2.saliency.StaticSaliencyFineGrained_create()
  (success, saliencyMap) = saliency.computeSaliency(resized)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/Njucz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Njucz.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/1p7Yz.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/1p7Yz.png" alt="enter image description here" /></a></p>
  <p><a href="https://i.stack.imgur.com/ZzR0o.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ZzR0o.png" alt="enter image description here" /></a></p>
  <p>All of these make sense and I understand why they were obtained.</p>
  <p>However, when I try to get the threshold map using the code below:</p>
  <pre><code>ret, threshMap = cv2.threshold(saliencyMap.astype(&quot;uint8&quot;), 120, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)
  cv2.imshow(&quot;Image&quot;, resized)
  cv2.imshow(&quot;Output&quot;, saliencyMap)
  cv2.imshow(&quot;Thresh&quot;, threshMap)
  cv2.waitKey(0)
  </code></pre>
  <p>I obtain the following image:</p>
  <p><a href="https://i.stack.imgur.com/4mlw4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/4mlw4.png" alt="enter image description here" /></a></p>
  <p>Not quite sure why this is the case since I'm pretty sure I've following everything that I have found online, any help is greatly appreciated.</p>