Local normalization in OpenCV

后端 未结 3 1871
迷失自我
迷失自我 2021-01-12 16:39

I\'m trying to implement in OpenCV a local normalization algorithm to reduce the difference of illumination in an image. I have found a MATLAB function, and I have implement

3条回答
  •  梦谈多话
    2021-01-12 17:25

    This is the Python implementation of the same algo above:

    import cv2
    import numpy as np
    
    img = cv2.imread('/home/anmol/Downloads/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
    
    gray = cv2.normalize(gray, dst=gray, alpha=0.0, beta=1.0, norm_type=cv2.NORM_MINMAX)
    
    cv2.imwrite("./debug.png", gray * 255)
    

    Outout:

提交回复
热议问题