对地址为C:\\Users\\11508\\Desktop\\123\\c631cd14-ebb2-4953-92cb-5ffe25610ea3.bmp的图像进行灰度级归一化处理,再转化为灰度级曲线图像,将曲线图像倒转并显示,显示出曲线顶部近乎线段的长度
时间: 2024-01-01 18:23:38 浏览: 57
以下是对图像进行灰度级归一化处理、转化为灰度级曲线图像、倒转并显示的Python代码:
```python
import cv2
import numpy as np
import matplotlib.pyplot as plt
# 读取图像
image_path = "C:\\Users\\11508\\Desktop\\123\\c631cd14-ebb2-4953-92cb-5ffe25610ea3.bmp"
image = cv2.imread(image_path)
# 灰度级归一化处理
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
normalized_image = cv2.normalize(gray_image, None, 0, 255, cv2.NORM_MINMAX)
# 转化为灰度级曲线图像
hist = cv2.calcHist([normalized_image], [0], None, [256], [0, 256])
hist = hist.flatten()
cdf = hist.cumsum()
cdf_normalized = cdf * hist.max() / cdf.max()
curve_image = np.interp(normalized_image.flatten(), np.arange(256), cdf_normalized).reshape(normalized_image.shape)
# 倒转并显示曲线图像
inverted_image = 255 - curve_image
plt.imshow(inverted_image, cmap='gray')
plt.axis('off')
plt.show()
# 计算曲线顶部近乎线段的长度
top_length = np.sum(inverted_image[0] == 0)
print("曲线顶部近乎线段的长度:", top_length)
```
阅读全文