Why is there a difference in the output image when calling the same image using plt.show
& cv2.imshow()
?
Here is my code:
import cv2 import numpy as np from matplotlib import pyplot as plt src=cv2.imread('fruits1.jpg') # Source image plt.subplot(211),plt.imshow(src),plt.title('image') plt.xticks([]),plt.yticks([]) plt.show() cv2.imshow('image',src) cv2.waitKey(0) cv2.destroyWindow()
Here is the image from plt.show
:
and the second one is the original image:
Is there some modification required with the plt.show()
?
cv2. imshow() method is used to display an image in a window. The window automatically fits to the image size. Syntax: cv2.imshow(window_name, image)
The matplotlib function imshow() creates an image from a 2-dimensional numpy array. The image will have one square for each element of the array. The color of each square is determined by the value of the corresponding array element and the color map used by imshow() .
imshow( I ) displays the grayscale image I in a figure. imshow uses the default display range for the image data type and optimizes figure, axes, and image object properties for image display.
Because OpenCV stores images in BGR order instead of RGB.
Try plt.imshow(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
See here for an example.
OpenCV - BGR and Matplotlib - RGB
OpenCV:
https://docs.opencv.org/2.4/doc/tutorials/introduction/display_image/display_image.html
Matplotlib:
https://matplotlib.org/api/_as_gen/matplotlib.pyplot.imshow.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With