OpenCV getGaussianKernel_0
The 1D Gaussian Blur Kernel — Blur's Building Block
- nparray
OpenCV getGaussianKernel_0 generates the 1D Gaussian convolution kernel OpenCV uses for blurring - a column vector of weights shaped like a bell curve. It's the ingredient behind a Gaussian blur, not the blur itself. The pack's GaussianBlur node does the whole job for you, so this one matters when you want the bare kernel: to apply it yourself via sepFilter2D, to combine it with another kernel, or just to see exactly what coefficients a given sigma produces.
How it works
A 2D Gaussian blur is separable - it's the outer product of a 1D kernel with itself. OpenCV's getGaussianKernel(ksize, sigma) computes that 1D kernel directly from the math: weights proportional to exp(-x²/(2σ²)), normalized so they sum to 1. If you pass sigma=0, OpenCV derives a sensible sigma from the kernel size for you - that's what the convenience blur nodes effectively do, and it's the right move unless you have a specific target.
The inputs
- ksize (
INT) - kernel length, in pixels. Must be positive and odd (1, 3, 5, 7, …); an even value trips OpenCV's assertion. - sigma (
FLOAT) - the standard deviation in pixels.0= let OpenCV compute it. Note the asymmetry: for a fixedksize, a large sigma just trims the tails, so you don't get a wider blur for free. - ktype (
INT) - output dtype of the kernel:-1for same-as-source,5forCV_32F,6forCV_64F. Float is the sane choice; the kernel coefficients are fractional by nature.
Output is a single nparray - a 1D (ksize, 1) float vector, not an image. In NPARRAY form it's OpenCV numpy, so it can't be previewed directly; you either consume it with a convolution node or accept that it's a number you're using, not looking at.
Why you'd reach for it instead of GaussianBlur
Two honest reasons. First, custom application: sepFilter2D with this kernel gives you a Gaussian blur you control as two separable passes, which is the standard setup for performance-sensitive pipelines or for asymmetric smoothing (blur more in one direction than the other by using different kernels per axis - a real technique for motion-ish softening). Second, education and verification: if you're hand-building a filter pipeline or debugging why a blur looks different from the stock one, this node shows you the coefficients instead of hiding them.
If all you want is "soften this image," stop reading and use GaussianBlur - that's the one-step answer, and the KB's post-processing playbook is explicit that a Gaussian smears everything including edges, so it's the softening tool, not the edge-preserving one (that'd be bilateral). getGaussianKernel is for the days you need the parts.
Install and gotchas
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, done, no models. Pack rules: outputs are NPARRAY not IMAGE, batch size stays 1, and this particular node's inputs are all plain numbers - no literal-string traps, which makes it one of the friendlier members of the family. Even ksize here is a plain INT, not a bracketed Size literal. The only real footgun is even ksize and forgetting that the output is a 1D vector, not a usable image.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| ksize | INT | — | |
| sigma | FLOAT | — | |
| ktype | INT | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| nparray | NPARRAY | — |