修改图片的明亮度和对比度

2023-12-13 14:05:42
def enhance_brightness(imgf, newname):
  img = Image.open(imgf)
  enhance = ImageEnhance.Brightness(img)
  bright_img = enhance.enhance(5)
  bright_img.show()
  bright_img.save(newname)


def enhance_contrast(imgf, newname):
  img = cv2.imread(imgf)
  hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
  v_channel = hsv[:,:,2]
  contrast_img = cv2.addWeighted(v_channel, 2, np.zeros(v_channel.shape, v_channel.dtype), 0,0)
  hsv[:,:,2] = contrast_img
  contrast_img = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
  cv2.imshow('contrast_img', cv2.resize(contrast_img,(1000,600)))
  cv2.waitKey(0)
  cv2.imwrite(newname, contrast_img)



imgl = r'D:\mydocs\ftp\temp_scan\left_155.png'
imgr = r'D:\mydocs\ftp\temp_scan\right_155.png'
enhance_brightness(imgl, r'D:\mydocs\ftp\temp_scan\bright_left_155.png')
enhance_brightness(imgr, r'D:\mydocs\ftp\temp_scan\bright_right_155.png')
enhance_contrast(imgl, r'D:\mydocs\ftp\temp_scan\contrast_left_155.png')
enhance_contrast(imgr, r'D:\mydocs\ftp\temp_scan\contrast_right_155.png')

原图

亮度提升后

对比度提升

文章来源:https://blog.csdn.net/Lyncai/article/details/134941272
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。