48 #ifndef _MIRA_COLOR_H_ 49 #define _MIRA_COLOR_H_ 52 #include <opencv2/core/core.hpp> 90 virtual operator cv::Scalar()
const;
112 RGB(
float ir,
float ig,
float ib) :
113 r(ir), g(ig), b(ib) {
128 template<
typename Reflector>
130 reflector.property(
"R", r,
"The red component",
132 reflector.property(
"G", g,
"The green component",
134 reflector.property(
"B", b,
"The blue component",
147 return r >= 0.0f && r <= 1.0f && g >= 0.0f && g <= 1.0f && b >= 0.0f
167 RGBA(
float ir,
float ig,
float ib,
float ia) :
168 RGB(ir, ig, ib), a(ia) {
178 RGB(other.r, other.g, other.b), a(other.a) {
185 RGB(other.r, other.g, other.b), a(ia) {
188 template<
typename Reflector>
191 r.property(
"A", a,
"The alpha component",
195 virtual operator cv::Scalar()
const {
196 return cv::Scalar(b * 255.0f, g * 255.0f, r * 255.0f, a * 255.0f);
217 HSV(
float hue,
float saturation,
float value) :
218 h(hue), s(saturation), v(value) {
225 h(0.0f), s(0.0f), v(0.0f) {
228 template<
typename Reflector>
231 r.property(
"S", s,
"The saturation component",
233 r.property(
"V", v,
"The value component",
243 float f = fmod(h * 6.0f, 6.0f);
247 float p = v * (1 - s);
248 float q = v * (1 - s * f);
249 float t = v * (1 - s * (1 - f));
296 XYZ(
float ix,
float iy,
float iz) :
297 x(ix), y(iy), z(iz) {
304 x(0.0f), y(0.0f), z(0.0f) {
307 template<
typename Reflector>
309 r.property(
"X", x,
"The x component",
311 r.property(
"Y", y,
"The y component",
313 r.property(
"Z", z,
"The z component",
330 float X = x / 100.0f;
331 float Y = y / 100.0f;
332 float Z = z / 100.0f;
334 float R = X * 3.2406f + Y * -1.5372f + Z * -0.4986f;
335 float G = X * -0.9689f + Y * 1.8758f + Z * 0.0415f;
336 float B = X * 0.0557f + Y * -0.2040f + Z * 1.0570f;
339 R = 1.055f *
pow(R, 1.0f / 2.4f) - 0.055f;
344 G = 1.055f *
pow(G, 1.0f / 2.4f) - 0.055f;
349 B = 1.055f *
pow(B, 1.0f / 2.4f) - 0.055f;
390 Lab(
float iL,
float ia,
float ib) :
391 L(iL), a(ia), b(ib) {
398 L(0.0f), a(0.0f), b(0.0f) {
401 template<
typename Reflector>
403 r.property(
"L", L,
"The L component",
405 r.property(
"A", a,
"The a component",
407 r.property(
"B", b,
"The b component",
420 float Y = (L + 16.0f) / 116.0f;
421 float X = a / 500.0f + Y;
422 float Z = Y - b / 200.0f;
424 float Y3 = Y * Y * Y;
425 float X3 = X * X * X;
426 float Z3 = Z * Z * Z;
431 Y = (Y - 16.0f / 116.0f) / 7.787f;
435 X = (X - 16.0f / 116.0f) / 7.787f;
439 Z = (Z - 16.0f / 116.0f) / 7.787f;
444 float refX = 95.047f;
445 float refY = 100.000f;
446 float refZ = 108.883f;
465 return toXYZ().
toRGB();
546 const RGB Red(1.0f, 0.0f, 0.0f);
548 const RGB Blue(0.0f, 0.0f, 1.0f);
549 const RGB Cyan(0.0f, 1.0f, 1.0f);
564 inline ColorBase::operator cv::Scalar()
const {
566 return cv::Scalar(c.
b * 255.0f, c.
g * 255.0f, c.
r * 255.0f, 255.0f);
XYZ()
Default constructor Initializes X,Y, and Z with 0.0.
Definition: Color.h:303
virtual Color::RGB toRGB() const
Converts CIE Lab to RGB.
Definition: Color.h:464
const RGB Red(1.0f, 0.0f, 0.0f)
Color in YUV color space.
base interface for all colors in different color spaces The class provides a base interface for all c...
Definition: Color.h:75
specialize cv::DataType for our ImgPixel and inherit from cv::DataType<Vec>
Definition: IOService.h:67
XYZ(float ix, float iy, float iz)
Constructs color in CIE 1931 XYZ color space X: from 0 to 95.047 Y: from 0 to 100.000 Z: from 0 to 108.883.
Definition: Color.h:296
RGBA()
Default constructor that creates a black color.
Definition: Color.h:172
Color in CIE Lab color space The CIE Lab color space is derived from the XYZ color space and is desig...
Definition: Color.h:381
RGB(const RGB &other)
copy constructor
Definition: Color.h:122
RGBA(const RGBA &other)
copy constructor
Definition: Color.h:177
#define MIRA_REFLECT_BASE(reflector, BaseClass)
Macro that can be used to reflect the base class easily.
Definition: ReflectorInterface.h:912
Provides property hints and attributes.
Lab(float iL, float ia, float ib)
Constructs color in CIE Lab color space.
Definition: Color.h:390
void reflect(Reflector &r)
Definition: Color.h:229
float r
Definition: Color.h:152
RGB(float ir, float ig, float ib)
Constructs RGB color R,G and B: range from 0.0 to 1.0.
Definition: Color.h:112
const RGB White(1.0f, 1.0f, 1.0f)
Lab()
Default constructor Initializes L,a, and b with 0.0.
Definition: Color.h:397
void reflect(Reflector &reflector)
Definition: Color.h:129
void reflect(Reflector &r)
Definition: Color.h:308
#define MIRA_ABSTRACT_OBJECT(classIdentifier)
Use this MACRO instead of MIRA_OBJECT to declare the class as abstract.
Definition: FactoryMacros.h:235
Color in RGBA color space.
Definition: Color.h:159
virtual Color::RGB toRGB() const
no conversion is done here, because it is already RGB
Definition: Color.h:139
HSV(float hue, float saturation, float value)
Constructs color in HSV color space.
Definition: Color.h:217
Contains the base interface of all Reflectors, Serializers, etc.
$Header file containing base classes to enable class creation using a class factory$ ...
float g
Definition: Color.h:152
RGBA(const RGB &other, float ia=1.0f)
Constructs RGBA color from RGB color and alpha value (that is 1.0f per default).
Definition: Color.h:184
PropertyHint limits(const T &min, const T &max)
Sets both attributes "minimum" and "maximum" to the specified values.
Definition: PropertyHint.h:275
void reflect(Reflector &r)
Definition: Color.h:189
const RGB Black(0.0f, 0.0f, 0.0f)
The object class acts as a generic base class for classes which should be used with the classFactory...
Definition: Object.h:144
void reflect(Reflector &r)
Definition: Color.h:402
const RGB Yellow(1.0f, 1.0f, 0.0f)
const RGB Magenta(1.0f, 0.0f, 1.0f)
#define MIRA_OBJECT(classIdentifier)
Use this MACRO if you like the factory to automatically extract the class name from the given identif...
Definition: FactoryMacros.h:179
bool isInRange() const
Returns true, if all rgb components are within valid ranges, i.e.
Definition: Color.h:146
float a
Definition: Color.h:200
float z
Definition: Color.h:357
const RGB Green(0.0f, 1.0f, 0.0f)
const RGB Cyan(0.0f, 1.0f, 1.0f)
T pow(T base)
Computes the power of 'base' with a constant integral exponent.
Definition: Power.h:104
RGB()
Default constructor that creates a black color.
Definition: Color.h:117
class MIRA_BASE_EXPORT RGB
Definition: Color.h:65
float b
Definition: Color.h:152
XYZ toXYZ() const
Converts CIE Lab to CIE XYZ.
Definition: Color.h:416
Color in CIE 1931 XYZ color space The CIE XYZ color space is the master for the derived CIE Lab color...
Definition: Color.h:286
The different color spaces.
Definition: Color.h:104
float v
Definition: Color.h:270
RGBA(float ir, float ig, float ib, float ia)
Constructs RGBA color R,G,B and A: range from 0.0 to 1.0.
Definition: Color.h:167
HSV()
Default constructor initializes H,S, and V to 0.0.
Definition: Color.h:224
float L
Definition: Color.h:469
virtual Color::RGB toRGB() const
Converts the HSV color to RGB.
Definition: Color.h:242
virtual Color::RGB toRGB() const
Converts the CIE XYZ color to RGB.
Definition: Color.h:326
Color in HSV color space.
Definition: Color.h:209
virtual ~ColorBase()
Definition: Color.h:78
const RGB Blue(0.0f, 0.0f, 1.0f)