1

I tried to plot some subplots using the code below. When i use OpenCv the image is fine, but when i use the pyplot, the color is changed. Please see the images and the code.

enter image description here

Ploted with cv2

enter image description here Ploted with pyplot

import cv2
from matplotlib import pyplot as plt

img = cv2.imread('image.jpg')

fig = plt.figure()

ax1 = fig.add_subplot(221)
ax2 = fig.add_subplot(223)
ax3 = fig.add_subplot(224)

ax1.imshow(img)
ax1.set_title('Original Image')



ax2.imshow(imgRedimensionata_proiect)
ax2.set_title('Alg image')

ax3.imshow(imgRedimensionata_traditional)
ax3.set_title('Traditional resize')

fig.show()
cv2.imshow('image',img)
cv2.waitKey(0)
Copacel
  • 1,328
  • 15
  • 25

1 Answers1

4

looks like it's taking BGR and displaying it as RGB (or viceversa). Add something like this to fix it.

b,g,r = cv2.split(img)       # get b,g,r
img = cv2.merge([r,g,b])     # switch it to rgb

reference

TheAtomicOption
  • 1,456
  • 1
  • 12
  • 21
  • 2
    CV2 reads images as numpy arrays so you can also just address the colors in reverse, like `rgb_img = bgr_img[..., ::-1]`, should save some memory – sapht Nov 01 '17 at 21:38