Reputation: 93
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
img=cv.imread("content.jpg")
x=np.array(img,dtype=np.uint8)
y=x[:,:,::-1]
plt.imshow(x,interpolation='nearest')
plt.show()
plt.imshow(y,interpolation='nearest')
plt.show()
I have some doubts regarding this code
y=x[:,:,::-1]
doing in this code. Upvotes: 0
Views: 542
Reputation: 150785
cv2
reads image as BGR
, that is, the pixels are in BGR
order. On the other hand plt.imshow()
uses the more common RBG
settings.
x[:,:,::-1]
essentially inverts the order of color, so BGR
becomes RGB
.
So the command
y = x[:,:,::-1]
is equivalent to cv2.cvtColor
:
y = cv2.cvtColor(x, cv2.COLOR_BGR2RGB)
Upvotes: 2