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')
亮度提升后
对比度提升