i trying implement in python same function on post: link
however, can't smooth result, whatever try, though tried both implementation, corrected 1 of op , second answer provided.
i missing small 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 @ end, use cv2.cv_32s
because op's encoding end black image. rest, use same sigma, 2.0 , 20.0.
there errors in implementation, here correctly translated code in python:
import cv2 import numpy np img = cv2.imread('lena.png') gray = cv2.cvtcolor(img, cv2.color_bgr2gray) float_gray = gray.astype(np.float32) / 255.0 blur = cv2.gaussianblur(float_gray, (0, 0), sigmax=2, sigmay=2) num = float_gray - blur blur = cv2.gaussianblur(num*num, (0, 0), sigmax=20, sigmay=20) den = cv2.pow(blur, 0.5) gray = num / den cv2.normalize(gray, dst=gray, alpha=0.0, beta=1.0, norm_type=cv2.norm_minmax) cv2.imwrite("./debug.png", gray * 255)
output:
Comments
Post a Comment