26 lines
807 B
Python
26 lines
807 B
Python
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()
|