# kornia.color¶

The functions in this section perform various color space conversions.

rgb_to_grayscale(input: torch.Tensor) → torch.Tensor[source]

Convert an RGB image to grayscale.

See RgbToGrayscale for details.

Parameters: input (torch.Tensor) – Image to be converted to grayscale. Grayscale version of the image. torch.Tensor
rgb_to_hsv(image)[source]

Convert an RGB image to HSV.

Parameters: input (torch.Tensor) – RGB Image to be converted to HSV. HSV version of the image. torch.Tensor
hsv_to_rgb(image)[source]

Convert an HSV image to RGB The image data is assumed to be in the range of (0, 1).

Parameters: input (torch.Tensor) – RGB Image to be converted to HSV. HSV version of the image. torch.Tensor
rgb_to_bgr(image: torch.Tensor) → torch.Tensor[source]

Convert a RGB image to BGR.

See RgbToBgr for details.

Parameters: image (torch.Tensor) – RGB Image to be converted to BGR. BGR version of the image. torch.Tensor
bgr_to_rgb(image: torch.Tensor) → torch.Tensor[source]

Convert a BGR image to RGB.

See BgrToRgb for details.

Parameters: input (torch.Tensor) – BGR Image to be converted to RGB. RGB version of the image. torch.Tensor
normalize(data: torch.Tensor, mean: Union[torch.Tensor, float], std: Union[torch.Tensor, float]) → torch.Tensor[source]

Normalise the image with channel-wise mean and standard deviation.

See Normalize for details.

Parameters: data (torch.Tensor) – The image tensor to be normalised. mean (torch.Tensor or float) – Mean for each channel. std (torch.Tensor or float) – Standard deviations for each channel. Returns – torch.Tensor: The normalised image tensor.
adjust_brightness(input: torch.Tensor, brightness_factor: Union[float, torch.Tensor]) → torch.Tensor[source]

See AdjustBrightness for details.

adjust_contrast(input: torch.Tensor, contrast_factor: Union[float, torch.Tensor]) → torch.Tensor[source]

See AdjustContrast for details.

adjust_saturation(input: torch.Tensor, saturation_factor: float) → torch.Tensor[source]

Adjust color saturation of an image.

See AdjustSaturation for details.

adjust_hue(input: torch.Tensor, hue_factor: float) → torch.Tensor[source]

See AdjustHue for details.

adjust_gamma(input: torch.Tensor, gamma: float, gain: float = 1.0) → torch.Tensor[source]

Perform gamma correction on an image.

See AdjustGamma for details.

class RgbToGrayscale[source]

convert image to grayscale version of image.

the image data is assumed to be in the range of (0, 1).

Parameters: input (torch.Tensor) – image to be converted to grayscale. grayscale version of the image. torch.Tensor
shape:
• input: $$(*, 3, H, W)$$
• output: $$(*, 1, H, W)$$

Examples:

>>> input = torch.rand(2, 3, 4, 5)
>>> gray = kornia.image.RgbToGrayscale()
>>> output = gray(input)  # 2x1x4x5

class RgbToHsv[source]

Convert image from RGB to HSV.

The image data is assumed to be in the range of (0, 1).

Parameters: image (torch.Tensor) – RGB image to be converted to HSV. HSV version of the image. torch.tensor
shape:
• image: $$(*, 3, H, W)$$
• output: $$(*, 3, H, W)$$
class HsvToRgb[source]

Convert image from HSV to Rgb The image data is assumed to be in the range of (0, 1).

Parameters: image (torch.Tensor) – RGB image to be converted to HSV. HSV version of the image. torch.tensor
shape:
• image: $$(*, 3, H, W)$$
• output: $$(*, 3, H, W)$$
class RgbToBgr[source]

Convert image from RGB to BGR.

The image data is assumed to be in the range of (0, 1).

Parameters: image (torch.Tensor) – RGB image to be converted to BGR BGR version of the image. torch.Tensor
shape:
• image: $$(*, 3, H, W)$$
• output: $$(*, 3, H, W)$$
class BgrToRgb[source]

Convert image from BGR to RGB.

The image data is assumed to be in the range of (0, 1).

Parameters: image (torch.Tensor) – BGR image to be converted to RGB. RGB version of the image. torch.Tensor
shape:
• image: $$(*, 3, H, W)$$
• output: $$(*, 3, H, W)$$
class Normalize(mean: Union[torch.Tensor, float], std: Union[torch.Tensor, float])[source]

Normalize a tensor image or a batch of tensor images with mean and standard deviation. Input must be a tensor of shape (C, H, W) or a batch of tensors $$(*, C, H, W)$$.

Given mean: (M1,...,Mn) and std: (S1,..,Sn) for n channels, this transform will normalize each channel of the input torch.Tensor i.e. input[channel] = (input[channel] - mean[channel]) / std[channel]

Parameters: mean (torch.Tensor or float) – Mean for each channel. std (torch.Tensor or float) – Standard deviations for each channel.
class AdjustBrightness(brightness_factor: Union[float, torch.Tensor])[source]

The input image is expected to be in the range of [0, 1].

Parameters: input (torch.Tensor) – Image/Input to be adjusted in the shape of (*, N). brightness_factor (Union[float, torch.Tensor]) – Brightness adjust factor per element in the batch. 0 generates a compleatly black image, 1 does not modify the input image while any other non-negative number modify the brightness by this factor. Adjusted image. torch.Tensor
class AdjustContrast(contrast_factor: Union[float, torch.Tensor])[source]

The input image is expected to be in the range of [0, 1].

Parameters: input (torch.Tensor) – Image to be adjusted in the shape of (*, N). contrast_factor (Union[float, torch.Tensor]) – Contrast adjust factor per element in the batch. 0 generates a compleatly black image, 1 does not modify the input image while any other non-negative number modify the brightness by this factor. Adjusted image. torch.Tensor
class AdjustSaturation(saturation_factor: float)[source]

Adjust color saturation of an image.

The input image is expected to be an RGB image in the range of [0, 1].

Parameters: input (torch.Tensor) – Image/Tensor to be adjusted in the shape of (*, N). saturation_factor (float) – How much to adjust the saturation. 0 will give a black white image, 1 will give the original image while 2 will enhance the saturation (and) – a factor of 2. (by) – Adjusted image. torch.Tensor
class AdjustHue(hue_factor: float)[source]

class AdjustGamma(gamma: float, gain: float = 1.0)[source]