megengine.functional.nn.cvt_color

cvt_color(inp, mode='')[源代码]

将图像从一种格式转化成另一种格式。

参数
  • inp (Tensor) – 输入图片。

  • mode (str) – 颜色空间。

返回

转换结果。

注解

不同的 devicedtype 支持不同的颜色空间模式。

x86/ARM:

float32: “RGB2GRAY”, “RGB2YUV”, “YUV2RGB”, “GRAY2RGB”, “BGR2GRAY”

uint8: “RGB2GRAY”, “RGB2YUV”, “YUV2RGB”, “GRAY2RGB”, “RGBA2RGB”, “RGBA2BGR”, “RGBA2GRAY”, “RGB2BGR”, “BGR2GRAY”, “BGR2RGB”, “YUV2GRAY_NV21”, “YUV2RGB_NV21”, “YUV2BGR_NV21”, “YUV2GRAY_NV12”, “YUV2RGB_NV12”, “YUV2BGR_NV12”, “YUV2GRAY_YV12”, “YUV2RGB_YV12”, “YUV2BGR_YV12”, “YUV2GRAY_YU12”, “YUV2RGB_YU12”, “YUV2BGR_YU12”, “YCrCb2RGB”, “YCrCb2BGR”, “BT601_YUV2RGB_NV21”, “BT601_YUV2BGR_NV21”, “BT601_YUV2RGB_NV12”, “BT601_YUV2BGR_NV12”, “BT601_YUV2RGB_YV12”, “BT601_YUV2BGR_YV12” ,”BT601_YUV2RGB_YU12”, “BT601_YUV2BGR_YU12”

CUDA:

float32: “RGB2GRAY”, “BGR2GRAY”, “RGB2YUV”, “YUV2RGB”, “GRAY2RGB”

uint8: “RGB2GRAY”, “BGR2GRAY”, “RGB2YUV”, “YUV2RGB”, “GRAY2RGB”, “YUV2GRAY_NV12”, “YUV2GRAY_NV21”, “YUV2GRAY_YU12” “YUV2GRAY_YV12”, “YUV2RGB_NV12”, “YUV2RGB_NV21”, “YUV2BGR_NV12” “YUV2BGR_NV21”, “YUV2RGB_YU12”, “YUV2RGB_YV12”, “YUV2BGR_YU12”, “YUV2BGR_YV12”

实际案例

>>> import numpy as np
>>> x = mge.tensor(np.array([[[[-0.58675045, 1.7526233, 0.10702174]]]]).astype(np.float32))
>>> y = F.vision.cvt_color(x, mode="RGB2GRAY")
>>> y.numpy()
array([[[[0.86555195]]]], dtype=float32)