python 降低图片饱和度
时间: 2023-08-30 07:10:27
浏览: 206
可以使用Python中的OpenCV库来降低[图片](https://geek.csdn.net/educolumn/1de9845baad351038ab25b200eff4431?spm=1055.2569.3001.10083)的饱和度。可以使用cv2.cvtColor()[函数](https://geek.csdn.net/educolumn/ba94496e6cfa8630df5d047358ad9719?dp_token=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6NDQ0MDg2MiwiZXhwIjoxNzA3MzcxOTM4LCJpYXQiOjE3MDY3NjcxMzgsInVzZXJuYW1lIjoid2VpeGluXzY4NjQ1NjQ1In0.RrTYEnMNYPC7AQdoij4SBb0kKEgHoyvF-bZOG2eGQvc&spm=1055.2569.3001.10083)将图像从BGR格式转换为HSV格式,然后调整饱和度,最后再将图像转换回BGR格式。[代码](https://geek.csdn.net/educolumn/1572ef9b473b4e00f6b2bf6d428b7c27?spm=1055.2569.3001.10083)示例如下:
import cv2
image = cv2.imread('image.jpg')
# 将图像从BGR转换为HSV
hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
# 减少饱和度
hsv[..., 1] = hsv[..., 1] * 0.5
# 将图像从HSV转换回BGR
result = cv2.cvtColor(hsv, cv2.COLOR_HSV2BGR)
cv2.imshow('Ori[gin](https://geek.csdn.net/educolumn/1aef582107c22aa4d9f243890549bf39?spm=1055.2569.3001.10083)al image', image)
cv2.imshow('Result', result)
cv2.waitKey(0)
cv2.destroyAll[window](https://geek.csdn.net/educolumn/03e5a5a554174a38fdfeb8376bd685e2?spm=1055.2569.3001.10083)s()
```
相关推荐










