Common Vision Blox 15.0
Loading...
Searching...
No Matches
Spectral/Cvb++/ColorConvert

This example program is located in your CVB installation under %CVB%Tutorial/Spectral/Cvb++/ColorConvert.

main.cpp:

// Example for normalizing and calculating Lab and sRGB images on **hyperspectral cubes**.
// ---------------------------------------------------------------------------
// ---------------------------------------------------------------------------
#include <iostream>
#include <cvb/spectral/spectral.hpp>
#include <cvb/spectral/cube.hpp>
#include <cvb/spectral/arithmetic.hpp>
#include <cvb/spectral/interpolator.hpp>
#include <cvb/spectral/convert_color_space.hpp>
int main()
{
try
{
// Load ENVI-Cubes
auto path = Cvb::ExpandPath(Cvb::InstallPath() + CVB_LIT("tutorial/Spectral/Images/Color/"));
Cvb::String objectHeader(path + CVB_LIT("ColorCube.hdr"));
Cvb::String objectBinary(path + CVB_LIT("ColorCube.bin"));
Cvb::String whiteRefHeader(path + CVB_LIT("WhiteCube.hdr"));
Cvb::String whiteRefBinary(path + CVB_LIT("WhiteCube.bin"));
Cvb::String blackRefHeader(path + CVB_LIT("DarkCube.hdr"));
Cvb::String blackRefBinary(path + CVB_LIT("DarkCube.bin"));
std::cout << "Load cube from: \n\t" <<
objectHeader << "\n\t" << objectBinary << std::endl;
std::cout << "White Reference: \n\t" <<
whiteRefHeader << "\n\t" << whiteRefBinary << std::endl;
std::cout << "Black Reference: \n\t" <<
blackRefHeader << "\n\t" << blackRefBinary << std::endl;
auto whiteRef = Cvb::Cube::Load(whiteRefHeader, whiteRefBinary);
auto blackRef = Cvb::Cube::Load(blackRefHeader, blackRefBinary);
auto imgCube = Cvb::Cube::Load(objectHeader, objectBinary);
// Normalize
auto normalizedCube = Cvb::Spectral::Normalization(*imgCube, *whiteRef, *blackRef, Cvb::Spectral::NormalizationMethod::AverageReferences1);
std::cout << "Normalization done!" << std::endl;
// Convert to Lab and RGB
auto interpolator = Cvb::Interpolator::Create(*normalizedCube,
Cvb::Spectral::StdObserver::CIE2006_2deg,
Cvb::Spectral::StdIlluminant::D65,
Cvb::Spectral::InterpolationMethod::Linear);
auto labImg = Cvb::Spectral::CubeToLab(*normalizedCube, *interpolator);
std::cout << "Lab calculation done!" << std::endl;
auto rgbImg = Cvb::Spectral::LabToRGB8(*labImg, *interpolator);
std::cout << "sRGB calculation done!" << std::endl;
Cvb::String labFilename(Cvb::ExpandPath(CVB_LIT("%TMP%LabImage.tiff")));
Cvb::String rgbFilename(Cvb::ExpandPath(CVB_LIT("%TMP%sRGBImage.tiff")));
labImg->Save(labFilename);
rgbImg->Save(rgbFilename);
std::cout << "Saved Lab image to:\n\t" <<
labFilename << std::endl;
std::cout << "Saved sRGB image to:\n\t" <<
rgbFilename << std::endl;
}
catch (const std::exception& error)
{
std::cout << error.what() << std::endl;
}
}
static std::unique_ptr< Cube > Load(Cvb::String EnviHeader, Cvb::String EnviBinary)
static std::unique_ptr< Interpolator > Create(const Cube &cube, StdObserver stdObserver, StdIlluminant stdIlluminant, InterpolationMethod interpolationMethod)
std::unique_ptr< Image > LabToRGB8(const Image &LabImage, const Interpolator &interpolator)
std::unique_ptr< Cube > Normalization(const Cube &cubeIn, const Cube &whiteReference, const Cube &blackReference, NormalizationMethod normalizationMethod)
std::unique_ptr< Image > CubeToLab(const Cube &cube, const Interpolator &interpolator)
String ExpandPath(const String &path)
std::string String
String InstallPath()