Color Components Code Snippet

This code snippet shows how to create a color image from three grayscale images and extract the luminance component from a color image.

C++

#include <eVision/EasyColor/EColorLookup.h>
#include <eVision/EasyColor/EasyColor.h>
using namespace eVision;
// Images constructor
EImageBW8 red, green, blue;
EImageC24 colorImage;
EImageBW8 luminance;
// ...
// Source and destination images must have the same size
colorImage.SetSize(&red);
// Combine the color planes into a color image
EasyColor::Compose(&red, &green, &blue, &colorImage);
// Prepare a lookup table for
// the RGB to LSH conversion
EColorLookup lookup;
lookup.ConvertFromRgb(EColorSystem_Lsh);
// Source and destination images must have the same size
luminance.SetSize(&colorImage);
// Get the Luminance component
EasyColor::GetComponent(&colorImage, &luminance, 0, &lookup);

C#

using eVision;
// Images constructor
EImageBW8 red = new EImageBW8();
EImageBW8 green = new EImageBW8();
EImageBW8 blue = new EImageBW8();
EImageC24 colorImage = new EImageC24();
EImageBW8 luminance = new EImageBW8();
// ...
// Source and destination images must have the same size
colorImage.SetSize(red);
// Combine the color planes into a color image
EasyColor.Compose(red, green, blue, colorImage);
// Prepare a lookup table for
// the RGB to LSH conversion
EColorLookup lookup = new EColorLookup();
lookup.ConvertFromRgb(EColorSystem.Lsh);
// Source and destination images must have the same size
luminance.SetSize(colorImage);
// Get the Luminance component
EasyColor.GetComponent(colorImage, luminance, 0, lookup);

Python

import eVision
# Images constructor
red = eVision.EImageBW8()
green = eVision.EImageBW8()
blue = eVision.EImageBW8()
color_image = eVision.EImageC24()
luminance = eVision.EImageBW8()
# ...
# Source and destination images must have the same size
color_image.SetSize(red)
# Combine the color planes into a color image
eVision.EasyColor.Compose(red, green, blue, color_image)
# Prepare a lookup table for
# the RGB to LSH conversion
lookup = eVision.EColorLookup()
lookup.ConvertFromRgb(eVision.EColorSystem.Lsh)
# Source and destination images must have the same size
luminance.SetSize(color_image)
# Get the Luminance component
eVision.EasyColor.GetComponent(color_image, luminance, 0, lookup)