Nodes/opencv-comfyui/OpenCV idft_0
ComfyUI Node

OpenCV idft_0

The inverse Fourier transform, for when you actually work in frequency space

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV idft_0
  • src
  • dst
  • nparray
flags
nonzeroRows

idft_0 is the inverse discrete Fourier transform: you feed it a spectrum (the output of dft_0, the forward transform, in this same pack) and it reconstructs the spatial image. This is the node you reach for when you're doing frequency-domain image work - removing periodic noise like moiré, building a notch filter to kill a repeating texture, or low-pass filtering by zeroing high-frequency bins instead of blurring pixels. It's niche, but when you want it, nothing else in ComfyUI wraps it.

The honest framing first: this pack auto-generates a node for every top-level cv2 function by parsing OpenCV's type stubs, and the README warns "Expect dragons!". idft_0 is a thin wrapper over cv2.idft. If you already know you're going to be doing Fourier-domain filtering, great - this is the reconstruction half of the pipeline. If you don't, you almost certainly don't need this node, and that's not a dig at you.

How it works. The forward dft turns an image into a spectrum of complex numbers (real + imaginary parts), arranged with the zero-frequency component in the corners. You do your filtering there, then idft reverses it. Because the transform is invertible, the round trip is exact up to floating point - unless you changed the spectrum, in which case the result is your filtered image.

The two inputs that matter:

  • src (NPARRAY) - the spectrum from dft_0. This is the only thing you'd normally wire in.
  • flags (INT) - the DFT flags. For idft, the two you'll actually use are DFT_SCALE = 2 (normalizes so the inverse properly undoes the forward scaling - without it your image comes back brighter by a factor of N) and DFT_REAL_OUTPUT = 8 if your source was real and you want a real image back. So 2 for the plain inverse, 10 (2+8) for inverse-plus-real-output.

nonzeroRows (INT, default 0) is an optimization: if only the top few rows of the input are nonzero, OpenCV can skip work. Leave it at 0 unless you know the optimization applies. dst is an optional out-parameter that the README tells you to just not connect - the node returns the result through nparray anyway.

Output. A single nparray (NPARRAY) - the reconstructed image. Convert it back to a ComfyUI IMAGE with Nparrays2Image.

Installing. Via ComfyUI Manager, search "opencv-comfyui". Manually:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-python-contrib

Then restart ComfyUI. The node lives under image/OpenCV.

Where people get burned. The classic one is forgetting the scale flag and getting a bright, washed-out reconstruction - idft without DFT_SCALE doesn't divide by N, so your image comes back way overexposed. Set flags = 2 (or 10). Also remember the pack's batch-size rule: input images must be batch of one, or you get the Only images with batch_size==1 are supported! error - fix with ImageFromBatch at length=1. And note that the NPARRAY you feed in must actually be a complex spectrum as dft_0 produced it; feeding it a normal BGR image and expecting magic just produces a wrong-looking result.

Why idft_0 and not idft_1? They're the same function. The _0/_1 suffix is OpenCV's overload index from its type stub, and the generator emitted both signatures. In the shipped source both call cv2.idft with the same argument order. Pick either; there's no behavioral difference.

Categoryimage/OpenCV

Inputs (4)

NameTypeDefaultDescription
srcNPARRAY
flagsINT
nonzeroRowsINT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY