实现亮度调整和饱和度调整的方法,都是通过对原图进行修改得到的。
如果不做处理,在调整亮度之后,再进行调整饱和度,显示的结果只有饱和度的调整,没有保留上一步亮度的调整
处理办法:
通过添加flag变量作为标识位,用来标识亮度(饱和度)是否被更改。
添加imageTemp变量,保存亮度(饱和度)属性被更改后,改变后的图片,作为下一步调整的原图
def BaoHeDu(self,value):
print('调整饱和度{}'.format(value))
if value == 0:
value = 1
if self.flag1 == 1:
hsv_image = cv2.cvtColor(self.pic_imageTemp, cv2.COLOR_RGB2HSV)
else:
hsv_image = cv2.cvtColor(self.pic_image0,cv2.COLOR_BGR2HSV)#####
h, s, v = cv2.split(hsv_image)
v = np.clip(v + value - 50, 0, 250)
hsv_image = cv2.merge((h, s, v))
self.pic_image = cv2.cvtColor(hsv_image, cv2.COLOR_HSV2RGB)
if value != 50:
self.pic_imageTemp1 = self.pic_image
self.flag2 = 1
else:
self.flag2 = 0
self.show_pic()
def LiangDu(self,value):
print("调整亮度")
if value == 0:
value = 1
contrast = value / 50.0 # float类型
if self.flag2 == 1:
self.pic_imageTemp = cv2.cvtColor(self.pic_imageTemp1, cv2.COLOR_RGB2BGR)
tmp_image = np.float32(self.pic_imageTemp) * contrast
#print(tmp_image)
else:
tmp_image = np.float32(self.pic_image0) * contrast
tmp_image = np.clip(tmp_image, 0, 255)
self.pic_image = np.uint8(tmp_image)
self.pic_image = cv2.cvtColor(self.pic_image, cv2.COLOR_BGR2RGB)
# print(value)
if value != 50:
self.pic_imageTemp = self.pic_image
self.flag1 = 1
else:
self.flag1 = 0
self.show_pic()