HLS#

Note

Hue is returned in radians in \([0, 2\pi)\); see Conventions & Pitfalls.

Functions#

kornia.color.rgb_to_hls(image, eps=1e-8)[source]#

Convert an RGB image to HLS.

hls = rgb_to_hls(image) converts a (*, 3, H, W) RGB image in \([0, 1]\) to hue, lightness and saturation.

_images/rgb_to_hls.png
Convention:

Channels are H, L, S at axis -3. Hue is measured in radians in \([0, 2\pi)\), unlike OpenCV, which uses degrees (halved for 8-bit images).

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

  • eps (float, optional) – added to the chroma and saturation denominators where they are non-zero. Zero denominators are guarded, so eps=0 is valid. Default: 1e-8

Return type:

Tensor

Returns:

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

See also

Example

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

Convert an HLS image to RGB.

rgb = hls_to_rgb(image) converts a (*, 3, H, W) image of hue in radians, lightness in \([0, 1]\) and saturation in \([0, 1]\) to RGB.

Convention:

Channels are H, L, S at axis -3. Hue wraps modulo 2π. The result is not clipped, so lightness or saturation outside \([0, 1]\) can give RGB values outside it.

Parameters:

image (Tensor) – HLS 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 = hls_to_rgb(input)  # 2x3x4x5

Modules#

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

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

out = RgbToHls()(image) is rgb_to_hls() with its default eps.

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

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

See also

Examples

>>> input = torch.rand(2, 3, 4, 5)
>>> hls = RgbToHls()
>>> output = hls(input)  # 2x3x4x5
class kornia.color.HlsToRgb(*args, **kwargs)[source]#

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

out = HlsToRgb()(image) is hls_to_rgb().

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

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

See also

References

https://en.wikipedia.org/wiki/HSL_and_HSV

Examples

>>> input = torch.rand(2, 3, 4, 5)
>>> rgb = HlsToRgb()
>>> output = rgb(input)  # 2x3x4x5