图像对比度增强python 伽马变换
时间: 2023-09-08 10:08:40 浏览: 132
要实现图像对比度增强的伽马变换,可以使用以下Python代码:
```python
import cv2
import numpy as np
# 读取图像并转为灰度图
in_image = cv2.imread('p2.jpg', cv2.IMREAD_GRAYSCALE)
# 图像归一化
fI = in_image/255.0
# 设置伽马值
gamma = 0.5
# 伽马变换
out_image = np.power(fI, gamma)
# 显示原图和伽马变换后的效果
cv2.imshow('IN', in_image)
cv2.imshow('OUT', out_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
这段代码首先读取图像并将其转为灰度图。然后进行图像归一化,将像素值范围映射到[0,1]之间。接下来,通过设置伽马值来调整图像的对比度。最后,显示原图和伽马变换后的效果。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [【3】python-opencv3教程:图像的对比度增强(线性变化,直方图正规化,伽马变化,全局直方图均衡化,限制...](https://blog.csdn.net/shawroad88/article/details/87918599)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文