Nodes/ComfyUI_FFT/InvertFFTWithMask
ComfyUI Node

InvertFFTWithMask

InvertFFTWithMask

By fssorc·Created 2 years ago·Updated 2 years ago· 15
InvertFFTWithMask
  • ff
  • mask
  • image

If you've ever scanned an old photo and ended up with a faint screen-door grid or moiré shimmer across it, this is the node you're actually looking for. InvertFFTWithMask is the working half of a tiny FFT pack from fssorc/ComfyUI_FFT - the part that takes the image's frequency spectrum, deletes the frequencies that make up the grid, and puts the image back together. It's the ComfyUI equivalent of the FFT filter in Photoshop, and for the narrow job it does, it's genuinely good.

The pack frames itself around old-photo restoration (it even ships an example scan with the repo), and the whole flow is: FFTNode → InvertFFTWithMask → SaveImage. There's no model to download and no API involved - it's all numpy math running on your own machine.

How it works

Every regular image can be decomposed into a sum of sine waves of different frequencies - the Fast Fourier Transform does that. A periodic grid like a scan pattern isn't one wave, it's a tight cluster of high-frequency waves, which shows up in the FFT display as a bright cross or a line of bright dots around the center. Kill those frequencies and the grid is gone without touching the rest of the photo.

That's exactly what this node does. Feed it the FFTData from the pack's FFTNode plus a mask, and it multiplies the complex frequency spectrum by the mask, runs the inverse FFT, and hands you a clean image. It processes all three color channels properly, which the pack's other invert node doesn't - one more reason to prefer it.

The two inputs that matter

  • ff (FFTData) - the second output of FFTNode. Wire FFTNode's first output (the image - the grayscale FFT display) to a Preview or SaveImage node so you can actually see what you're deleting.
  • mask (MASK) - paint this yourself. White keeps frequency content, black removes it. So you draw black over the bright spots and cross in the FFT display, white everywhere else.

That last bit is where people trip up: the mask's white/black is doing the real work, and it gets applied directly to the spectrum. A quick way to build it is to draw on the FFT display image in any editor, load it back, and convert it to a mask.

The single output, image (IMAGE), goes straight into SaveImage.

Install

From ComfyUI Manager, search for "ComfyUI_FFT" and hit install, or clone it manually:

cd ComfyUI/custom_nodes
git clone https://github.com/fssorc/ComfyUI_FFT

Restart ComfyUI. No requirements.txt exists in the repo and no model files are needed - it leans on numpy, scipy, and OpenCV, which a stock ComfyUI already ships. It's also a small, single-author pack with a handful of stars and no commits since September 2024, so treat it as a stable little utility, not something under active development.

Where people get burned

  • Mask size has to match the image. The spectrum is the same width and height as the input, and the mask multiplies it directly, so a differently-sized mask throws a shape error. Resize before you convert to MASK.
  • You must go through FFTNode first. No other pack produces FFTData; the type only flows between this pack's own nodes.
  • The pack's other invert node, InvertFFTNode, is broken as shipped (it indexes the FFT data like a list instead of a dict and dies with KeyError: 0). If an old workflow uses it, swap it for this node - this is the one that actually runs.

It's a niche tool, but for "get the moiré out of this scan" there isn't much that does it this cleanly. Paint the black spots, hit run, done.

CategoryFFT

Inputs (2)

NameTypeDefaultDescription
ffFFTData
maskMASK

Outputs (1)

NameTypeDescription
imageIMAGE