2024-10-08 18:28:20 发布
网友
当我使用matplotlib.imread()时,它返回一个形状的3D数组(4971248,3)
此数组中存储了哪些值?这是照片中像素的RGB值吗
img = mpimg.imread("./pearlite_strain2.jpg")
我想遍历这个数组,并保存从照片最左侧到某个RGB值的所有像素的距离
我该怎么做
数组中的值是RGB值(y, x, color)。该数组是一个标准的numpy数组,因此您可以使用^{}和^{}来获取所需的信息(argmax在0和1或^}和True的布尔数组中查找1或True的第一个匹配项)。所需距离为x坐标:
RGB
(y, x, color)
argmax
0
1
True
x
import numpy as np import matplotlib.pyplot as plt np.random.seed(0) img = np.random.randint(0, 200, (2,4,3), np.uint8) searched = [245, 250, 255] # almost white bright pixels img[0,2,:] = img[1,1,:] = img[1,3,:] = searched plt.imshow(img) all_distances = np.argwhere((img[...,:]==searched).all(2))[:,1] # array([2, 1, 3], dtype=int64) first_distances = np.argmax((img[...,:]==searched).all(2), axis=1) # array([2, 1], dtype=int64)
数组中的值是} 和^{} 来获取所需的信息(}和
RGB
值(y, x, color)
。该数组是一个标准的numpy数组,因此您可以使用^{argmax
在0
和1
或^True
的布尔数组中查找1
或True
的第一个匹配项)。所需距离为x
坐标:相关问题 更多 >
编程相关推荐