【发布时间】:2021-02-12 05:23:58
【问题描述】:
假设我们从灰度图像中提取具有特定值的像素,然后在同一图像上使用散点图突出显示这些像素。
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import cv2
image = cv2.imread('images/wa_state_highway.jpg')
copy_image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
gray_image = cv2.cvtColor(copy_image, cv2.COLOR_RGB2GRAY)
plt.matshow(gray_image, cmap='gray')
# Get the index of elements with value 12
result = np.where(gray_image == 12)
print('Tuple of arrays returned : ', result, sep='\n')
print('List of coordinates where element with value 0 exists in red channel : ')
# zip the 2 arrays to get the exact coordinates
listOfCoordinates = list(zip(result[0], result[1]))
# iterate over the list of coordinates
# for cord in listOfCoordinates:
# print(cord)
x_val = [x[0] for x in listOfCoordinates]
y_val = [x[1] for x in listOfCoordinates]
plt.scatter(x_val, y_val)
plt.show()
我需要将散点的坐标与图像上对应的坐标进行匹配。
@warped 评论后解决:
【问题讨论】:
-
试试
plt.scatter(y_val, x_val) -
@warped merci beaucoup,我更新了帖子。
-
@sci9 如果您解决了问题,请发布一个自我回答并接受它,这样您已经解决的问题就会显示为这样。否则,想要帮助的人可能会浪费时间阅读整个问题。 :-/
标签: python image opencv matplotlib image-processing