Chapter 6-image transformation-convolution and discrete Fourier transform DFT (cvdft)

Source: Internet
Author: User

The DFT can greatly accelerate the convolution operation, because the convolution theorem shows that the convolution operation in the spatial domain can be converted to the multiplication operation in the frequency domain.

-------------------------------------------------------------------------------

Getoptimaldftsize

Getoptimaldftsize
Returns the optimal DFT size for the given vector size.

Int cvgetoptimaldftsize (INT size0 );
Size0
Vector length.
Function cvgetoptimaldftsize returns the minimum value n that is greater to equal to size0, such that DFT of a vector of size N can be computed fast. in the current implementation n = 2 p × 3q × 5R for some P, Q, R.

The function returns a negative number if size0 is too large (very close to int_max)

 

Getsubrect

Getsubrect
Returns the matrix header of the input image or matrix's rectangular array subset.

Cvmat * cvgetsubrect (const cvarr * arr, cvmat * submat, cvrect rect );
Arr
Input array.
Submat
Pointer to the matrix header of the subset of the rectangle array.
Rect
The ROI is based on 0 coordinates.
The cvgetsubrect function returns the matrix header Based on the specified array rectangle. In other words, the function allows processing a specified stator rectangle of the input array just like processing an independent array. When processing functions, consider the input array Roi. Therefore, the array Roi is actually extracted.

 

DFT

DFT
Executes the Discrete Fourier positive transformation or the Discrete Fourier inverse transformation of one-dimensional or two-dimensional floating point groups.

# Define cv_dxt_forward 0
# Define cv_dxt_inverse 1
# Define cv_dxt_scale: 2
# Define cv_dxt_rows: 4
# Define cv_dxt_inv_scale (cv_dxt_scale | cv_dxt_inverse)
# Define cv_dxt_inverse_scale cv_dxt_inv_scale
Void cvdft (const cvarr * SRC, cvarr * DST, int flags );
SRC
Input array, real number or plural number.
DST
The output array has the same type and size as the input array.
Flags
Conversion sign, a combination of the following values:
Cv_dxt_forward-transforms forward to 1D or 2D. The result is not scaled.
Cv_dxt_inverse-reverse 1D or 2D transformation. The result is not scaled. Of course, cv_dxt_forward and cv_dxt_inverse are mutually exclusive.
Cv_dxt_scale-scale the result: divide it by array elements. Generally, it is combined with cv_dxt_inverse. You can use the cv_dxt_inv_scale abbreviation.

Cv_dxt_rows-each independent row of the input matrix performs integer or inverse transformation. This flag allows users to transform multiple vectors at the same time to reduce overhead (it is usually several times faster than processing itself) and perform 3D and high-dimensional transformations.

The cvdft function executes the Discrete Fourier positive transformation or the Discrete Fourier inverse transformation of one-dimensional or two-dimensional floating point groups:

Positive Fourier transformation of N element vector:
Y = f (n )? X, here f (n) JK = exp (-I? 2PI? J? K/N), I = SQRT (-1)
Inverse Fourier transformation of N element vector:
X' = (f (N)-1? Y = conj (f (N ))? Y
X = (1/n )? X
Positive Fourier transformation of m × N element two-dimensional vectors:
Y = f (m )? X? F (N)
Inverse Fourier transformation of m × N element 2D vectors:
X' = conj (f (M ))? Y? Conj (f (n ))
X = (1/(m? N ))? X'
Assume that the real number data (single channel), the compression format referenced from IPL is used to represent the result of a forward Fourier transformation or the input of a Reverse Fourier Transformation:

Re y0, 0: re y0, 1: Im y0, 1: re y0, 2: Im y0, 2... re y0, n/2-1 im y0, n/2-1 re y0, n/2
Re Y1, 0: re Y1, 1: Im Y1, 1: re Y1, 2: Im Y1, 2... re Y1, n/2-1 im Y1, n/2-1 re Y1, n/2
Im Y1, 0: re Y2, 1: Im Y2, 1: re Y2, 2: Im Y2, 2... re Y2, n/2-1 im Y2, n/2-1 im Y2, n/2
........................................ ........................................ ............
Re ym/2-Re YM-3, 1 im YM-3, 1 re YM-3, 2 Im YM-3, 2... re YM-3, n/2-1 im YM-3, n/2-1 re YM-3, n/2
Im ym/2-Re YM-2, 1 im YM-2, 1 re YM-2, 2 Im YM-2, 2... re YM-2, n/2-1 im YM-2, n/2-1 im YM-2, n/2
Re ym/: re YM-1, 1 im YM-1, 1 re YM-1, 2 Im YM-1, 2... re YM-1, n/2-1 im YM-1, n/2-1 im YM-1, n/2
NOTE: If n is an even number and the last column exists (is present), if M is an even number, the last row (is present ).

The transformation result of a one-dimensional real number is like the form of the first row of the matrix above. Solving Two-dimensional convolution using DFT

Cvmat * A = cvcreatemat (M1, N1, cv_32f );
Cvmat * B = cvcreatemat (M2, N2, A-> type );

-------------------------------------------------------------------------------

/* Code */

# Include 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.