synthetic.cpp
3.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright 2012 The MITRE Corporation *
* *
* Licensed under the Apache License, Version 2.0 (the "License"); *
* you may not use this file except in compliance with the License. *
* You may obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* Unless required by applicable law or agreed to in writing, software *
* distributed under the License is distributed on an "AS IS" BASIS, *
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
* See the License for the specific language governing permissions and *
* limitations under the License. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <opencv2/imgproc/imgproc.hpp>
#include <openbr_plugin.h>
#include "core/opencvutils.h"
using namespace cv;
namespace br
{
/*!
* \ingroup transforms
* \brief Prediction using only the red wavelength; magic numbers from jmp
* \author E. Taborsky \cite mmtaborsky
*/
class RedLinearRegressionTransform : public UntrainableTransform
{
Q_OBJECT
void project(const Template &src, Template &dst) const
{
Mat m; src[0].convertTo(m, CV_32F); assert(m.isContinuous() && (m.channels() == 1));
const float rmult = .6533673;
const float add = 41.268;
Mat dst1(m.size(), CV_32F);
int rows = m.rows;
int cols = m.cols;
const float *rsrc = (const float*) m.ptr();
float *p = (float*)dst1.ptr();
for (int r = 0; r < rows; r++){
for (int c = 0; c < cols; c++){
int index = r*cols+c;
const float rval = rsrc[index];
p[index] = rval*rmult+add;
}
}
dst = dst1;
}
};
BR_REGISTER(Transform, RedLinearRegressionTransform)
/*!
* \ingroup transforms
* \brief Prediction with magic numbers from jmp; must get input as blue;green;red
* \author E. Taborsky \cite mmtaborsky
*/
class OrigLinearRegressionTransform : public UntrainableMetaTransform
{
Q_OBJECT
void project(const Template &src, Template &dst) const
{
if (src.size() != 3) qFatal("OrigLinearRegression::project expected exactly three source images, got %d.", src.size());
Mat m1; src[0].convertTo(m1, CV_32F); assert(m1.isContinuous() && (m1.channels() == 1));
Mat m2; src[1].convertTo(m2, CV_32F); assert(m2.isContinuous() && (m2.channels() == 1));
Mat m3; src[2].convertTo(m3, CV_32F); assert(m3.isContinuous() && (m3.channels() == 1));
const float rmult = .809911, gmult = -.09625, bmult = -.020115, add = 35.78;
Mat dstmat(m1.size(), CV_32F);
int rows = m1.rows;
int cols = m1.cols;
const float *pb = (const float*) m1.ptr(), *pg = (const float*) m2.ptr(), *pr = (const float*) m3.ptr();
float *pd = (float*)dstmat.ptr();
for (int r = 0; r < rows; r++){
for (int c = 0; c < cols; c++){
int index = r*cols+c;
const float bval = pb[index], gval = pg[index], rval = pr[index];
pd[index] = bval*bmult+ gval*gmult+rval*rmult+add;
}
}
dst = dstmat;
}
};
BR_REGISTER(Transform, OrigLinearRegressionTransform)
} // namespace br
#include "synthetic.moc"