Why setting U and V channels to 0 leads to displaying a Blue picture?
What I did:
I read a BGR image and convert it to YUV color space.
Then I set its U and V channels to 0
I display the image and I see it is all blue (as if I set R and B to 0, instead)
Questions:
- Why setting U and V values to 0 leads the the G and R channels of the picture set to 0 also ?
- Why the image is displayed in blue (BGR color space) instead of YUV color space ?
Code:
import cv2
import numpy as np
img=cv2.imread('rgb_pic.png')
yuv_img=cv2.cvtColor(img,cv2.COLOR_BGR2YUV)
cv2.imwrite('yuv_pic',yuv_img)
cv2.namedWindow('YUV',cv2.WINDOW_AUTOSIZE)
cv2.imshow('YUV',yuv_img) # Displayed image is YUV, that is ok
cv2.waitKey(0)
cv2.destroyAllWindows()
im=yuv_img # Copy the YUV image to an other one
for in in range(im.shape[0]):
for j in range(im.shape[1]):
im[i,j,1]=0 # Set U to 0
im[i,j,2]=0 # Set V to 0
cv2.namedWindow('Result',cv2.WINDOW_AUTOSIZE)
cv2.imshow('Result',im) # Displayed image is totally BLUE :(
cv2.waitKey(0)
cv2.destroyAllWindows()
Results:
yuv_img
displayed like this (that is ok for me):
im
displayed like this (I do not understand why it is blue):
Regards, from BEGUERADJ