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.
Tip
Learn more: https://en.wikipedia.org/wiki/RGB_color_model
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:
- Returns:
RGB image with shape
(*, 3, H, W).
See also
rgb_to_bgr(): the same operation under the other name.BgrToRgb: the module form.
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:
alpha_valis as inrgb_to_rgba().
- Parameters:
- Return type:
- Returns:
RGBA image with shape
(*, 4, H, W).
Note
The current functionality is NOT supported by Torchscript.
See also
rgb_to_rgba(): takes an RGB image.rgba_to_bgr(): composites the alpha away and returns BGR.BgrToRgba: the module form, with the alpha stored.
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)isbgr_to_rgb().- Shape:
image:
(*, 3, H, W)output:
(*, 3, H, W)
See also
bgr_to_rgb(): the one-call form.RgbToBgr: the same channel reversal.
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, andout = conv(image)isbgr_to_rgba()with it.- Convention:
See the convention block of
bgr_to_rgba().
- Parameters:
alpha_val (
Union[float,Tensor]) – alpha, as inbgr_to_rgba(). A plain tensor is kept as a non-persistent buffer, so.to(device)moves it andstate_dictomits it.
- Shape:
image:
(*, 3, H, W)output:
(*, 4, H, W)
Note
The current functionality is NOT supported by Torchscript.
See also
bgr_to_rgba(): the one-call form.RgbToRgba: takes an RGB image.
Example
>>> input = torch.rand(2, 3, 4, 5) >>> rgba = BgrToRgba(1.) >>> output = rgba(input) # 2x4x4x5