title: Python - Local Normalization in OpenCV
body: <p>I am trying to implement in python the same function than on this post: <a href="https://stackoverflow.com/questions/14872306/local-normalization-in-opencv">link</a></p>
  
  <p>However, I can't get a smooth result, whatever I try, even though I tried both implementation, the corrected one of the OP and the second answer provided.</p>
  
  <p>I am probably missing something small but I can't figure out what.</p>
  
  <pre><code>def local_norm(img, sigma_1, sigma_2):
  
      float_gray = img * cv2.CV_32FC1 / 255.0
      blur_1 = int(2 * np.ceil(- norm.ppf(0.05, loc=0, scale=sigma_1)) + 1)
      blurred_1 = cv2.GaussianBlur(float_gray, (blur_1, blur_1), sigma_1, sigma_1)
      temp_1 = float_gray - blurred_1
  
      temp_2 = cv2.pow(temp_1, 2.0)
      blur_2 = int(2 * np.ceil(- norm.ppf(0.05, loc=0, scale=sigma_2)) + 1)
      blurred_2 = cv2.GaussianBlur(temp_2, (blur_2, blur_2), sigma_2, sigma_2)
      temp_2 = cv2.pow(blurred_2, 0.5)
  
      float_gray = temp_1 / temp_2
      res = cv2.normalize(float_gray, 0, 255, cv2.NORM_MINMAX)
      res = res * cv2.CV_32S
      return res
  </code></pre>
  
  <p>I must precise that at the end, I use <code>cv2.CV_32S</code> because with the OP's encoding I end up with a black image. For the rest, I use the same sigma, 2.0 and 20.0.</p>
  
  <p><a href="https://i.stack.imgur.com/ee17Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ee17Q.png" alt="enter image description here"></a></p>