python图像处理-----图像增强(空间域)

1.反转变换

反转变换:s = (L-1) - r

def fan_zhuan_bian_huan(image):
    a,b = image.shape[:2]
    img = np.zeros((a,b),dtype=np.uint8)
    for i in range(a):
        for j in range(b):
            img[i][j] = 255 - image[i][j]
    return img

2.对数变换

对数变换:s = c log(k+r)

def dui_shu_bian_huan(image,c,k):
    a,b = image.shape[:2]
    img = np.zeros((a,b),dtype=np.uint8)
    for i in range(a):
        for j in range(b):
            img[i][j] = c * math.log(k+image[i][j],2)
    return img

3.指数变换

指数变换:s = c r^γ

def zhi_shu_bian_huan(image,c,gamma):
    a,b = image.shape[:2]
    img = np.zeros((a,b),dtype=np.uint8)
    for i in range(a):
        for j in range(b):
            img[i][j] = 256 * c * math.pow(image[i][j]/256,gamma)
    return img

你可能感兴趣的:(python图像处理-----图像增强(空间域))