megengine.functional.nn.cvt_color¶
- cvt_color(inp, mode='')[source]¶
Convert images from one format to another
Note
There are different supported modes for different combinations of
device
anddtype
.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”
Examples
>>> 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)