CVB++ 15.0
Spectral/ColorConvert
1// ---------------------------------------------------------------------------
5// ---------------------------------------------------------------------------
6
7#include <iostream>
8
9#include <cvb/spectral/spectral.hpp>
10#include <cvb/spectral/cube.hpp>
11#include <cvb/spectral/arithmetic.hpp>
12#include <cvb/spectral/interpolator.hpp>
13#include <cvb/spectral/convert_color_space.hpp>
14
15int main()
16{
17 try
18 {
19 // Load ENVI-Cubes
20 auto path = Cvb::ExpandPath(Cvb::InstallPath() + CVB_LIT("tutorial/Spectral/Images/Color/"));
21 Cvb::String objectHeader(path + CVB_LIT("ColorCube.hdr"));
22 Cvb::String objectBinary(path + CVB_LIT("ColorCube.bin"));
23 Cvb::String whiteRefHeader(path + CVB_LIT("WhiteCube.hdr"));
24 Cvb::String whiteRefBinary(path + CVB_LIT("WhiteCube.bin"));
25 Cvb::String blackRefHeader(path + CVB_LIT("DarkCube.hdr"));
26 Cvb::String blackRefBinary(path + CVB_LIT("DarkCube.bin"));
27
28 std::cout << "Load cube from: \n\t" <<
29 objectHeader << "\n\t" << objectBinary << std::endl;
30 std::cout << "White Reference: \n\t" <<
31 whiteRefHeader << "\n\t" << whiteRefBinary << std::endl;
32 std::cout << "Black Reference: \n\t" <<
33 blackRefHeader << "\n\t" << blackRefBinary << std::endl;
34
35 auto whiteRef = Cvb::Cube::Load(whiteRefHeader, whiteRefBinary);
36 auto blackRef = Cvb::Cube::Load(blackRefHeader, blackRefBinary);
37 auto imgCube = Cvb::Cube::Load(objectHeader, objectBinary);
38
39 // Normalize
40 auto normalizedCube = Cvb::Spectral::Normalization(*imgCube, *whiteRef, *blackRef, Cvb::Spectral::NormalizationMethod::AverageReferences1);
41 std::cout << "Normalization done!" << std::endl;
42
43 // Convert to Lab and RGB
44 auto interpolator = Cvb::Interpolator::Create(*normalizedCube,
48 auto labImg = Cvb::Spectral::CubeToLab(*normalizedCube, *interpolator);
49 std::cout << "Lab calculation done!" << std::endl;
50 auto rgbImg = Cvb::Spectral::LabToRGB8(*labImg, *interpolator);
51 std::cout << "sRGB calculation done!" << std::endl;
52
53 Cvb::String labFilename(Cvb::ExpandPath(CVB_LIT("%TMP%LabImage.tiff")));
54 Cvb::String rgbFilename(Cvb::ExpandPath(CVB_LIT("%TMP%sRGBImage.tiff")));
55 labImg->Save(labFilename);
56 rgbImg->Save(rgbFilename);
57 std::cout << "Saved Lab image to:\n\t" <<
58 labFilename << std::endl;
59 std::cout << "Saved sRGB image to:\n\t" <<
60 rgbFilename << std::endl;
61 }
62 catch (const std::exception& error)
63 {
64 std::cout << error.what() << std::endl;
65 }
66}
static std::unique_ptr< Cube > Load(Cvb::String EnviHeader, Cvb::String EnviBinary)
Static function Loads a cube from ENVI.
Definition: cube.hpp:315
static std::unique_ptr< Interpolator > Create(const Cube &cube, StdObserver stdObserver, StdIlluminant stdIlluminant, InterpolationMethod interpolationMethod)
Creates an Interpolator object.
Definition: interpolator.hpp:57
std::unique_ptr< Image > LabToRGB8(const Image &LabImage, const Interpolator &interpolator)
Converts a Lab image to a sRGB 8bit image.
Definition: convert_color_space.hpp:119
@ Linear
linear interpolation, at the border the last value is used
@ CIE2006_2deg
2006 Observer with 2 deg
std::unique_ptr< Cube > Normalization(const Cube &cubeIn, const Cube &whiteReference, const Cube &blackReference, NormalizationMethod normalizationMethod)
Normalizes a cube.
Definition: arithmetic.hpp:107
std::unique_ptr< Image > CubeToLab(const Cube &cube, const Interpolator &interpolator)
Converts a normalized cube to a Lab image.
Definition: convert_color_space.hpp:66