Nodes/opencv-comfyui/OpenCV idct_0
ComfyUI Node

OpenCV idct_0

The inverse DCT node

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

idct_0 runs the inverse Discrete Cosine Transform - it takes a DCT-transformed array and turns it back into an image. On its own it's half a story: the interesting work happens in the forward DCT (the pack's dct_0), where you can filter, compress, or manipulate frequency content before coming back with this node. If you're doing frequency-domain image processing - JPEG-style experiments, watermarking, blur-in-frequency tricks - this is your "render the result" step.

How it works

The DCT is the transform JPEG is built on. It decomposes an image into a grid of frequency coefficients: the top-left corner of the coefficient array holds the low frequencies (the broad structure, the part your eye actually needs), and the bottom-right holds high frequencies (fine detail, noise, the part you can throw away without anyone noticing). cv2.dct() converts image → coefficients; cv2.idct() converts coefficients → image.

In this pack the practical flow is:

  1. Image2Nparray - image → nparray (float32 works best here).
  2. dct_0 with flags=0 - image → DCT coefficients.
  3. Something in between - a mask that zeros high-frequency coefficients for a compression/denoising effect, for example.
  4. idct_0 - coefficients → image back out.
  5. Nparrays2Image - nparray → Comfy IMAGE.

The inputs that matter

  • src (NPARRAY) - the DCT coefficient array you want to invert. This should be a float32 array; feeding it a uint8 image directly will not produce the image you started with, because the forward transform was never applied.
  • flags (INT) - 0 for the standard 2D inverse DCT; 4 (cv2.DCT_ROWS) for row-wise 1D transforms instead. Beginners want 0.
  • dst (NPARRAY, optional) - the generator's out-parameter; leave it disconnected and read the nparray output.

The dct_0 node (and its flags values - 1 is DCT_INVERSE, 4 is DCT_ROWS) is the forward counterpart you'll pair this with.

What you'd use it for

Honest answer: this is a niche-in-ComfyUI node. Frequency-domain filtering shows up in real pipelines - lossy-compression studies, denoising by cutting high frequencies, image forensics, invisible-watermark experiments - but most Comfy users never touch the DCT. If you do go down this road, the payoff is understanding where the visual information lives in an image, which is genuinely illuminating.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

or "OpenCV" via ComfyUI Manager, plus pip install opencv-contrib-python. No model files.

Gotchas

The classic beginner mistake is feeding idct_0 an image that never went through dct_0 and expecting the original back - it isn't a blur or a filter, it's an inverse transform, and garbage in means a noise-looking array out. Keep your working data in float32 and expect the output nparray to need Nparrays2Image (and possibly a scale/offset fix) before it displays correctly. This is squarely an "expect dragons" node - know the DCT before you grab it.

Categoryimage/OpenCV

Inputs (3)

NameTypeDefaultDescription
srcNPARRAY
flagsINT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY