title: How to identify the pixels with the highest activation from four or more grayscale images and save as the final heatmap?
body: <p>I have four attention maps, each of dimension 217 x 217 and in the form of array of float64. I need to perform an operation using these attention maps and save the final attention map where only the pixels with the highest activations are present. A custom function is needed in this regard. Attached are the heatmaps:</p>
  <p><a href="https://i.stack.imgur.com/w2zfo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/w2zfo.png" alt="heatmap4.png" /></a>
  <a href="https://i.stack.imgur.com/GZljp.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GZljp.png" alt="heatmap3.png" /></a>
  <a href="https://i.stack.imgur.com/ugH0G.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ugH0G.png" alt="heatmap2.png" /></a>
  <a href="https://i.stack.imgur.com/XR0Yv.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XR0Yv.png" alt="heatmap1.png" /></a></p>
  <p>The starter code is here:</p>
  <pre><code>import cv2
  import numpy as np
  import os
  from PIL import Image
  
  im1 = np.array(Image.open(&quot;heatmap1.png&quot;).convert('L'))
  im2 = np.array(Image.open(&quot;heatmap2.png&quot;).convert('L'))
  im3 = np.array(Image.open(&quot;heatmap3.png&quot;).convert('L'))
  im4 = np.array(Image.open(&quot;heatmap4.png&quot;).convert('L'))
  
  #compute to save only the pixels with the highest activation
  
  #save final heatmap as a PNG file
  cv2.imwrite(&quot;final_heatmap.png&quot;, bitwise_AND)
  </code></pre>