BGR#

BGR is the channel order OpenCV uses. bgr_to_rgb() reverses the channels; bgr_to_rgba() also appends an alpha channel and returns RGBA, not BGRA.

Functions#

kornia.color.bgr_to_rgb(image)[source]#

Convert a BGR image to RGB.

rgb = bgr_to_rgb(image) reorders the channels of a (*, 3, H, W) BGR image, as OpenCV loads it, to RGB.

Convention:

Reverses the three channels at axis -3; it is its own inverse.

Parameters:

image (Tensor) – BGR image with shape (*, 3, H, W).

Return type:

Tensor

Returns:

RGB image with shape (*, 3, H, W).

See also

Example

>>> input = torch.rand(2, 3, 4, 5)
>>> output = bgr_to_rgb(input) # 2x3x4x5
kornia.color.bgr_to_rgba(image, alpha_val)[source]#

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

rgba = bgr_to_rgba(image, alpha_val) reverses the channels of a (*, 3, H, W) BGR image and appends alpha.

Convention:
Parameters:
  • image (Tensor) – BGR image with shape (*, 3, H, W).

  • alpha_val (Union[float, Tensor]) – alpha, one float or a tensor.

Return type:

Tensor

Returns:

RGBA image with shape (*, 4, H, W).

Note

The current functionality is NOT supported by Torchscript.

See also

Example

>>> input = torch.rand(2, 3, 4, 5)
>>> output = bgr_to_rgba(input, 1.) # 2x4x4x5

Modules#

class kornia.color.BgrToRgb(*args, **kwargs)[source]#

Convert an image from BGR to RGB (module form).

out = BgrToRgb()(image) is bgr_to_rgb().

Shape:
  • image: (*, 3, H, W)

  • output: (*, 3, H, W)

See also

Example

>>> input = torch.rand(2, 3, 4, 5)
>>> rgb = BgrToRgb()
>>> output = rgb(input)  # 2x3x4x5
class kornia.color.BgrToRgba(alpha_val)[source]#

Convert an image from BGR to RGBA (module form).

conv = BgrToRgba(alpha_val) stores the alpha, and out = conv(image) is bgr_to_rgba() with it.

Convention:
Parameters:

alpha_val (Union[float, Tensor]) – alpha, as in bgr_to_rgba(). A plain tensor is kept as a non-persistent buffer, so .to(device) moves it and state_dict omits it.

Shape:
  • image: (*, 3, H, W)

  • output: (*, 4, H, W)

Note

The current functionality is NOT supported by Torchscript.

See also

Example

>>> input = torch.rand(2, 3, 4, 5)
>>> rgba = BgrToRgba(1.)
>>> output = rgba(input)  # 2x4x4x5