1 /***************************************************************************
2 * This file is part of Tecorrec. *
3 * Copyright 2008 James Hogan <james@albanarts.com> *
5 * Tecorrec is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation, either version 2 of the License, or *
8 * (at your option) any later version. *
10 * Tecorrec is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with Tecorrec. If not, write to the Free Software Foundation, *
17 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
18 ***************************************************************************/
21 * @file tcIlluminantDiscontinuity.cpp
22 * @brief Illuminant discontinuity in both dimentions.
25 #include "tcIlluminantDiscontinuity.h"
26 #include "tcChannel.h"
33 * Constructors + destructor
36 /// Primary constructor.
37 tcIlluminantDiscontinuity::tcIlluminantDiscontinuity(const QList
<tcChannel
*>& chromaticities
)
38 : tcIlluminantDirection(chromaticities
, 2, QObject::tr("Illuminant discontinuity measure"), QObject::tr(""))
40 channels()[0]->setName(QObject::tr("idm.x"));
41 channels()[1]->setName(QObject::tr("idm.y"));
42 channels()[0]->setDescription(QObject::tr("Illuminant discontinuity measure in the x direction"));
43 channels()[1]->setDescription(QObject::tr("Illuminant discontinuity measure in the y direction"));
47 tcIlluminantDiscontinuity::~tcIlluminantDiscontinuity()
52 * Interface for derived class to implement
55 void tcIlluminantDiscontinuity::loadPortions(const QList
< Reference
< tcPixelData
<float> > >& chromaticities
, int width
, int height
)
57 Reference
< tcPixelData
<float> > discontinuityData
[2];
58 for (int i
= 0; i
< 2; ++i
)
60 discontinuityData
[i
] = new tcPixelData
<GLfloat
>(width
, height
);
61 m_portions
+= discontinuityData
[i
];
64 // Go through the pixels
65 maths::VarVector
<float> lastLogChromaticity(numChromaticities());
66 maths::VarVector
<float> logChromaticity(numChromaticities());
67 maths::VarVector
<float> temp(numChromaticities());
68 float lastDisc
= 0.0f
;
69 for (int i
= 0; i
< width
; ++i
)
71 for (int j
= 0; j
< height
; ++j
)
73 int index
= j
*width
+ i
;
74 // Fill log chromaticity vector
75 for (int channel
= 0; channel
< numChromaticities(); ++channel
)
77 logChromaticity
[channel
] = logf(chromaticities
[channel
]->buffer()[index
]);
80 temp
= logChromaticity
;
81 temp
-= lastLogChromaticity
;
83 float discontinuity
= lastDisc
;
84 float sqr
= temp
.sqr();
87 float mag
= sqrtf(sqr
);
90 discontinuity
= /*fabs*/(temp
* illuminantDirection()) /*/ mag*/;
93 lastDisc
= discontinuity
*0.5f
;
95 lastLogChromaticity
= logChromaticity
;
97 discontinuityData
[0]->buffer()[index
] = 0.5f
+ discontinuity
;
101 for (int j
= 0; j
< height
; ++j
)
103 for (int i
= 0; i
< width
; ++i
)
105 int index
= j
*width
+ i
;
106 // Fill log chromaticity vector
107 for (int channel
= 0; channel
< numChromaticities(); ++channel
)
109 logChromaticity
[channel
] = logf(chromaticities
[channel
]->buffer()[index
]);
112 temp
= logChromaticity
;
113 temp
-= lastLogChromaticity
;
115 float discontinuity
= lastDisc
;
116 float sqr
= temp
.sqr();
119 float mag
= sqrtf(sqr
);
122 discontinuity
= /*fabs*/(temp
* illuminantDirection()) /*/ mag*/;
125 lastDisc
= discontinuity
*0.5f
;
127 lastLogChromaticity
= logChromaticity
;
129 discontinuityData
[1]->buffer()[index
] = 0.5f
+ discontinuity
;