和YCbCr颜色空间图像

和YCbCr颜色空间图像

本文介绍了在Opencv Python中将RGB图像转换为YUV和YCbCr颜色空间图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮助我使用opencv Python将RGB颜色空间图像转换为YUV颜色空间图像和YCbCr颜色空间图像吗?

Can anyone help me to convert an RGB colour space image to YUV colour space image and to YCbCr colour space image using opencv Python?

推荐答案

使用cv2.cvtColor(src, code)转换Color-Space,代码以COLOR_开头.

Use cv2.cvtColor(src, code) to convert Color-Space, the code starts with COLOR_.

您可以使用它来查找颜色代码.

You can use this to look for the color code.

import cv2
## get all color codes
codes = [x for x in dir(cv2) if x.startswith("COLOR_")]

## print first three color codes
print(codes[:3])
# ['COLOR_BAYER_BG2BGR', 'COLOR_BAYER_BG2BGRA', 'COLOR_BAYER_BG2BGR_EA']

## print all color codes
print(codes)

如果将图像读入BGR空间,请使用cv2.COLOR_BGR2YUVcv2.COLOR_BGR2YCrCb:

If you read the image into BGR space, then use cv2.COLOR_BGR2YUV and cv2.COLOR_BGR2YCrCb:

#cv2.COLOR_BGR2YUV
#cv2.COLOR_BGR2YCrCb

img = cv2.imread("test.png")
yuv = cv2.cvtColor(img, cv2.COLOR_BGR2YUV)
cv2.imwrite("yuv.png", yuv)

如果将图像读入RGB空间,请使用cv2.COLOR_RGB2YUVcv2.COLOR_RGB2YCrCb.

If you read the image into RGB space, then use cv2.COLOR_RGB2YUV and cv2.COLOR_RGB2YCrCb.

以下是示例图片(在BGR-HSV-YUV-YCRCB颜色空间中):

Here is an example image(in BGR-HSV-YUV-YCRCB color spaces):

这篇关于在Opencv Python中将RGB图像转换为YUV和YCbCr颜色空间图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-31 05:43