@@ -10,159 +10,136 @@ namespace rta
1010namespace core
1111{
1212
13- std::vector<double > cctToxy ( const double &cctd );
14-
15- void calDayLightSPD ( const int &cct, Spectrum &spectrum );
16- void calBlackBodySPD ( const int &cct, Spectrum &spectrum );
17-
18- class Idt
13+ // / Calculate spectral power distribution of a daylight illuminant of given CCT
14+ // / - parameter cct: correlated colour temperature of the requested illuminant.
15+ // / - parameter spectrum: a reference to a `Spectrum` object to full with the
16+ // / calculated values.
17+ void calculate_daylight_SPD ( const int &cct, Spectrum &spectrum );
18+
19+ // / Calculate spectral power distribution of a blackbody illuminant of given CCT
20+ // / - parameter cct: correlated colour temperature of the requested illuminant.
21+ // / - parameter spectrum: a reference to a `Spectrum` object to full with the
22+ // / calculated values.
23+ void calculate_blackbody_SPD ( const int &cct, Spectrum &spectrum );
24+
25+ // / Solve an input transform using spectral sensitivity curves of a camera.
26+ class SpectralSolver
1927{
2028public:
21- Idt ();
22-
23- int loadCameraSpst (
29+ SpectralSolver ();
30+
31+ // / Load spectral sensitivity data for a camera.
32+ // / - parameter path: a path to the data file
33+ // / - parameter make: the camera make to verify the loaded data against.
34+ // / - parameter model: the camera model to verify the loaded data against.
35+ // / - returns `true` if loaded successfully.
36+ bool load_camera (
2437 const std::string &path,
2538 const std::string &make,
2639 const std::string &model );
27- int loadIlluminant (
28- const std::vector<std::string> &paths, std::string type = " na" );
29-
30- void loadTrainingData ( const std::string &path );
31- void loadCMF ( const std::string &path );
32- void chooseIllumSrc ( const std::vector<double > &src, int highlight );
33- void chooseIllumType ( const std::string &type, int highlight );
34- void setIlluminants ( const SpectralData &illuminant );
35- void setVerbosity ( const int verbosity );
36- void scaleLSC ( SpectralData &illuminant );
37-
38- std::vector<double > calCM ();
39- std::vector<double > calWB ( SpectralData &illuminant, int highlight );
40- std::vector<Spectrum> calTI () const ;
41- std::vector<std::vector<double >>
42- calXYZ ( const std::vector<Spectrum> &TI ) const ;
43- std::vector<std::vector<double >>
44- calRGB ( const std::vector<Spectrum> &TI ) const ;
45-
46- int curveFit (
47- const std::vector<std::vector<double >> &RGB,
48- const std::vector<std::vector<double >> &XYZ,
49- double *B );
50- int calIDT ();
51-
52- const SpectralData &getCameraSpst () const ;
53- const SpectralData &getBestIllum () const ;
54- const SpectralData &getTrainingSpec () const ;
55- const std::vector<SpectralData> &getIlluminants () const ;
56- const SpectralData &getCMF () const ;
57- const std::vector<std::vector<double >> getIDT () const ;
58- const std::vector<double > getWB () const ;
59- const int getVerbosity () const ;
40+
41+ // / Load spectral power distribution data for an illuminant.
42+ // / If an illuminant type specified, try to find the matching data,
43+ // / otherwise load all known illuminants.
44+ // / - parameter paths: a set of data file paths to the data file
45+ // / - parameter type: illuminant type to load.
46+ // / - returns `true` if loaded successfully.
47+ bool load_illuminant (
48+ const std::vector<std::string> &paths, const std::string &type = " " );
49+
50+ // / Load spectral reflectivity data for a training set (a colour chart).
51+ // / - parameter path: a path to the data file
52+ // / - returns `true` if loaded successfully.
53+ bool load_training_data ( const std::string &path );
54+
55+ // / Load spectral sensitivity data for an observer
56+ // / (colour matching functions).
57+ // / - parameter path: a path to the data file
58+ // / - returns `true` if loaded successfully.
59+ bool load_observer ( const std::string &path );
60+
61+ // / Find the illuminant best matching the given white-balancing multipliers.
62+ // / See `get_best_illuminant()` to access the result.
63+ // / - parameter wb_multipliers: white-balancing multipliers to match.
64+ // / - parameter highlight: the highlight recovery mode, used for
65+ // / normalisation.
66+ void find_best_illuminant (
67+ const std::vector<double > &wb_multipliers, int highlight );
68+
69+ // / Select an illuminant of a given type.
70+ // / See `get_best_illuminant()` to access the result.
71+ // / - parameter type: illuminant type to select.
72+ // / - parameter highlight: the highlight recovery mode, used for
73+ // / normalisation.
74+ void select_illuminant ( const std::string &type, int highlight );
75+
76+ // / Calculate an input transform matrix.
77+ // / See `get_IDT_matrix()` to access the result.
78+ // / - returns `true` if calculated successfully.
79+ bool calculate_IDT_matrix ();
80+
81+ // / Get the illuminant configured using `find_best_illuminant()` or
82+ // / `select_illuminant()`.
83+ // / - returns a reference to the illuminant.
84+ const SpectralData &get_best_illuminant () const ;
85+
86+ // / Get the matrix calculated using `calculate_IDT_matrix()`.
87+ // / - returns a reference to the matrix.
88+ const std::vector<std::vector<double >> &get_IDT_matrix () const ;
89+
90+ // / Get the white-balance multipliers calculated using
91+ // / `find_best_illuminant()` or `select_illuminant()`.
92+ // / - returns a reference to the multipliers.
93+ const std::vector<double > &get_WB_multipliers () const ;
94+
95+ int verbosity = 0 ;
6096
6197private:
6298 SpectralData _camera;
6399 SpectralData _best_illuminant;
64100 SpectralData _observer;
65101 SpectralData _training_data;
66- std::vector<SpectralData> _Illuminants;
67-
68- int _verbosity;
102+ std::vector<SpectralData> _illuminants;
69103
70- std::vector<double > _wb ;
71- std::vector<std::vector<double >> _idt ;
104+ std::vector<double > _WB_multipliers ;
105+ std::vector<std::vector<double >> _IDT_matrix ;
72106};
73107
108+ // / DNG metadata required to calculate an input transform.
74109struct Metadata
75110{
111+ // / A calibration data set. Currently two sets are supported.
76112 struct Calibration
77113 {
78114 unsigned short illuminant = 0 ;
79- std::vector<double > cameraCalibrationMatrix;
80- std::vector<double > xyz2rgbMatrix;
81-
82- friend bool operator ==( const Calibration &c1, const Calibration &c2 )
83- {
84- if ( c1.illuminant != c2.illuminant )
85- return false ;
86- if ( c1.cameraCalibrationMatrix != c2.cameraCalibrationMatrix )
87- return false ;
88- if ( c1.xyz2rgbMatrix != c2.xyz2rgbMatrix )
89- return false ;
90-
91- return true ;
92- }
93-
94- friend bool operator !=( const Calibration &c1, const Calibration &c2 )
95- {
96- return !( c1 == c2 );
97- }
115+ std::vector<double > camera_calibration_matrix;
116+ std::vector<double > XYZ_to_RGB_matrix;
98117 } calibration[2 ];
99118
100- std::vector<double > neutralRGB;
101- double baselineExposure = 0.0 ;
102-
103- friend bool operator ==( const Metadata &m1, const Metadata &m2 )
104- {
105- if ( m1.calibration [0 ] != m2.calibration [0 ] )
106- return false ;
107- if ( m1.calibration [1 ] != m2.calibration [1 ] )
108- return false ;
109- if ( m1.baselineExposure != m2.baselineExposure )
110- return false ;
111- if ( m1.neutralRGB != m2.neutralRGB )
112- return false ;
113-
114- return true ;
115- }
116-
117- friend bool operator !=( const Metadata &m1, const Metadata &m2 )
118- {
119- return !( m1 == m2 );
120- }
119+ std::vector<double > neutral_RGB;
120+ double baseline_exposure = 0.0 ;
121121};
122122
123- class DNGIdt
123+ // / Solve an input transform using the metadata stored in DNG files.
124+ class MetadataSolver
124125{
125- core::Metadata _metadata;
126-
127126public:
128- DNGIdt ( const core::Metadata &metadata );
129-
130- double ccttoMired ( const double cct ) const ;
131- double robertsonLength (
132- const std::vector<double > &uv, const std::vector<double > &uvt ) const ;
133- double lightSourceToColorTemp ( const unsigned short tag ) const ;
134- double XYZToColorTemperature ( const std::vector<double > &XYZ ) const ;
135-
136- std::vector<double > XYZtoCameraWeightedMatrix (
137- const double &mir, const double &mir1, const double &mir2 ) const ;
127+ // / Initialise the solver using DNG metadata.
128+ // / - parameter metadata: DNG metadata
129+ MetadataSolver ( const core::Metadata &metadata );
138130
139- std::vector<double >
140- findXYZtoCameraMtx ( const std::vector<double > &neutralRGB ) const ;
141- std::vector<double > colorTemperatureToXYZ ( const double &cct ) const ;
142- std::vector<double >
143- matrixRGBtoXYZ ( const double chromaticities[][2 ] ) const ;
131+ // / Calculate an input transform matrix.
132+ // / - returns: calculated matrix
133+ std::vector<std::vector<double >> calculate_IDT_matrix ();
144134
145- std::vector<std::vector<double >> getDNGCATMatrix ();
146- std::vector<std::vector<double >> getDNGIDTMatrix ();
147- void getCameraXYZMtxAndWhitePoint ();
135+ // / Calculate a chromatic adaptation transform matrix. Strictly speaking,
136+ // / this matrix is not required for image processing, as it is embedded in
137+ // / the IDT, see `calculate_IDT_matrix`.
138+ // / - returns: calculated matrix
139+ std::vector<std::vector<double >> calculate_CAT_matrix ();
148140
149141private:
150- std::vector<double > _cameraToXYZMtx;
151- std::vector<double > _cameraXYZWhitePoint;
152- };
153-
154- struct Objfun
155- {
156- Objfun (
157- const std::vector<std::vector<double >> &RGB,
158- const std::vector<std::vector<double >> &outLAB )
159- : _RGB( RGB ), _outLAB( outLAB )
160- {}
161-
162- template <typename T> bool operator ()( const T *B, T *residuals ) const ;
163-
164- const std::vector<std::vector<double >> _RGB;
165- const std::vector<std::vector<double >> _outLAB;
142+ core::Metadata _metadata;
166143};
167144
168145} // namespace core
0 commit comments