直方图均衡python
时间: 2023-08-31 16:08:49 浏览: 92
要在Python中进行直方图均衡化,你可以使用numpy和skimage库来计算直方图,也可以使用OpenCV库来实现直方图均衡化。下面是两种方法的示例代码:
方法一:使用numpy和skimage库
```python
import numpy as np
from skimage import exposure, data
image = data.camera() * 1.0
hist, bins_center = np.histogram(image, bins=2) # 用numpy包计算直方图
hist2, bins2 = exposure.histogram(image, nbins=2) # 用skimage计算直方图
print(hist)
print(bins_center)
print(hist2)
print(bins2)
```
方法二:使用OpenCV库
```python
import cv2
img = cv2.imread('图像路径', 0)
equ = cv2.equalizeHist(img)
cv2.imshow('equ', equ)
```
请注意,在方法二中,你需要将图像的路径替换为你要进行直方图均衡化的图像的路径。这个方法使用OpenCV的equalizeHist函数来实现直方图均衡化,并通过imshow函数显示均衡化后的图像。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [python数字图像处理(9):直方图与均衡化](https://blog.csdn.net/weixin_34239592/article/details/85794050)[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_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [直方图的均衡化(Python)](https://blog.csdn.net/qq_34510308/article/details/64905493)[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_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文