Scikit Image - Conversion from luv colorspace



The Luv color space also referred to as CIELUV, is a color space defined by the International Commission on Illumination (abbreviated CIE) in 1976. It is a transformation of the CIE XYZ color space and is designed to achieve perceptual uniformity. It is commonly used in various applications, including computer graphics and color-related tasks in image processing.

In the scikit-image library, you can use the CIELUV color space through the color.luv2rgb() and color.luv2xyz() functions. These functions allow you to convert images in the CIELUV color space to the RGB, and XYZ color spaces.

Converting CIE-Luv image to RGB image

The skimage.color.rgb() method is used to perform the conversion of an image in CIE-Luv color space to the RGB color space. Using the luv2xyz() and xyz2rgb() method.

Syntax

Following is the syntax of this function −

skimage.color.luv2rgb(luv, *, channel_axis=-1)

Parameters

  • luv(array_like): The input image in CIE-Luv color space. The shape of the array should be at least 2-D with the last dimension having a size of 3, representing the CIE-Luv channels.
  • channel_axis: This parameter indicates which axis of the array corresponds to the channels. By default, it is set to -1, which corresponds to the last axis.

Return Value

The method returns a ndarray representing the output image in RGB color space. The dimensions of the output array are the same as the input array.

Exception

It will raise the ValueError, if the lab input is not at least 2-D with a shape of (..., 3, ...), indicating the presence of the three channels.

Example

The following example demonstrates the conversion of an image from CIE-Luv color space image to an image in RGB color space using color.luv2rgb() method.

import numpy as np
from skimage import color, io
import matplotlib.pyplot as plt	
 
# Read an image
image = io.imread('Images/Fruits.jpg')

# Convert RGB to luv format
luv_image = color.rgb2luv(image)

# Again convert Luv to RGB 
rgb_image = color.luv2rgb(luv_image)
 
# Display the Luv and RGB images using Matplotlib
fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(10, 5))
 
axes[0].imshow(luv_image)
axes[0].set_title('Input CIE-Luv Image')
axes[0].axis('off')
 
axes[1].imshow(rgb_image)
axes[1].set_title('Output RGB Image')
axes[1].axis('off')

plt.tight_layout()
plt.show()

Output

When you run the above program, it will generate the following output −

Converting CIE-Luv image to XYZ image

The skimage.color.luv2xyz() method is used to perform the CIE-Luv color space to the XYZ color space conversion of an image.

Syntax

Following is the syntax of this function −

skimage.color.luv2xyz(luv, illuminant='D65', observer='2', *, channel_axis=-1)

Parameters

  • xyz (array_like): The input image in CIE-Luv color space. The shape of the array should be at least 2-D with the last dimension having a size of 3, representing the CIE-Luv channels.
  • illuminant: Representing the name of the illuminant {A, B, C, D50, D55, D65, D75, E}. The default value is 'D65'.
  • observer: Representing the aperture angle of the observer {2, 10, R}. The default value is '2'.
  • channel_axis: This parameter indicates which axis of the array corresponds to the channels. By default, it is set to -1, which corresponds to the last axis.

Return Value

The method returns a ndarray representing the output image in XYZ color space. The dimensions of the output array are the same as the input array.

Exception

It will raise the following exceptions −

  • ValueError: If the lab input is not at least 2-D with a shape of (..., 3, ...), indicating the presence of the three channels.
  • ValueError: If either the illuminant or the observer angle is unsupported or unknown.

Example

The following example demonstrates the conversion of an image from CIE-Luv color space image to an image in XYZ color space using color.luv2xyz() method.

import numpy as np
from skimage import color, io
import matplotlib.pyplot as plt	
 
# Read an image
image = io.imread('Images/Fruits.jpg')

# Convert RGB to XYZ format
luv_image = color.rgb2luv(image)

# Finally convert Luv to XYZ
xyz_image = color.luv2xyz(luv_image)
 
# Display the Luv and XYZ images using Matplotlib
fig, axes = plt.subplots(nrows=2, ncols=1, figsize=(10, 5))
 
axes[0].imshow(luv_image)
axes[0].set_title('Input CIE-Luv Image')
axes[0].axis('off')
 
axes[1].imshow(xyz_image)
axes[1].set_title('Output XYZ Image')
axes[1].axis('off')

plt.tight_layout()
plt.show()

Output

Advertisements