Color conversion#

Conversions between color spaces, on float image tensors of shape (*, C, H, W). Every conversion except rgb_to_y() exists as a function and as an nn.Module; each page below documents one color scheme.

All functions#

rgb_to_grayscale

Convert an RGB image to grayscale.

bgr_to_grayscale

Convert a BGR image to grayscale.

grayscale_to_rgb

Convert a grayscale image to RGB.

rgb_to_bgr

Convert an RGB image to BGR.

bgr_to_rgb

Convert a BGR image to RGB.

rgb_to_rgb255

Scale an RGB image from [0, 1] to [0, 255].

rgb255_to_rgb

Scale an RGB image from [0, 255] to [0, 1].

rgb255_to_normals

Map an RGB image in [0, 255] to unit surface normals.

normals_to_rgb255

Map surface normals in [-1, 1] to RGB in [0, 255].

rgb_to_rgba

Convert an RGB image to RGBA by appending an alpha channel.

bgr_to_rgba

Convert a BGR image to RGBA, with the color channels in RGB order.

rgba_to_rgb

Convert an RGBA image to RGB by compositing it over a background.

rgba_to_bgr

Convert an RGBA image to BGR by compositing it over white.

rgb_to_linear_rgb

Convert an sRGB image to linear RGB.

linear_rgb_to_rgb

Convert a linear RGB image to sRGB.

rgb_to_hls

Convert an RGB image to HLS.

hls_to_rgb

Convert an HLS image to RGB.

rgb_to_hsv

Convert an image from RGB to HSV.

hsv_to_rgb

Convert an image from HSV to RGB.

rgb_to_lab

Convert an sRGB image to Lab.

lab_to_rgb

Convert a Lab image to sRGB.

rgb_to_luv

Convert an sRGB image to Luv.

luv_to_rgb

Convert a Luv image to sRGB.

rgb_to_xyz

Convert a linear RGB image to XYZ.

xyz_to_rgb

Convert an XYZ image to linear RGB.

rgb_to_ycbcr

Convert an RGB image to full-range YCbCr.

rgb_to_y

Convert an RGB image to the Y channel of YCbCr.

ycbcr_to_rgb

Convert a full-range YCbCr image to RGB.

rgb_to_yuv

Convert an RGB image to YUV.

yuv_to_rgb

Convert a YUV image to RGB.

rgb_to_yuv420

Convert an RGB image to YUV 4:2:0 planes.

yuv420_to_rgb

Convert YUV 4:2:0 planes to RGB.

rgb_to_yuv422

Convert an RGB image to YUV 4:2:2 planes.

yuv422_to_rgb

Convert YUV 4:2:2 planes to RGB.

rgb_to_raw

Sample an RGB image into a Bayer raw image.

raw_to_rgb

Demosaic a Bayer raw image to RGB.

raw_to_rgb_2x2_downscaled

Convert a Bayer raw image to RGB at half the height and width.