CVB++ 15.0
lut.hpp
1#pragma once
2
3#if defined _WIN32
4
5# include "../_cexports/c_foundation.h"
6
7# include "../global.hpp"
8# include "../image.hpp"
9# include "../exception.hpp"
10
11# include <iterator>
12# include <vector>
13# include <algorithm>
14# include <memory>
15# include <cstdint>
16
17namespace Cvb
18{
19 CVB_BEGIN_INLINE_NS
20
21 namespace Foundation
22 {
23
25
29 namespace Lut
30 {
31
42
44
46 struct LutLevel
47 {
49 double Level;
51 double Value;
52 };
53
55
63 template <class RANGE>
64 inline typename TypedRange<std::unique_ptr<Image>, int, RANGE>::type ApplyLut(const ImagePlane &plane,
65 const RANGE &values)
66 {
67 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
68 return CVB_CALL_CAPI(
69 ApplyLUT8Bit(plane.Parent().Handle(), plane.Plane(),
70 reinterpret_cast<CExports::cvbval_t *>(MakeRangeAdapter<int>(values, 256).Data()), resimg));
71 });
72 }
73
75
82 template <class RANGE>
83 inline typename TypedRange<std::unique_ptr<Image>, std::uint8_t, RANGE>::type ApplyLut(const ImagePlane &plane,
84 const RANGE &values)
85 /*template <class ByteRange, class = Private::IsTypedRange<ByteRange, uint8_t>, class = void>
86 inline std::unique_ptr<Image> ApplyLut (const ImagePlane & plane, const ByteRange &values)*/
87 {
88 std::vector<int> values_int;
89 std::copy(std::begin(values), std::end(values), std::back_inserter(values_int));
90 return ApplyLut(plane, values_int);
91 }
92
95
103 template <class RANGE>
104 inline typename TypedRange<std::unique_ptr<Image>, LutLevel, RANGE>::type
105 ApplyLut(const ImagePlane &plane, const RANGE &levels, LutInterpolation interpolation)
106 /*template <class LutLevelRange, class = Private::IsTypedRange<LutLevelRange, LutLevel>>
107 inline std::unique_ptr<Image> ApplyLut (const ImagePlane & plane, const LutLevelRange &levels, LutInterpolation
108 interpolation) */
109 {
110 std::vector<double> levelData, valueData;
111 for (auto &&lutLevel : levels)
112 {
113 levelData.push_back(lutLevel.Level);
114 valueData.push_back(lutLevel.Value);
115 }
116
117 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
118 switch (interpolation)
119 {
121 return CVB_CALL_CAPI(ApplyLUTGeneric(
122 plane.Parent().Handle(), plane.Plane(), static_cast<CExports::cvbval_t>(levelData.size()),
123 const_cast<double *>(levelData.data()), const_cast<double *>(valueData.data()), resimg));
125 return CVB_CALL_CAPI(ApplyLUTLinear(
126 plane.Parent().Handle(), plane.Plane(), static_cast<CExports::cvbval_t>(levelData.size()),
127 const_cast<double *>(levelData.data()), const_cast<double *>(valueData.data()), resimg));
129 return CVB_CALL_CAPI(ApplyLUTCubic(
130 plane.Parent().Handle(), plane.Plane(), static_cast<CExports::cvbval_t>(levelData.size()),
131 const_cast<double *>(levelData.data()), const_cast<double *>(valueData.data()), resimg));
132 default:
133 throw std::invalid_argument("unknown LUT interpolation mode");
134 }
135 });
136 }
137
138 } /* namespace Lut */
139
141 using Lut::LutLevel;
142
143 using Lut::ApplyLut;
144
145 } /* namespace Foundation */
146 CVB_END_INLINE_NS
147} /* namespace Cvb */
148
149#endif
T back_inserter(T... args)
T begin(T... args)
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:232
Image plane information container.
Definition decl_image_plane.hpp:29
int Plane() const noexcept
Plane index in the image, to which this plane refers to.
Definition decl_image_plane.hpp:147
const Image & Parent() const noexcept
Image to which this plane descriptor refers to.
Definition detail_image_plane.hpp:87
T copy(T... args)
T end(T... args)
cvbres_t ApplyLUTGeneric(IMG ImgIn, long Index, long NumLevels, double Levels[], double Values[], IMG &ImgOut)
cvbres_t ApplyLUTLinear(IMG ImgIn, long Index, long NumLevels, double Levels[], double Values[], IMG &ImgOut)
cvbres_t ApplyLUT8Bit(IMG ImgIn, long Index, long Values[256], IMG &ImgOut)
cvbres_t ApplyLUTCubic(IMG ImgIn, long Index, long NumLevels, double Levels[], double Values[], IMG &ImgOut)
Namespace for collection of lookup table functions from the Foundation package.
Definition lut.hpp:30
LutInterpolation
Different approaches for interpolating between lookup table (LUT) values and levels.
Definition lut.hpp:34
@ Linear
Linear interpolation between two adjacent LUT levels.
Definition lut.hpp:38
@ Constant
LUT values are constant between two LUT levels.
Definition lut.hpp:36
@ Cubic
Cubic interpolation between two adjacent LUT levels.
Definition lut.hpp:40
TypedRange< std::unique_ptr< Image >, int, RANGE >::type ApplyLut(const ImagePlane &plane, const RANGE &values)
Apply a lookup table to an 8 bit per pixel input image plane.
Definition lut.hpp:64
Namespace for the Foundation package.
Definition decl_metric_aqs12_calibration_piece.hpp:11
Root namespace for the Image Manager interface.
Definition c_bayer_to_rgb.h:17
Struct that combines a LUT (lookup table) level and the value assigned to this level.
Definition lut.hpp:47
double Level
Gray value level at which the value applies.
Definition lut.hpp:49
double Value
Transformed gray value, that applies to the associated gray level.
Definition lut.hpp:51