OpenCV mulSpectrums_0
Multiply two Fourier spectra — the pack's deepest rabbit hole
- a
- b
- c
- nparray
mulSpectrums_0 wraps cv2.mulSpectrums(a, b, flags, c, conjB) - element-wise multiplication of two arrays in the frequency domain. That's the whole trick of fast convolution and correlation: instead of sliding a kernel over an image pixel by pixel, you transform to frequency space, multiply, and transform back. It's a real, powerful primitive. It's also the furthest thing from a beginner node in this pack, and you should only reach for it if you know why you're in frequency space at all.
What it does
A Fourier-transformed image isn't an image anymore - it's a complex array where low frequencies (smooth gradients) live near the center and high frequencies (edges, noise) near the edges. Multiplying two spectra, then inverse-transforming, gives you:
- Convolution, if you multiply normally - filter an image by multiplying its spectrum with a filter's spectrum. That's how frequency-domain low-pass (blur) and high-pass (sharpen/edge) filtering works.
- Correlation, if
conjBisTrue- this conjugates the second spectrum, which flips one signal, turning the multiply into a similarity/correlation measure. This is the basis of phase-correlation template matching.
So the classic chain in this pack is dft_0 → mulSpectrums_0 → idft_0 (all present in opencv-comfyui). Between the two DFTs you can do filtering that would be painful in the spatial domain.
Inputs
a,b(NPARRAY) - the two spectra, which must be floating-point (CV_32F/CV_64F) DFT outputs, not uint8 images. Feeding it a normal image is a type error.flags(INT) -0normally, or1(DFT_ROWS) to treat each row as an independent transform.conjB(BOOLEAN) - conjugate spectrumbbefore multiplying (correlation vs convolution).c(optionalNPARRAY) - the out-parameter; leave unconnected.
Output: nparray - a spectrum, which only makes sense fed back into idft_0 (or another mulSpectrums), never directly into Nparrays2Image.
The honest take
If you're doing frequency-domain work in ComfyUI - deconvolution, custom filter design, phase correlation - this is the node for the multiply step. If you're not, this is a great way to spend an afternoon producing noise and type errors. Frequency-domain filtering is a deep, easy-to-get-wrong area: spectra have complex values, the DC component sits in a corner, magnitudes vs phases are separate, and you'll fight CV_32FC1 vs CV_8UC1 the whole way. Before going down this path, ask whether a spatial-domain approach (filter2D, GaussianBlur, or even just normalize_0 + multiply_0) does the job. It usually does.
Installing
Part of geroldmeisinger/opencv-comfyui. Manager → search "opencv-comfyui", or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
restart. Dependency: opencv-contrib-python.
Troubleshooting
- Type errors on input - feed
dft_0output, not anImage2Nparrayresult. - Output looks like noise - it's a spectrum; it's supposed to look like noise. Route it to
idft_0, not a viewer. - Wrong result with
conjB- that's expected; it flips between convolution and correlation on purpose.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| a | NPARRAY | — | |
| b | NPARRAY | — | |
| flags | INT | — | |
| conjB | BOOLEAN | — | |
| copt | NPARRAY | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |