OpenCV getGaborKernel_0
The Fiddliest Filter in This Pack, and Worth It
- nparray
OpenCV getGaborKernel_0 builds a Gabor filter kernel: a sinusoid windowed by a Gaussian, tuned to respond strongly to texture at one specific orientation and spatial frequency. This is the pack's most powerful filter-building node and simultaneously its least friendly - six numeric knobs, no defaults worth trusting, and the output isn't an image you can look at. It's texture analysis, the way a spectrogram is audio analysis: you get out exactly what you design in.
The mechanism
A Gabor kernel is a plane wave (the sinusoid) multiplied by a Gaussian envelope (the window). Its parameters control the wave and the window independently:
- ksize (
STRING) - kernel size as a literal, e.g.[31, 31]. Odd values, and big enough to fit a few wave cycles or it'll be truncated. - sigma (
FLOAT) - the standard deviation of the Gaussian envelope. Bigger sigma = a wider window, more spatial context. - theta (
FLOAT) - orientation of the filter, in radians.0is vertical-ish,math.pi/2is horizontal. This is the knob you sweep to build an orientation bank. - lambd (
FLOAT) - wavelength of the sinusoid, in pixels. Smaller wavelength = higher frequency detail. - gamma (
FLOAT) - aspect ratio of the Gaussian (ellipticity).1is circular; less than 1 stretches the filter along the orientation axis. - psi (
FLOAT) - phase offset of the sinusoid, in radians. Odd vs. even symmetry of the kernel. - ktype (
INT) - output dtype (-1for same as source,5forCV_32F,6forCV_64F). Use a float type; integer kernels here are a footgun.
Output is one nparray - the kernel itself, a small float matrix, not an image. To see what it does, wire it into the pack's filter2D node (or sepFilter2D won't work - Gabor isn't separable). A classic pipeline: generate several kernels at different theta values, filter2D each, and combine or pick the strongest response. That's how you'd detect wood grain, fingerprint ridges, or fabric weave orientation.
Where it fits
This is the anti-"AI does it" tool: deterministic, millisecond, zero models. If your workflow needs to find periodic texture structure - alignment marks, screen-door patterns, repeating fabric - Gabor is the textbook primitive, and post-processing is exactly where the KB's playbook says to reach for cheap deterministic ops before burning a diffusion pass. That said: with six knobs and no feedback loop, budget some experimenting. Start from a known-good set (small odd ksize, sigma around ksize/5, lambd a few pixels, gamma ~0.5, psi 0) and tune one knob at a time.
Install
ComfyUI Manager → search opencv-comfyui (display "OpenCV"), or:
cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui
pip install opencv-contrib-python
Restart. No models. Remember ksize needs the bracket-literal form [31, 31] - a bare 31 throws the pack's invalid syntax (<unknown>, line 0) error. And the kernel output is NPARRAY, so when you eventually convert filtered results back, it's Nparrays2Image on the end and batch size 1 throughout.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| ksize | STRING | — | |
| sigma | FLOAT | — | |
| theta | FLOAT | — | |
| lambd | FLOAT | — | |
| gamma | FLOAT | — | |
| psi | FLOAT | — | |
| ktype | INT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |