我有一个脚本在matplotlib中显示了几个图像:
i = cv2.imread(sys.argv[1])
def cv2np(img):
b, g, r = cv2.split(img)
imn = cv2.merge([r,g,b])
return imn
img = cv2np(i)
igg = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
imb = cv2.GaussianBlur(igg,(7,7),0)
LoG = nd.gaussian_laplace(imb, 2)
f0 = plt.figure()
ax0 = f0.add_subplot(111)
ax0.imshow(i)
ax0.set_title('Raw Image')
f1 = plt.figure()
ax1 = f1.add_subplot(111)
ax1.imshow(img)
ax1.set_title('Image')
f1_5 = plt.figure()
ax1_5 = f1_5.add_subplot(111)
ax1_5.imshow(igg)
ax1_5.set_title('Grey')
f2 = plt.figure()
ax2 = f2.add_subplot(111)
ax2.imshow(imb)
ax2.set_title('Blur')
f3 = plt.figure()
ax3 = f3.add_subplot(111)
ax3.imshow(LoG)
ax3.set_title('LoG')
plt.show()
但问题在于图1_5 Grey
。一开始,我遇到了一个RGB/BGR opencv/numpy视差的问题,我用cv2np
函数修复了这个问题。但即使Image
是正确的颜色,Grey
仍然是jet颜色图:
igg = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
不应该有任何颜色了,那为什么是jet?当我第二次运行这个函数时(ax1_5.imshow(cv2np(igg))
),它会给我一个错误:
所以最后,我假设我做了完全错误的事情,所以我从头开始写了一个全新的脚本来解决问题:
img = cv2.imread(sys.argv[1])
def cv2np(img):
b, g, r = cv2.split(img)
imn = cv2.merge([r,g,b])
return imn
a = cv2np(img)
b = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
c = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
d = cv2.cvtColor(a, cv2.COLOR_RGB2GRAY)
f0 = plt.figure()
ax0 = f0.add_subplot(111)
ax0.imshow(img)
ax0.set_title('Raw Image')
f1 = plt.figure()
ax1 = f1.add_subplot(111)
ax1.imshow(a)
ax1.set_title('A')
f2 = plt.figure()
ax2 = f2.add_subplot(111)
ax2.imshow(b)
ax2.set_title('B')
f3 = plt.figure()
ax3 = f3.add_subplot(111)
ax3.imshow(c)
ax3.set_title('C')
f4 = plt.figure()
ax4 = f4.add_subplot(111)
ax4.imshow(c)
ax4.set_title('D')
plt.show()
现在,出于某种原因,这些图像中的每一张都是jet:
我不明白:喷射色是从哪里来的?所有图像单元格应为0或255。有人能解释一下吗?在
目前没有回答
相关问题 更多 >
编程相关推荐