Ocean
Loading...
Searching...
No Matches
WhitePointDetector.h
Go to the documentation of this file.
1/*
2 * Copyright (c) Meta Platforms, Inc. and affiliates.
3 *
4 * This source code is licensed under the MIT license found in the
5 * LICENSE file in the root directory of this source tree.
6 */
7
8#ifndef META_OCEAN_CV_ADVANCED_WHITE_POINT_DETECTOR_H
9#define META_OCEAN_CV_ADVANCED_WHITE_POINT_DETECTOR_H
10
12#include "ocean/cv/Histogram.h"
13
14#include "ocean/base/Frame.h"
15#include "ocean/base/Worker.h"
16
17#include "ocean/math/Vector3.h"
18
19namespace Ocean
20{
21
22namespace CV
23{
24
25namespace Advanced
26{
27
28/**
29 * Provides functions for white point detection and correction
30 * @ingroup cvadvanced
31 */
32class OCEAN_CV_ADVANCED_EXPORT WhitePointDetector
33{
34 public:
35
36 /**
37 * Attempts to detect the white point in the specified image frame.
38 * @param frame The frame in which the white point will be detected, must have a RGB24 pixel format, must be valid
39 * @param worker Optional worker instance to distribute the computational load
40 * @return The resulting white point
41 */
42 static VectorF3 detectWhitePointHistogram(const Frame& frame, Worker* worker = nullptr);
43
44 /**
45 * Attempts to detect the white point in the specified frame using the iterative gray points algorithm.
46 * @param frame The frame in which the white point will be detected, must have a RGB24 pixel format, must be valid
47 * @param grayThreshold Tolerance for gray point detection, higher tolerance is results in a larger set of gray points, with range [0, 255]
48 * @return The resulting white point
49 */
50 static VectorF3 detectWhitePointGrayPoints(const Frame& frame, const float grayThreshold = 0.4f);
51
52 /**
53 * Applies white point balancing on the image frame.
54 * @param frame The frame to be corrected, must have a RGB24 pixel format, must be valid
55 * @param whitePoint White point of the image.
56 * @param worker Optional worker instance to distribute the computational load
57 */
58 static void correctWhitePoint(Frame& frame, const VectorF3& whitePoint, Worker* worker = nullptr);
59
60 protected:
61
62 /**
63 * Iterates through the specified color channel histogram from highest to lowest bin to find the first bin that has more votes than the specified threshold.
64 * @param histogram The histogram that is searched
65 * @param channel Specifies the color channel for which its histogram is examined, with range [0, 2]
66 * @param threshold Number of votes threshold
67 * @return Color value that satisfies the number of votes threshold
68 */
69 static unsigned char colorRange(const CV::Histogram::Histogram8BitPerChannel<3u>& histogram, const unsigned char channel, const unsigned int threshold);
70
71 /**
72 * Converts from RGB to YUV color space
73 * @param r Red channel value
74 * @param g Green channel value
75 * @param b Blue channel value
76 * @param y Resulting luminance value
77 * @param u Resulting U channel value
78 * @param v Resulting V channel value
79 */
80 static inline void rgb2yuv(const float r, const float g, const float b, float& y, float& u, float& v);
81
82 /**
83 * Converts from YUV to RGB color space
84 * @param y Luminance value
85 * @param u U channel value
86 * @param v V channel value
87 * @param r Resulting red channel value
88 * @param g Resulting green channel value
89 * @param b Resulting blue channel value
90 */
91 static inline void yuv2rgb(const float y, const float u, const float v, float& r, float& g, float& b);
92};
93
94inline void WhitePointDetector::rgb2yuv(const float r, const float g, const float b, float& y, float& u, float& v)
95{
96 // RGB to ITU-R BT.601 YPbPr
97 y = 0.299000f * r + 0.587000f * g + 0.114000f * b;
98 u = -0.168736f * r - 0.331264f * g + 0.500000f * b;
99 v = 0.500000f * r - 0.418688f * g - 0.081312f * b;
100}
101
102inline void WhitePointDetector::yuv2rgb(const float y, const float u, const float v, float& r, float& g, float& b)
103{
104 // ITU-R BT.601 YPbPr to RGB
105 r = y - 1.21889419e-06f * u + 1.40199959e+00f * v;
106 g = y - 3.44135678e-01f * u - 7.14136156e-01f * v;
107 b = y + 1.77200007e+00f * u + 4.06298063e-07f * v;
108}
109
110}
111
112}
113
114}
115
116#endif // META_OCEAN_CV_ADVANCED_WHITE_POINT_DETECTOR_H
Provides functions for white point detection and correction.
Definition WhitePointDetector.h:33
static unsigned char colorRange(const CV::Histogram::Histogram8BitPerChannel< 3u > &histogram, const unsigned char channel, const unsigned int threshold)
Iterates through the specified color channel histogram from highest to lowest bin to find the first b...
static void correctWhitePoint(Frame &frame, const VectorF3 &whitePoint, Worker *worker=nullptr)
Applies white point balancing on the image frame.
static VectorF3 detectWhitePointHistogram(const Frame &frame, Worker *worker=nullptr)
Attempts to detect the white point in the specified image frame.
static VectorF3 detectWhitePointGrayPoints(const Frame &frame, const float grayThreshold=0.4f)
Attempts to detect the white point in the specified frame using the iterative gray points algorithm.
static void yuv2rgb(const float y, const float u, const float v, float &r, float &g, float &b)
Converts from YUV to RGB color space.
Definition WhitePointDetector.h:102
static void rgb2yuv(const float r, const float g, const float b, float &y, float &u, float &v)
Converts from RGB to YUV color space.
Definition WhitePointDetector.h:94
This class implements a standard histogram object storing 8 bit per channel.
Definition Histogram.h:208
This class implements Ocean's image class.
Definition Frame.h:1808
This class implements a vector with three elements.
Definition Vector3.h:97
This class implements a worker able to distribute function calls over different threads.
Definition Worker.h:33
The namespace covering the entire Ocean framework.
Definition Accessor.h:15