Reputation: 1
I want to display an image using matplotlib. I want to split the channels of image and display them separately. only if I want to display the red pixels does it show them in blue. And the other way around. The green color is going well. By the way, if I display them with cv2.imshow () everything is fine.
empty_image = img.copy()
empty_image = np.zeros(img.shape, img.dtype)
channel=empty_image.copy()
channel[:,:,0]=img[:,:,0]
fig, ax = plt.subplots()
ax.imshow(channel, cmap="binary")
ax.spines['top'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['bottom'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.set_xticks([])
ax.set_yticks([])
plt.show()
Upvotes: 0
Views: 3455
Reputation: 120
this is because OpenCV load images in BGR (Blue Green Red) instead of the commonly used RGB (Red Green Blue). Matplotlib displays in RGB.
So according to this post, you can use plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
to convert the colors from BGR to RGB so Matplotlib will read it fine.
Hopefully this helps.
Upvotes: 3