CVB++ 15.0
bayer_conversion.hpp
1#pragma once
2
3#include "../_cexports/c_bayer_to_rgb.h"
4
5#include "../global.hpp"
6#include "../image.hpp"
7#include "../exception.hpp"
8#include "../wrapped_image.hpp"
9#include "../white_balance.hpp"
10#include "../rect.hpp"
11#include "../size_2d.hpp"
12#include "../area_2d.hpp"
13
14namespace Cvb
15{
16 CVB_BEGIN_INLINE_NS
17
18 namespace Foundation
19 {
20
22
27 {
28
30 enum class RGBConversion
31 {
37 Linear = CExports::RGB_INTERPOLATE,
43 NearestNeighbor = CExports::RGB_NEIGHBOUR,
50 HalfResolution = CExports::RGB_HALF
51 };
52
54
57 enum class BayerPattern
58 {
60 GreenBlue = CExports::PM_GREENBLUE,
62 BlueGreen = CExports::PM_BLUEGREEN,
64 RedGreen = CExports::PM_REDGREEN,
66 GreenRed = CExports::PM_GREENRED
67 };
68
70 enum class GammaCorrection
71 {
73 Gamma100 = CExports::GAMMA_100,
75 Gamma045 = CExports::GAMMA_045,
77 Gamma060 = CExports::GAMMA_060
78 };
79
81
95 {
96 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
97 /* The dummy image is only asked for its size... so we do not need actual image data. */
98 auto dummy = WrappedImage::FromGrey8Pixels(reinterpret_cast<void *>(42), width, height);
99 return CVB_CALL_CAPI(
100 etCreateOutputImage(dummy->Handle(), resimg, static_cast<CExports::B2RGB_InterpolationMode>(mode)));
101 });
102 }
103
105
118 {
119 return CreateDestinationImage(size.Width(), size.Height(), mode);
120 }
121
123
134 inline void BayerToRGB(const Image &imageSrc, Image &imageDst, BayerPattern pattern, RGBConversion conversion,
137 {
138 /* Note: the binary compatibility between WhiteBalanceFactors and WB is guaranteed, therefore the cast below is
139 * legal. */
140 CExports::IMG dstHandle = imageDst.Handle();
141 CVB_CALL_CAPI_CHECKED(
142 etBayerToRGB(imageSrc.Handle(), dstHandle, static_cast<CExports::B2RGB_PixelMode>(pattern),
143 static_cast<CExports::B2RGB_InterpolationMode>(conversion),
144 static_cast<CExports::B2RGB_Gamma>(gamma), reinterpret_cast<CExports::WB &>(whiteBalance)));
145 imageDst.RaisePixelContentChanged();
146 }
147
149
159 inline std::unique_ptr<Image> BayerToRGB(const Image &image, BayerPattern pattern, RGBConversion conversion,
162 {
163 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
164 /* Note: the binary compatibility between WhiteBalanceFactors and WB is guaranteed, therefore the cast below
165 * is legal. */
166 return CVB_CALL_CAPI(etBayerToRGB(image.Handle(), resimg, static_cast<CExports::B2RGB_PixelMode>(pattern),
167 static_cast<CExports::B2RGB_InterpolationMode>(conversion),
168 static_cast<CExports::B2RGB_Gamma>(gamma),
169 reinterpret_cast<CExports::WB &>(whiteBalance)));
170 });
171 }
172
174
184 inline std::unique_ptr<Image> BayerToMono(const Image &image, BayerPattern pattern, RGBConversion conversion,
187 {
188 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
189 /* Note: the binary compatibility between WhiteBalanceFactors and WB is guaranteed, therefore the cast below
190 * is legal. */
191 return CVB_CALL_CAPI(etBayerToMono(image.Handle(), resimg, static_cast<CExports::B2RGB_PixelMode>(pattern),
192 static_cast<CExports::B2RGB_InterpolationMode>(conversion),
193 static_cast<CExports::B2RGB_Gamma>(gamma),
194 reinterpret_cast<CExports::WB &>(whiteBalance)));
195 });
196 }
197
199
207 {
208 return Internal::DoResCallObjectOut<Image>([&](void *&resimg) {
209 return CVB_CALL_CAPI(etRGBToBayer(image.Handle(), resimg, static_cast<CExports::B2RGB_PixelMode>(pattern)));
210 });
211 }
212
214
223 {
224 WhiteBalanceFactors wb(0, 0, 0);
225 /* Note: the binary compatibility between Area2D and TArea is guaranteed, therefore the cast below is legal. */
226 CVB_CALL_CAPI_CHECKED(etWhiteBalance(image.Handle(), static_cast<CExports::B2RGB_PixelMode>(pattern),
227 CExports::WB_SET, reinterpret_cast<CExports::TArea &>(aoi),
228 reinterpret_cast<CExports::WB &>(wb)));
229 return wb;
230 }
231
233
241 {
242 return GetWhiteBalance(image, pattern, Area2D(static_cast<Rect<double>>(image.Bounds())));
243 }
244
245 } /* namespace BayerConversion */
246
250
256
257 } /* namespace Foundation */
258 CVB_END_INLINE_NS
259} /* namespace Cvb */
Structure that represents an area of interest in the image.
Definition area_2d.hpp:21
The Common Vision Blox image.
Definition decl_image.hpp:50
void RaisePixelContentChanged() const
Inform clients listening to the pixel content changed event, that the image data has been completely ...
Definition decl_image.hpp:448
Rect< int > Bounds() const noexcept
Bounding rectangle of the image in pixels.
Definition decl_image.hpp:438
void * Handle() const noexcept
Classic API image handle.
Definition decl_image.hpp:237
Rectangle object.
Definition rect.hpp:24
Stores a pair of numbers that represents the width and the height of a subject, typically a rectangle...
Definition size_2d.hpp:20
T Height() const noexcept
Gets the vertical component of the size.
Definition size_2d.hpp:77
T Width() const noexcept
Gets the horizontal component of the size.
Definition size_2d.hpp:57
Factors for white balance correction.
Definition white_balance.hpp:22
static WhiteBalanceFactors Identity() noexcept
Identity transformation leaving all values as they are.
Definition white_balance.hpp:112
static std::unique_ptr< WrappedImage > FromGrey8Pixels(void *buffer, int width, int height)
Wraps, without copying, the given Mono8 pixel buffer in a CvbImage.
Definition decl_wrapped_image.hpp:61
Namespace for collection of functions converting images with a Bayer pattern.
Definition bayer_conversion.hpp:27
BayerPattern
Bayer pattern of the sensor used to acquire the image to be converted.
Definition bayer_conversion.hpp:58
@ GreenRed
Left top pixels are green and red.
Definition bayer_conversion.hpp:66
@ GreenBlue
Left top pixels are green and blue.
Definition bayer_conversion.hpp:60
@ RedGreen
Left top pixels are red and green.
Definition bayer_conversion.hpp:64
@ BlueGreen
Left top pixels are blue and green.
Definition bayer_conversion.hpp:62
GammaCorrection
Different gamma corrections that can be applied while converting from Bayer pattern to RGB.
Definition bayer_conversion.hpp:71
@ Gamma045
Correct with Gamma = 0.45.
Definition bayer_conversion.hpp:75
@ Gamma060
Correct with Gamma = 0.6.
Definition bayer_conversion.hpp:77
@ Gamma100
Correct with Gamma = 1.0 (i.e. no correction).
Definition bayer_conversion.hpp:73
WhiteBalanceFactors GetWhiteBalance(const Image &image, BayerPattern pattern, Area2D aoi)
Determine a suitable white balance from a monochrome image with Bayer pattern.
Definition bayer_conversion.hpp:222
std::unique_ptr< Image > BayerToMono(const Image &image, BayerPattern pattern, RGBConversion conversion, GammaCorrection gamma=GammaCorrection::Gamma100, WhiteBalanceFactors whiteBalance=WhiteBalanceFactors::Identity())
Convert a monochrome image with a Bayer pattern to a proper monochrome image.
Definition bayer_conversion.hpp:184
void BayerToRGB(const Image &imageSrc, Image &imageDst, BayerPattern pattern, RGBConversion conversion, GammaCorrection gamma=GammaCorrection::Gamma100, WhiteBalanceFactors whiteBalance=WhiteBalanceFactors::Identity())
Convert a Bayer-pattern image to an RGB image.
Definition bayer_conversion.hpp:134
RGBConversion
Available conversion modes from Bayer patterns to RGB images.
Definition bayer_conversion.hpp:31
@ Linear
Definition bayer_conversion.hpp:37
@ HalfResolution
Definition bayer_conversion.hpp:50
@ NearestNeighbor
Definition bayer_conversion.hpp:43
std::unique_ptr< Image > RGBToBayer(const Image &image, BayerPattern pattern)
Convert an RGB image to a monochrome image with Bayer pattern.
Definition bayer_conversion.hpp:206
std::unique_ptr< Image > CreateDestinationImage(int width, int height, RGBConversion mode)
Create a destination image for Bayer to RGB conversions.
Definition bayer_conversion.hpp:94
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