ColorSpaceConversion
Converts a color image from a color space to another one.
Access to parameter description
For an introduction to image filters: section Color Transforms.
The ColorSpaceConversion algorithm performs conversion between two color image formats or spaces. The color spaces supported are RGB and HSL.
Note that an image cannot be transformed into a color space to which it already belongs. By default, ImageDev considers color images belonging to RGB color space.
Thus, converting a color image to the RGB space, without having performed a conversion to HSL before, raises an exception.
See also
Access to parameter description
For an introduction to image filters: section Color Transforms.
The ColorSpaceConversion algorithm performs conversion between two color image formats or spaces. The color spaces supported are RGB and HSL.
RGB to HSL Conversion
Considering $$ C_1=\frac{\sqrt{3}}{2}\times (R-G) ~\mbox{and}~ C_2=B-\frac{1}{2}\times (R+G) $$ the HSL components are:- The intensity component: $$ L=\frac{R+G+B}{3} $$
- The saturation chromatic component: $$ S=\sqrt{C_1^2+C_2^2} $$ S is equal to 0 for gray level images (R = G = B) and is maximum for a fully saturated color.
- The hue chromatic component:
$$ H=\left\{\begin{array}{2l} acos \frac{C_1}{S} & \mbox {if $C_2\geq0$} \\ & \\ 2\pi-acos \frac{C_1}{S} & \mbox{if $C_2<0$} \end{array}\right. $$
The H value varies from 0 to $2\pi$ as it goes from red ($H = 0$) through green ($H = 2\pi/3$) and blue
($H = 4\pi/3$) and back to red.
Hue is converted from radians to a value between 0-255 and is not defined if the saturation is equal to 0.
Note that an image cannot be transformed into a color space to which it already belongs. By default, ImageDev considers color images belonging to RGB color space.
Thus, converting a color image to the RGB space, without having performed a conversion to HSL before, raises an exception.
See also
Function Syntax
This function returns outputColorImage.
// Function prototype
std::shared_ptr< iolink::ImageView > colorSpaceConversion( std::shared_ptr< iolink::ImageView > inputColorImage, ColorSpaceConversion::ColorSpace colorSpace, std::shared_ptr< iolink::ImageView > outputColorImage = NULL );
This function returns outputColorImage.
// Function prototype. color_space_conversion( input_color_image, color_space = ColorSpaceConversion.ColorSpace.HSL, output_color_image = None )
This function returns outputColorImage.
// Function prototype. public static IOLink.ImageView ColorSpaceConversion( IOLink.ImageView inputColorImage, ColorSpaceConversion.ColorSpace colorSpace = ImageDev.ColorSpaceConversion.ColorSpace.HSL, IOLink.ImageView outputColorImage = null );
Class Syntax
Parameters
Parameter Name | Description | Type | Supported Values | Default Value | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
inputColorImage |
The input color image. | Image | Multispectral | nullptr | ||||||||
colorSpace |
The output color space.
|
Enumeration | HSL | |||||||||
outputColorImage |
The output color image. Its dimensions and type are forced to the same values as the input. | Image | nullptr |
Parameter Name | Description | Type | Supported Values | Default Value | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
input_color_image |
The input color image. | image | Multispectral | None | ||||||||
color_space |
The output color space.
|
enumeration | HSL | |||||||||
output_color_image |
The output color image. Its dimensions and type are forced to the same values as the input. | image | None |
Parameter Name | Description | Type | Supported Values | Default Value | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
inputColorImage |
The input color image. | Image | Multispectral | null | ||||||||
colorSpace |
The output color space.
|
Enumeration | HSL | |||||||||
outputColorImage |
The output color image. Its dimensions and type are forced to the same values as the input. | Image | null |
Object Examples
std::shared_ptr< iolink::ImageView > ateneub = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "ateneub.jpg" ); ColorSpaceConversion colorSpaceConversionAlgo; colorSpaceConversionAlgo.setInputColorImage( ateneub ); colorSpaceConversionAlgo.setColorSpace( ColorSpaceConversion::ColorSpace::HSL ); colorSpaceConversionAlgo.execute(); std::cout << "outputColorImage:" << colorSpaceConversionAlgo.outputColorImage()->toString();
ateneub = ioformat.read_image(imagedev_data.get_image_path("ateneub.jpg")) color_space_conversion_algo = imagedev.ColorSpaceConversion() color_space_conversion_algo.input_color_image = ateneub color_space_conversion_algo.color_space = imagedev.ColorSpaceConversion.HSL color_space_conversion_algo.execute() print( "output_color_image:", str( color_space_conversion_algo.output_color_image ) )
ImageView ateneub = ViewIO.ReadImage( @"Data/images/ateneub.jpg" ); ColorSpaceConversion colorSpaceConversionAlgo = new ColorSpaceConversion { inputColorImage = ateneub, colorSpace = ColorSpaceConversion.ColorSpace.HSL }; colorSpaceConversionAlgo.Execute(); Console.WriteLine( "outputColorImage:" + colorSpaceConversionAlgo.outputColorImage.ToString() );
Function Examples
std::shared_ptr< iolink::ImageView > ateneub = ioformat::readImage( std::string( IMAGEDEVDATA_IMAGES_FOLDER ) + "ateneub.jpg" ); auto result = colorSpaceConversion( ateneub, ColorSpaceConversion::ColorSpace::HSL ); std::cout << "outputColorImage:" << result->toString();
ateneub = ioformat.read_image(imagedev_data.get_image_path("ateneub.jpg")) result = imagedev.color_space_conversion( ateneub, imagedev.ColorSpaceConversion.HSL ) print( "output_color_image:", str( result ) )
ImageView ateneub = ViewIO.ReadImage( @"Data/images/ateneub.jpg" ); IOLink.ImageView result = Processing.ColorSpaceConversion( ateneub, ColorSpaceConversion.ColorSpace.HSL ); Console.WriteLine( "outputColorImage:" + result.ToString() );