Complex Images and Frequency Domain

This page groups the OpenCV-side complex image and frequency-domain statements. Unlike CX., these commands operate on images/stacks stored as OpenCV Mats, typically CV_32FC2 where channel 0 is real and channel 1 is imaginary.

Typical flow: convert an image to 32F, compute CV.DFT_COMPLEX, center it with CV.DFT_SHIFT, visualize with CV.SPECTRUM_LOG_MAG/CV.SPECTRUM_PHASE, optionally filter with CV.FREQ_*, then apply CV.IDFT_SHIFT and CV.IDFT_COMPLEX.
CV.TO32F gray AS src
CV.DFT_COMPLEX src AS spec
CV.DFT_SHIFT spec AS centered
CV.SPECTRUM_LOG_MAG centered, TRUE AS logmag
GUI.SHOW logmag, "centered log spectrum"
CV.FREQ_GAUSSIAN_LOW_PASS centered, 18 AS lowCentered
CV.IDFT_SHIFT lowCentered AS lowSpec
CV.IDFT_COMPLEX lowSpec AS lowComplex
CV.SPLIT_COMPLEX lowComplex AS lowReal, lowImag
GUI.SHOW lowReal, "low-pass reconstruction"

Page map

Complex image statements 5

CV.COMPLEX_CONJ

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Complex image statements   Namespace: CV

CV.COMPLEX_CONJ complexImage AS dst

Computes the complex conjugate of a complex image by negating the imaginary channel.

Minimal example

CV.COMPLEX_CONJ complexImage AS dst

CV.COMPLEX_MAGNITUDE

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Complex image statements   Namespace: CV

CV.COMPLEX_MAGNITUDE complexImage AS magnitudeImage

Computes per-pixel magnitude sqrt(re^2 + im^2) from a complex image.

Minimal example

CV.COMPLEX_MAGNITUDE complexImage AS magnitudeImage

CV.COMPLEX_PHASE

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Complex image statements   Namespace: CV

CV.COMPLEX_PHASE complexImage AS phaseImage

Computes per-pixel phase angle atan2(im,re), in radians, from a complex image.

Minimal example

CV.COMPLEX_PHASE complexImage AS phaseImage

CV.MERGE_COMPLEX

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Complex image statements   Namespace: CV

CV.MERGE_COMPLEX realImage, imagImage AS complexImage

Merges two same-size single-channel images into a CV_32FC2 complex image: channel 0 is real, channel 1 is imaginary.

Minimal example

CV.MERGE_COMPLEX re, im AS zimg

CV.SPLIT_COMPLEX

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Complex image statements   Namespace: CV

CV.SPLIT_COMPLEX complexImage AS realImage, imagImage

Splits a CV_32FC2/CV_64FC2 complex image into real and imaginary single-channel images.

Minimal example

CV.SPLIT_COMPLEX zimg AS re, im

Frequency / spectral statements 15

CV.DFT_COMPLEX

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.DFT_COMPLEX src AS spectrum

Computes a complex 2D DFT. A real single-channel input becomes CV_32FC2; a complex two-channel input is transformed as complex data.

Minimal example

CV.DFT_COMPLEX src AS spec

CV.DFT_MAGNITUDE

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.DFT_MAGNITUDE src [, logScale] AS dst

Computes a centered 2D DFT magnitude map from the grayscale source, normalized to 0..255 as 32F.

Optional parameters

Parameters enclosed in [...] may be omitted. Nested brackets mean that the later parameter is available only when the previous optional level is also supplied.

ParameterMeaning
logScaleWhen true, applies logarithmic visualization scaling to spectral magnitude/power.

Minimal example

CV.DFT_MAGNITUDE img, TRUE AS spec

CV.DFT_SHIFT

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.DFT_SHIFT spectrum AS centered

Circularly shifts a real or complex spectrum so the DC component is at the image center. Dimensions are preserved, including odd sizes.

Minimal example

CV.DFT_SHIFT spectrum AS centered

CV.FREQ_BAND_PASS

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.FREQ_BAND_PASS centeredSpectrum, innerRadius, outerRadius AS filteredSpectrum

Keeps a centered annular frequency band and rejects frequencies outside the selected radii.

Minimal example

CV.FREQ_BAND_PASS centeredSpectrum, innerRadius, outerRadius AS filteredSpectrum

CV.FREQ_GAUSSIAN_HIGH_PASS

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.FREQ_GAUSSIAN_HIGH_PASS centeredSpectrum, sigma AS filteredSpectrum

Applies a smooth Gaussian high-pass mask to a centered complex spectrum.

Minimal example

CV.FREQ_GAUSSIAN_HIGH_PASS centeredSpectrum, sigma AS filteredSpectrum

CV.FREQ_GAUSSIAN_LOW_PASS

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.FREQ_GAUSSIAN_LOW_PASS centeredSpectrum, sigma AS filteredSpectrum

Applies a smooth Gaussian low-pass mask to a centered complex spectrum.

Minimal example

CV.FREQ_GAUSSIAN_LOW_PASS centeredSpectrum, sigma AS filteredSpectrum

CV.FREQ_HIGH_PASS

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.FREQ_HIGH_PASS centeredSpectrum, radius AS filteredSpectrum

Applies an ideal circular high-pass mask to a centered complex spectrum.

Minimal example

CV.FREQ_HIGH_PASS centeredSpectrum, radius AS filteredSpectrum

CV.FREQ_LOW_PASS

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.FREQ_LOW_PASS centeredSpectrum, radius AS filteredSpectrum

Applies an ideal circular low-pass mask to a centered complex spectrum.

Minimal example

CV.FREQ_LOW_PASS centeredSpectrum, radius AS filteredSpectrum

CV.FREQ_NOTCH

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.FREQ_NOTCH centeredSpectrum, offsetX, offsetY, radius [, mirror] AS filteredSpectrum

Suppresses a circular notch at the offset from the centered DC component. mirror=TRUE also suppresses the symmetric notch.

Optional parameters

Parameters enclosed in [...] may be omitted. Nested brackets mean that the later parameter is available only when the previous optional level is also supplied.

ParameterMeaning
mirrorOptional parameter. If omitted, the command uses its internal default.

Minimal example

CV.FREQ_NOTCH centeredSpectrum, offsetX, offsetY, radius [, mirror] AS filteredSpectrum

CV.IDFT_COMPLEX

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.IDFT_COMPLEX spectrum AS complexImage

Computes the inverse complex DFT with scaling. The output remains a complex image; split it to inspect real and imaginary residuals.

Minimal example

CV.IDFT_COMPLEX spec AS recon
CV.SPLIT_COMPLEX recon AS real, imag

CV.IDFT_SHIFT

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.IDFT_SHIFT centered AS spectrum

Inverse circular shift for a spectrum previously centered with CV.DFT_SHIFT.

Minimal example

CV.IDFT_SHIFT centered AS spectrum

CV.SPECTRUM_LOG_MAG

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.SPECTRUM_LOG_MAG spectrum [, normalize] AS logMagnitudeImage

Computes log(1+magnitude) from a complex spectrum, optionally normalized for display.

Optional parameters

Parameters enclosed in [...] may be omitted. Nested brackets mean that the later parameter is available only when the previous optional level is also supplied.

ParameterMeaning
normalizeOptional parameter. If omitted, the command uses its internal default.

Minimal example

CV.SPECTRUM_LOG_MAG centered, TRUE AS view
GUI.SHOW view, "log spectrum"

CV.SPECTRUM_MAGNITUDE

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.SPECTRUM_MAGNITUDE spectrum [, normalize] AS magImage

Computes magnitude from a complex spectrum. With normalize=TRUE the result is scaled to 0..255 for display.

Optional parameters

Parameters enclosed in [...] may be omitted. Nested brackets mean that the later parameter is available only when the previous optional level is also supplied.

ParameterMeaning
normalizeOptional parameter. If omitted, the command uses its internal default.

Minimal example

CV.SPECTRUM_MAGNITUDE spectrum [, normalize] AS magImage

CV.SPECTRUM_PHASE

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.SPECTRUM_PHASE spectrum [, normalize] AS phaseImage

Computes phase from a complex spectrum. Without normalization the result is in radians; normalized output is intended for GUI display.

Optional parameters

Parameters enclosed in [...] may be omitted. Nested brackets mean that the later parameter is available only when the previous optional level is also supplied.

ParameterMeaning
normalizeOptional parameter. If omitted, the command uses its internal default.

Minimal example

CV.SPECTRUM_PHASE spectrum [, normalize] AS phaseImage

CV.SPECTRUM_POWER

STATEMENTCVBATCH-FRIENDLYIMAGE
Kind: Command   Category: Frequency / spectral statements   Namespace: CV

CV.SPECTRUM_POWER spectrum [, logScale [, normalize]] AS powerImage

Computes power re^2+im^2 from a complex spectrum, optionally applying log(1+x) and normalization for display.

Optional parameters

Parameters enclosed in [...] may be omitted. Nested brackets mean that the later parameter is available only when the previous optional level is also supplied.

ParameterMeaning
logScaleWhen true, applies logarithmic visualization scaling to spectral magnitude/power.
normalizeOptional parameter. If omitted, the command uses its internal default.

Minimal example

CV.SPECTRUM_POWER spectrum [, logScale [, normalize]] AS powerImage