HSV#

Note

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

Functions#

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

Convert an image from RGB to HSV.

hsv = rgb_to_hsv(image) converts a (*, 3, H, W) RGB image in \([0, 1]\) to hue, saturation and value.

_images/rgb_to_hsv.png
Convention:

Channels are H, S, V at axis -3. Hue is in radians in \([0, 2\pi)\), unlike OpenCV, which uses degrees (halved for 8-bit images), and grayscale pixels have hue zero. S and V are in \([0, 1]\).

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

  • eps (float, optional) – added to V in the saturation denominator where V is non-zero. Default: 1e-8

Return type:

Tensor

Returns:

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

Note

See a working example here.

See also

Example

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

Convert an image from HSV to RGB.

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

Convention:

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

Parameters:

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

Modules#

class kornia.color.RgbToHsv(eps=1e-8)[source]#

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

hsv = RgbToHsv(eps) stores eps, and out = hsv(image) is rgb_to_hsv() with it.

Convention:
Parameters:

eps (float, optional) – added to V in the saturation denominator where V is non-zero. Default: 1e-8

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

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

See also

Example

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

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

out = HsvToRgb()(image) is hsv_to_rgb().

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

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

See also

Example

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