我要评分
获取效率
正确性
完整性
易理解

fft_upsampling

Usage

Performs phase adjustment and interpolation on an image to implement upsampling, that is, scale up the image.

  1. The source image matrix is converted into an information matrix in frequency domain through fast Fourier transform (FFT).
  2. The phase of the frequency domain matrix is adjusted based on shift.
  3. The frequency domain matrix is periodically padded (with zeros for high frequencies) to the size of the target matrix.
  4. The frequency-domain matrix is converted back to a space-domain matrix through inverse fast Fourier transform (IFFT) to complete image interpolation.

Interface

1
void kcv_FFTUpsampling_acc(const double *_src, double *_dst, size_t src_rows, size_t src_cols, size_t dst_rows, size_t dst_cols, double shift_x, double shift_y);

Parameters

Parameter

Description

Value Range

Input/Output

src

Input image.

Not null. The size of the allocated memory is src_rows*src_cols*sizeof(double).

Input

dst

Output image after interpolation.

Not null. The size of the allocated memory is dst_rows*dst_cols*sizeof(double).

Output

src_rows

Number of rows of the input image.

(0, 16384]

Input

src_cols

Number of columns of the input image.

(0, 16384]

Input

dst_rows

Number of rows of the output image.

[src_rows, 16384]

Output

dst_cols

Number of columns of the output image.

[src_cols, 16384]

Output

shift_x

Offset of the output image origin against the input image origin in the X direction.

(-inf, inf)

Output

shift_y

Offset of the output image origin against the input image origin in the Y direction.

(-inf, inf)

Output

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 src_rows or src_cols is 0.
  • The value of dst_rows is smaller than that of src_rows, or the value of dst_cols is smaller than that of src_cols.

LITHO_IMG_STS_FFT_ERR

Failed to create the FFT plan.

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

int main() {
    // Define the input image size and target size.
    size_t src_rows = 5;
    size_t src_cols = 5;
    size_t dst_rows = 10;
    size_t dst_cols = 10;
    // Define the pointers to the input and output images.
    double *src = (double *)malloc(src_rows * src_cols * sizeof(double));
    double *dst = (double *)malloc(dst_rows * dst_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, 1, 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];
        }
    }
    // Define phase adjustment parameters.
    double shift_x = 0.5;
    double shift_y = 0.5;
    // Call kcv_FFTUpsampling_acc to perform upsampling.
    cv::kcv_FFTUpsampling_acc(src, dst, src_rows, src_cols, dst_rows, dst_cols, shift_x, shift_y);
    // Print the result (only part of the result is printed here).
    printf("Upsampled Image:\n");
    for (size_t i = 0; i < dst_rows; i++) {
        for (size_t j = 0; j < dst_cols; j++) {
            printf("%.2f ", dst[i * dst_cols + j]);
            if (j == dst_cols - 1) {
                printf("\n");
            }
        }
    }
    // Release memory.
    free(src);
    free(dst);
    return 0;
}

Output:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
Upsampled Image:
0.02 0.05 0.09 0.11 0.11 0.09 0.05 0.02 -0.01 -0.01 
0.05 0.17 0.24 0.26 0.26 0.24 0.17 0.05 -0.04 -0.04 
0.09 0.24 0.25 0.20 0.20 0.25 0.24 0.09 -0.07 -0.07 
0.11 0.26 0.20 0.05 0.05 0.20 0.26 0.11 -0.09 -0.09 
0.11 0.26 0.20 0.05 0.05 0.20 0.26 0.11 -0.09 -0.09 
0.09 0.24 0.25 0.20 0.20 0.25 0.24 0.09 -0.07 -0.07 
0.05 0.17 0.24 0.26 0.26 0.24 0.17 0.05 -0.04 -0.04 
0.02 0.05 0.09 0.11 0.11 0.09 0.05 0.02 -0.01 -0.01 
-0.01 -0.04 -0.07 -0.09 -0.09 -0.07 -0.04 -0.01 0.01 0.01 
-0.01 -0.04 -0.07 -0.09 -0.09 -0.07 -0.04 -0.01 0.01 0.01