Nodes/ComfyUI_CompressedSensingAugmentation/Compressed Sensing (10% Random Sampling)
ComfyUI Node

Compressed Sensing (10% Random Sampling)

Rebuild an Image From 10% of Its Frequencies

By bemoregt·Created 6 months ago·Updated 6 months ago· 1
Compressed Sensing (10% Random Sampling)
  • image
  • reconstructed
  • kspace_mask
sampling_ratio0.10
sampling_patternvariable_density
iterations300
tv_weight0.050
seed0

This node will not make your images prettier. It will not upscale them, sharpen them, or unblur a face. What it does is arguably cooler: it throws away 90% of your image's Fourier coefficients, then mathematically reconstructs the whole image from what's left - the actual compressed sensing algorithm from the MRI literature, running live on whatever you feed it.

Be honest about what that means before you install it. Compressed sensing is the math behind "Sparse MRI," where scanners deliberately sample a fraction of k-space to cut scan time, then rebuild the scan afterward. This pack is a working, self-contained demo of that idea, not an image-enhancement utility. You reach for it when you want to see how the trick works, use the k-space mask as a visualization, or add a genuinely weird augmentation to a pipeline. The name says "Augmentation," but there's no training and no dataset involved - it's a single reconstruction node.

How it works

The node transforms your image into k-space with a 2-D FFT, keeps a random sampling_ratio fraction of the complex coefficients (10% by default), and reconstructs via ISTA - iterative gradient descent with a total-variation (TV) denoising step, the same combination Lustig, Donoho & Pauly used for sparse MRI. The step size is hard-coded to 1.0, which is safe because the FFT is unitary and the mask is binary, so the Lipschitz constant is exactly 1. The implementation is pure NumPy in float64 on the CPU - every iteration is an FFT on your full image.

Two sampling patterns exist. variable_density (the default) draws samples from a 2-D Gaussian centered on DC, MRI-style, and always keeps DC itself; uniform samples every k-space cell with equal probability. For real images, variable density wins on looks, because nearly all the energy lives at low frequencies.

The inputs that matter

Only image is required; everything else has a sensible default:

  • sampling_ratio (0.01–1.0, default 0.10) - how much k-space to keep. Crank it to 0.2–0.3 and the reconstruction gets dramatically cleaner.
  • iterations (10–2000, default 300) - ISTA iterations. More is better quality and slower. 500–1000 is the sweet spot if you're patient.
  • tv_weight (0.001–2.0, default 0.05) - regularization strength. Lower is sharper, higher is smoother.
  • seed - the trap. 0 (the default) means a different random mask every run, so your outputs won't reproduce. Set any non-zero integer to lock the mask.

Two outputs come out: reconstructed (the recovered image) and kspace_mask, a visualization of the sampling pattern with DC at the center and white where samples were taken. Preview them side by side and the whole trick becomes legible at a glance.

Installing it

It's in the ComfyUI Manager registry, so search "CompressedSensing" there and click install. Or do it by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/bemoregt/ComfyUI_CompressedSensingAugmentation
pip install scikit-image

Then restart ComfyUI. There are no model downloads - this is one of the rare packs that needs nothing but numpy and scikit-image (requirements.txt is just those two). scikit-image isn't strictly required either: the code falls back to a pure-NumPy Chambolle TV solver, so it runs either way, just slower without it.

Where people get burned

It's a math demo, and the math takes its time. Default 300 iterations of FFT on a full-resolution image on CPU can take a while - and it loops over every image in your batch, so a batch of four is four times the work. Downscale the input first with an ImageScale node, or drop iterations, before you get frustrated. And if your two runs don't match, check seed first: zero means "random every time."

The honest bottom line: this is a learning tool from a prolific author who publishes a whole family of signal-processing demos (Fourier, DCT, phase, quaternion variants), and it's genuinely good at being one. If that's your goal - or you just want to watch a MRI-style reconstruction rebuild your own images - it's a fun, dependency-light add. Just don't wire it into your SDXL workflow expecting magic. It was never meant to.

CategoryCompressedSensing

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
sampling_ratiooptFLOAT0.100.01–1
sampling_patternoptCOMBOvariable_density2 options: variable_density, uniform
iterationsoptINT30010–2000
tv_weightoptFLOAT0.0500.001–2
seedoptINT00–2147483647

Outputs (2)

NameTypeDescription
reconstructedIMAGE
kspace_maskIMAGE