I have a script that shows several images in 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()
But the issue is with figure 1_5 Grey
. At first, I was having an issue with the RGB/BGR opencv/numpy disparity, that I fixed with the cv2np
function. But even though Image
is the correct color, Grey
is still the jet colormap:
I don't see how this is happening: I ran the function to turn the image black-and-white:
igg = cv2.cvtColor(img, cv2.COLOR_RGB2GRAY)
there shouldn't be any colors left, so why is is jet? And when I try to run the function a second time (ax1_5.imshow(cv2np(igg))
), it gives me an error:
Traceback (most recent call last):
File "LaplacianOfGaussian--01-1.py", line 35, in <module>
ax1_5.imshow(cv2np(igg))
File "LaplacianOfGaussian--01-1.py", line 13, in cv2np
b, g, r = cv2.split(img)
ValueError: need more than 1 value to unpack
##########################################################################/
So finally, I assumed that I had done something completely wrong, and so I wrote a completely new script from scratch to figure out the problem:
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()
And now, for some reason, every single one of those images is jet:
I don't understand: Where is the jet color coming from? All of the image cells should be either 0 or 255. Can someone explain this?