目录
1.白化处理的作用
图像白化(whitening)可用于对过度曝光或低曝光的图片进行处理,下图所示,左图是过分曝光,右图是白化后的结果;

2.白化处理的原理
处理的方式就是改变图像的平均像素值为 0 ,改变图像的方差为单位方差 1。
3.白化处理的代码
def whitening(self, img_path): img = cv2.imread(img_path) img = img / 255.0 m, dev = cv2.meanStdDev(img) # 返回均值和方差,分别对应3个通道 img[:, :, 0] = (img[:, :, 0] - m[0]) / (dev[0]+1e-6) img[:, :, 1] = (img[:, :, 1] - m[1]) / (dev[1] + 1e-6) img[:, :, 2] = (img[:, :, 2] - m[2]) / (dev[2] + 1e-6) # 将 像素值 低于 值域区间[0, 255] 的 像素点 置0 img = img*255 img *= (img > 0) # 将 像素值 高于 值域区间[0, 255] 的 像素点 置255 img = img * (img <= 255) + 255 * (img > 255) img = img.astype(np.uint8) cv2.imshow('result', img) cv2.waitKey(1000) cv2.destroyAllWindows() cv2.imwrite('result.jpg',img)
Pytorch中的线性变换可用于白化处理:
class torchvision.transforms.LinearTransformation(transformation_matrix) #功能:对矩阵做线性变换,可用于白化处理
发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/230653.html原文链接:https://javaforall.net
