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 
15 int main()
16 {
17  try
18  {
19  // Load ENVI-Cubes
20  Cvb::String objectHeader(Cvb::ExpandPath(Cvb::InstallPath() + CVB_LIT("tutorial/Spectral/Images/Leaf/leaf.hdr")));
21  Cvb::String objectBinary(Cvb::ExpandPath(Cvb::InstallPath() + CVB_LIT("tutorial/Spectral/Images/Leaf/leaf.bin")));
22  Cvb::String whiteRefHeader(Cvb::ExpandPath(Cvb::InstallPath() + CVB_LIT("tutorial/Spectral/Images/Leaf/WRef.hdr")));
23  Cvb::String whiteRefBinary(Cvb::ExpandPath(Cvb::InstallPath() + CVB_LIT("tutorial/Spectral/Images/Leaf/WRef.bin")));
24  Cvb::String blackRefHeader(Cvb::ExpandPath(Cvb::InstallPath() + CVB_LIT("tutorial/Spectral/Images/Leaf/BRef.hdr")));
25  Cvb::String blackRefBinary(Cvb::ExpandPath(Cvb::InstallPath() + CVB_LIT("tutorial/Spectral/Images/Leaf/BRef.bin")));
26 
27  std::cout << "Load cube from: \n\t" <<
28  objectHeader << "\n\t" << objectBinary << std::endl;
29  std::cout << "White Reference: \n\t" <<
30  whiteRefHeader << "\n\t" << whiteRefBinary << std::endl;
31  std::cout << "Black Reference: \n\t" <<
32  blackRefHeader << "\n\t" << blackRefBinary << std::endl;
33 
34  auto whiteRef = Cvb::Cube::Load(whiteRefHeader, whiteRefBinary);
35  auto blackRef = Cvb::Cube::Load(blackRefHeader, blackRefBinary);
36  auto imgCube = Cvb::Cube::Load(objectHeader, objectBinary);
37 
38  // Normalize
39  auto normalizedCube = Cvb::Spectral::Normalization(*imgCube, *whiteRef, *blackRef, Cvb::Spectral::NormalizationMethod::AverageReferences1);
40  std::cout << "Normalization done!" << std::endl;
41 
42  // Convert to Lab and RGB
43  auto interpolator = Cvb::Interpolator::Create(*normalizedCube,
47  auto labImg = Cvb::Spectral::CubeToLab(*normalizedCube, *interpolator);
48  std::cout << "Lab calculation done!" << std::endl;
49  auto rgbImg = Cvb::Spectral::LabToRGB8(*labImg, *interpolator);
50  std::cout << "sRGB calculation done!" << std::endl;
51 
52  Cvb::String labFilename(Cvb::ExpandPath(CVB_LIT("%TMP%LabImage.tiff")));
53  Cvb::String rgbFilename(Cvb::ExpandPath(CVB_LIT("%TMP%sRGBImage.tiff")));
54  labImg->Save(labFilename);
55  rgbImg->Save(rgbFilename);
56  std::cout << "Saved Lab image to:\n\t" <<
57  labFilename << std::endl;
58  std::cout << "Saved sRGB image to:\n\t" <<
59  rgbFilename << std::endl;
60  }
61  catch (const std::exception& error)
62  {
63  std::cout << error.what() << std::endl;
64  }
65 }
std::unique_ptr< Image > CubeToLab(const Cube &cube, const Interpolator &interpolator)
Converts the cube to a Lab image.
Definition: convert_color_space.hpp:66
STL class.
static std::unique_ptr< Interpolator > Create(const Cube &cube, StdObserver stdObserver, StdIlluminant stdIlluminant, InterpolationMethod interpolationMethod)
Creates an Interpolator object.
Definition: interpolator.hpp:52
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
STL class.
static std::unique_ptr< Cube > Load(Cvb::String EnviHeader, Cvb::String EnviBinary)
Static function Loads a cube from ENVI.
Definition: cube.hpp:317
std::unique_ptr< Cube > Normalization(const Cube &cubeIn, const Cube &whiteReference, const Cube &blackReference, NormalizationMethod normalizationMethod)
Normalizes a cube.
Definition: arithmetic.hpp:103
linear interpolation, at the border the last value is used