Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void GaussImage(const Image8 &src_image, Image8 &dst_image)
- {
- double sigma = 1.25;
- int radius = 2;
- double** kernel = NULL;
- double kernelSum = 0;
- kernel = new double*[2 * radius + 1];
- for(int i = 0; i < 2 * radius + 1; ++i)
- {
- kernel[i] = new double[2 * radius + 1];
- }
- for(int x = -radius; x <= radius; x += 1)
- {
- for(int y = -radius; y <= radius; y += 1)
- {
- kernel[x + radius][y + radius] =
- exp(-((x * x + y * y) / 2 / sigma / sigma))
- / 2 / M_PI / sigma / sigma;
- kernelSum += kernel[x + radius][y + radius];
- }
- }
- for(int x = -radius; x <= radius; x += 1)
- {
- for(int y = -radius; y <= radius; y += 1)
- {
- kernel[x + radius][y + radius] /= kernelSum;
- }
- }
- dst_image.height = src_image.height;
- dst_image.width = src_image.width;
- dst_image.widthstep = src_image.widthstep;
- dst_image.data = new uint8_t[src_image.height * src_image.width];
- double sum = 0;
- for(int line = radius; line < src_image.height - radius; ++line)
- {
- for(int column = radius; column < src_image.width - radius;
- ++column)
- {
- sum = 0;
- for(int i = -radius; i <= radius; i += 1)
- {
- for(int j = -radius; j <= radius; j += 1)
- {
- sum += kernel[i + radius][j + radius] * src_image.data[
- (line + i) * src_image.width + (column + j)];
- }
- }
- dst_image.data[(line) * dst_image.width + column] = sum;
- }
- }
- }
Add Comment
Please, Sign In to add comment