Rate This Document
Findability
Accuracy
Completeness
Readability

gaussian_blur_fft

Usage

Converts an image to the frequency domain for Gaussian filtering.

  1. A frequency-domain image is calculated through FFT.
  2. The kernel in the frequency domain is calculated based on sigma and size.
  3. A filtered frequency-domain image is obtained by performing dot product on the two matrices.
  4. A filtered space-domain image is obtained through IFFT.

Interface

1
void kcv_GaussianBlurFFT_acc(double *_src, double *_dst, size_t rows, size_t cols, double *kernel_ft, double sigma);

Parameters

Parameter

Description

Value Range

Input/Output

src

Input image.

Not null. The size of the allocated memory is rows*cols*sizeof(double).

Input

dst

Output image after filtering.

Not null. The size of the allocated memory is the same as that of src.

Output

rows

Height (rows) of the input image.

(0, 16384]

Input

cols

Width (columns) of the input image.

(0, 16384]

Input

kernel_ft

Output, frequency-domain Gaussian kernel.

Not null. The size of the allocated memory is rows*(cols/2+1)*sizeof(double).

Output

sigma

Gaussian sigma.

(0, inf)

Input

Return Values

  • Success: LITHO_IMG_STS_NO_ERR
  • Failure: an error code

Error Codes

Error Code

Description

LITHO_IMG_STS_NULL_PTR_ERR

The src or dst parameter has a null pointer.

LITHO_IMG_STS_SIZE_ERR

The value of rows or cols is 0.

Example

 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
#include <stdio.h>
#include <stdlib.h>
#include <complex.h>
#include <iostream>
#include <vector>
#include "kp_litho_img.h"

void test_kcv_laplacian_acc() {
    const size_t src_rows = 2; // Adjustable
const size_t src_cols = 2; // Adjustable
const double sigma = 3.0; // Adjustable

    double *_src = (double *)malloc(src_rows * src_cols * sizeof(double));
    double *_dst = (double *)malloc(src_rows * src_cols * sizeof(double));
    double *kernel_ft = (double *)malloc(src_rows * src_cols * sizeof(double));
    // Initialize the input image (a simple 5x5 image is used as an example).
    double src_data[5][5] = {
        {0, 0, 0, 0, 0},
        {0, 1, 2, 1, 0},
        {0, 1, 0, 1, 0},
        {0, 1, 1, 1, 0},
        {0, 0, 0, 0, 0}
    };
    for (size_t i = 0; i < src_rows; i++) {
        for (size_t j = 0; j < src_cols; j++) {
            _src[i * src_cols + j] = src_data[i][j];
        }
    }
    // Call the function.
    cv::kcv_GaussianBlurFFT_acc(_src, _dst, src_rows, src_cols, kernel_ft, sigma);
    // Print the result (only part of the result is printed here).
    printf("Upsampled Image:\n");
    for (size_t i = 0; i < src_rows; i++) { 
        for (size_t j = 0; j < src_cols; j++) { 
            printf("%.2f ", _dst[i * src_cols + j]);
            if (j == src_cols - 1) {
                printf("\n");
            }
        }
    }
}
int main() {
    test_kcv_laplacian_acc();
    return 0;
}

Output:

1
2
3
Upsampled Image:
0.25 0.25 
0.25 0.25