I am trying to implement in python the same function than on this post: link
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.
I am probably missing something small but I can't figure out what.
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
I must precise that at the end, I use cv2.CV_32S
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.