medical_balloon/Dimensional_Inspection/Histogram.py
leo890808 a1fb25c89f UP
2024-07-30 16:18:26 +08:00

26 lines
807 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import cv2
import matplotlib.pyplot as plt
if __name__ == '__main__':
# 讀取圖像
image = cv2.imread(r"50.bmp", cv2.IMREAD_GRAYSCALE)
# 反轉圖像的 Y 軸
flipped_image = cv2.flip(image, 0)
# 選擇特定的列x 軸等於 1024
column_index = 2736
y_coordinates = range(0, 3648)
column_data = flipped_image[y_coordinates, column_index]
# 打印每個 Y 坐標的灰度值和索引
for y_coord, pixel_value in zip(y_coordinates, column_data):
print(f"Y 坐標: {y_coord}, 灰度值: {pixel_value}")
# 繪製直方圖
plt.plot(column_data, y_coordinates, color='gray')
plt.xlabel('像素強度')
plt.ylabel('Y 軸坐標(反向)')
plt.title(f'在 X 軸 = {column_index} 的灰度分佈 (Y 坐標: 0-2047)')
plt.show()