Why are the values ββof the Gaussian nuclei not the same, generated by the equation and indicated in the book?
I created a Gaussian kernel using the following code.
double gaussian(double x, double mu, double sigma) {
return std::exp(-(((x - mu) / (sigma))*((x - mu) / (sigma))) / 2.0);
}
typedef std::vector<double> kernel_row;
typedef std::vector<kernel_row> kernel_type;
kernel_type produce2dGaussianKernel(int kernelRadius) {
double sigma = kernelRadius / 2.;
kernel_type kernel2d(2 * kernelRadius + 1, kernel_row(2 * kernelRadius + 1));
double sum = 0;
for (int row = 0; row < kernel2d.size(); row++)
for (int col = 0; col < kernel2d[row].size(); col++) {
double x = gaussian(row, kernelRadius, sigma)
* gaussian(col, kernelRadius, sigma);
kernel2d[row][col] = x;
sum += x;
}
for (int row = 0; row < kernel2d.size(); row++) {
for (int col = 0; col < kernel2d[row].size(); col++) {
kernel2d[row][col] /= sum;
}
}
return kernel2d;
}
His result
0.01134 0.08382 0.01134
0.08382 0.61935 0.08382
0.01134 0.08382 0.01134
Press any key to continue . . .
And this is the 3x3 Gaussian core given in the book
{1 / 16.0f, 2 / 16.0f, 1 / 16.0f,
2 / 16.0f, 4 / 16.0f, 2 / 16.0f,
1 / 16.0f, 2 / 16.0f, 1 / 16.0f };
I wander why both coefficients are the same. and at which the sigma value is generated, the gaussain kernel masks (given in the book)? Note. I used the Gauss equation to generate a Gaussian kernel
Edited: I added a Gaussian function to my code.
source
share