>>> (img_RGB[:,:,2] == img_RGB[:,:,1]).all()
False
# So there are some values that are not identical
# Let's get the indices
>>> np.nonzero(img_RGB[:,:,2] != img_RGB[:,:,1])
(array([ 16, 16, 16, ..., 1350, 1350, 1350], dtype=int64),
array([ 83, 84, 85, ..., 1975, 1976, 1977], dtype=int64))
# So these are the indices, where :
# first element of tuple is indices along axis==0
# second element of tuple is indices along axis==1
# Now let's get values at these indices:
>>> img_RGB[np.nonzero(img_RGB[:,:,2] != img_RGB[:,:,1])]
# R G B
array([[254, 254, 255],
[252, 252, 254],
[251, 251, 253],
...,
[144, 144, 142],
[149, 149, 147],
[133, 133, 131]], dtype=uint8)
# As can be seen, values in `G` and `B` are different in these, essentially `B`.
# Let's check for the first index, `G` is:
>>> img_RGB[16, 83, 1]
254
# And `B` is:
>>> img_RGB[16, 83, 1]
255
对于您的图像,似乎大多数像素在所有通道中都具有相同的值(至少在
B
和G
),这就是为什么在打印时您看不到差异,因为不同值的数量非常少。我们可以通过以下方式进行检查:检查这一结果时,人们可能会说所有人都是平等的,但是,如果我们仔细观察,情况并非如此:
因此,打印形状为
(1351, 1982)
的图像数组并不是检查差异的好方法相关问题 更多 >
编程相关推荐