Gaussian Filter
1/SIGMA*SQRT(2*PI) *
EXP^(-(x-MEAN)^2/2 * SIGMA ^2Implementation
void cv_apply_gaussian_blur(Image *image, float sigma, int size) {
/* ... */
cv_compute_gaussian_kernel(&kernel, sigma, SIZE);
for (int i = 0; i < image->height; i++) {
for (int j = 0; j < image->width; j++) {
for (int c = 0; c < image->channels; c++) {
for (int k = 0; k < SIZE; k++) {
for (int l = 0; l < SIZE; l++) {
/* ... */
float weight = kernel[k][l];
int pixelIndex = (yIndex * image->width + xIndex) * image->channels + c;
unsigned char pixelValue = imageBytes[pixelIndex];
sum += pixelValue * weight;
sumWeight += weight;
}
}
int pixelIndex = (i * image->width + j) * image->channels + c;
newImageBytes[pixelIndex] = (unsigned char)(sum / sumWeight);
}
}
}
/* ... */
}
Result


Last updated