title: OpenCV/python: How to change image pixels' values using a formula?
body: <p>I'm trying to stretch an image's histogram using a logarithmic transformation.  Basically, I am applying a <code>log</code> operation to each pixel's intensity. When I'm trying to change image's value in each pixel, the new values are not saved but the histogram looks OK. Also, the maximum value is not correct. This is my code:</p>
  
  <pre><code>import cv2
  import numpy as np
  import math
  from matplotlib import pyplot as plt
  
  img = cv2.imread('messi.jpg',0)
  img2 = img
  for i in range(0,img2.shape[0]-1):
      for j in range(0,img2.shape[1]-1):
          if (math.log(1+img2[i,j],2)) &lt; 0:
              img2[i,j]=0
          else:
              img2[i,j] = np.int(math.log(1+img2[i,j],2))
              print (np.int(math.log(1+img2[i,j],2)))
  
  print (img2.ravel().max())          
  cv2.imshow('LSP',img2)
  cv2.waitKey(0)
  fig = plt.gcf()
  fig.canvas.set_window_title('LSP histogram')
  plt.hist(img2.ravel(),256,[0,256]); plt.show()
  img3 = img2
  B = np.int(img3.max())
  A = np.int(img3.min())
  print ("Maximum intensity = ", B)
  print ("minimum intensity = ", A)
  </code></pre>
  
  <p>This is also the histogram I get:</p>
  
  <p><a href="https://i.stack.imgur.com/1LMSp.png" rel="noreferrer"><img src="https://i.stack.imgur.com/1LMSp.png" alt="This is the resulted histogram"></a></p>
  
  <p>However, the maximum intensity shows 186!  This isn't applying the proper logarithmic operation at all.</p>
  
  <p>Any ideas?</p>