Flávio Losada
Flávio Losada

Reputation: 11

OpenCV Python converting color-space image to YCbCr

I need convert an image from BGR to YCbCr in Python using OpenCV. I have an image with size/resolution 512x512, but when the image is opened, the size is 128x128.

I'm doing:

image = cv2.imread(imageName, cv2.COLOR_BGR2YCR_CB)

Could anyone help me?

Upvotes: 0

Views: 3023

Answers (1)

William Yolland
William Yolland

Reputation: 151

The problem:

If you look at the docs for imread, the function takes an integer flag called imreadmodes. This flag seems to accept information about resizing the image, rather than changing color spaces.

The solution:

I believe you are looking for the cv2.cvtColor function which uses a flag to determine the source and destination colorspaces.

Both flags are simple integer enumerations. I assume the imread function is simply doing the best it can with the wrong type of flag.

You probably want to do something like:

BGRImage = cv2.imread(imageName)
YCrCbImage = cv2.cvtColor(BGRImage, cv2.COLOR_BGR2YCR_CB)

Upvotes: 1

Related Questions