57 const double twoSigmaSquared = 2.0 / (
sigma *
sigma);
58 const double twoPiSigma = std::sqrt(2.0 * M_PI) / (
sigma+1e-10);
62 gaussianKernel(row, col) = twoPiSigma * std::exp(-twoSigmaSquared *
63 (std::pow((
double)(row - center), 2.0) +
64 std::pow((
double)(col - center), 2.0)));
71 Eigen::MatrixXd uniformH = Eigen::MatrixXd::Random(rows, cols);
72 Eigen::MatrixXd uniformV = Eigen::MatrixXd::Random(rows, cols);
79 for(
int r = 0; r < rows; r++)
81 for(
int c = 0; c < cols; c++)
83 double convolvedH = 0.0, convolvedV = 0.0;
88 int inputRow = r - kernelCenter + kr;
89 int inputCol = c - kernelCenter + kc;
90 if(inputRow >= 0 && inputRow < rows && inputCol >= 0 && inputCol < cols)
92 convolvedH += uniformH(inputRow, inputCol) *
gaussianKernel(kr, kc);
93 convolvedV += uniformV(inputRow, inputCol) *
gaussianKernel(kr, kc);
106 double horizontalScaling = rng.
generate<
double>(-1.0, 2.0) *
gammaX / 100.0;
107 double verticalScaling = rng.
generate<
double>(-1.0, 2.0) *
gammaY / 100.0;
109 int imageCenter = rows / 2;
110 for(
int r = 0; r < rows; r++)
112 for(
int c = 0; c < cols; c++)
114 distortionH(r, c) += horizontalScaling * (double)(c - imageCenter);
115 distortionV(r, c) -= verticalScaling * (double)(imageCenter - r);
122 double angle =
beta * rng.
generate<
double>(-1.0, 2.0) * M_PI / 180.0;
123 double cosAngle = cos(angle);
124 double sinAngle = sin(angle);
126 for(
int r = 0; r < rows; r++)
128 for(
int c = 0; c < cols; c++)
130 distortionH(r, c) += (c - imageCenter) * (cosAngle - 1.0) - (imageCenter - r) * sinAngle;
131 distortionV(r, c) -= (imageCenter - r) * (cosAngle - 1.0) - (c - imageCenter) * sinAngle;
141 Eigen::VectorXd instance;
142 for(
int n = 0; n < instances.cols(); n++)
144 instance = instances.col(n);
146 instances.col(n) = instance;
153 Eigen::VectorXd input = instance;
154 for(
int r = 0; r < rows; r++)
156 for(
int c = 0; c < cols; c++)
160 double rowFraction = sourceRow - ceil(sourceRow);
161 double colFraction = sourceCol - ceil(sourceCol);
162 double w1 = (1.0 - rowFraction) * (1.0 - colFraction);
163 double w2 = (1.0 - rowFraction) * colFraction;
164 double w3 = rowFraction * (1.0 - colFraction);
165 double w4 = rowFraction * colFraction;
167 if(!(sourceRow + 1 >= rows || sourceRow < 0 || sourceCol + 1 > cols || sourceCol < 0))
169 int sr = (int) sourceRow, sc = (
int) sourceCol;
170 int srn = sr + 1, scn = sc + 1;
171 while(srn >= rows) srn -= rows;
172 while(srn < 0) srn += rows;
173 while(scn >= cols) scn -= cols;
174 while(scn < 0) scn += cols;
175 instance(r * cols + c) = w1 * input(sr * cols + sc)
176 + w2 * input(sr * cols + scn)
177 + w3 * input(srn * cols + sc)
178 + w4 * input(srn * cols + scn);
185 #endif // DISTORTER_H_