import cv2
import numpy as np
import sys
import matplotlib.pyplot as plt
def zhifangtu_zhengguihua(image,a):
Imax=np.max(image)
print(Imax)
Imin=np.min(image)
print("Imax", Imax)
Omin,Omax=0,255
a=float(Omax-Omin)/(Imax-Imin)
b=Omin-a*Imin
O=a*image+b
O=O.astype(np.uint8)
print("a",a)
print("Omax", Omax)
print("Imax", Imax)
print("Omin", Omin)
print("Imin", Imin)
return O
if __name__=='__main__':
a = cv2.imread('D:/5.png', cv2.IMREAD_UNCHANGED)
image1 = cv2.split(a)[0]
image2 = cv2.split(a)[1]
image3 = cv2.split(a)[2]
print(image1)
image1 = zhifangtu_zhengguihua(image1, 4)
image2 = zhifangtu_zhengguihua(image2, 4)
image3 = zhifangtu_zhengguihua(image3, 4)
merged = cv2.merge([image1, image2, image3])
cv2.imshow("原图", a)
cv2.imshow("增强后图", merged)
cv2.waitKey(0)
cv2.destroyAllWindows()