Nodes/ComfyUI CV/cv2.ft.createKernel
ComfyUI Node

cv2.ft.createKernel

The smoothing scale knob nobody told you about

By bmad4ever·Created 4 months ago·Updated 15 days ago· 1
cv2.ft.createKernel
    • nparray
    ◄functionLINEAR►
    ◄radius0►
    ◄chn0►

    The ft module is one of OpenCV's obscure contrib corners: the fuzzy transform, a method that expresses an image as coefficients over a coarse fuzzy partition, then reconstructs it. In practice, cv2.ft.filter is a smoothing/approximation filter with a single scale knob, and cv2.ft.createKernel is the node that builds that kernel. If you want a denoiser that isn't a Gaussian and doesn't need a model, this corner of the pack is worth twenty minutes.

    createKernel lives in ComfyUI CV (bmad4ever), which exposes OpenCV 5.0 to ComfyUI as ~470 auto-generated cv2.* wrappers plus curated nodes. The ft wrappers are uncurated, so they're OpenCV's parameters verbatim - with one gap the author documents himself in the tooltip, which we'll get to.

    What a fuzzy kernel is

    A fuzzy transform doesn't convolve with a small fixed stencil. It partitions the image into overlapping blocks under a fuzzy membership function (the "basic function", LINEAR here - triangular membership), computes a coefficient per block, and the inverse transform rebuilds the image from those coefficients. The kernel is the membership function evaluated across the partition, which is why it's parameterised by a radius rather than a sigma: the radius sets the spacing between block centres, and therefore the scale of everything that survives.

    Concretely: the kernel is (2·radius + 1) square per channel, and the radius is your smoothing scale. Small radius = fine detail preserved, light smoothing. Large radius = a coarse piecewise-smooth approximation that keeps big structure and throws away texture. That reconstruction step is why the output reads differently from a Gaussian of comparable width: the result is rebuilt from coarse coefficients rather than smeared.

    Inputs

    • function - a dropdown, and it has exactly one entry: LINEAR. Not a bug. The pack's tooltip says it plainly: SINUS is compiled out of this OpenCV build and raises on every call, so offering it would only hand you a node that can't run.
    • radius - INT, ported straight from cv2, so the widget starts at 0. A radius of 0 gives you a 1×1 kernel, i.e. no smoothing at all, which is why "I ran the fuzzy filter and nothing changed" is the single most common outcome with these nodes. Type a real radius. The right number scales with your image: it's a fraction of the frame, not a pixel measurement, so the same value on a 512 px and a 4K image does different amounts of work.
    • chn - the channel count the kernel is built for: 3 for a BGR image, 1 for grayscale. This must match whatever you'll filter with it. A 3-channel kernel applied to a single-channel array (or vice versa) is a cv2 error rather than a silent mismatch, but it's an easy one to cause when you build the kernel on one branch of the graph and crop the image on another.

    Output is an NPARRAY - the kernel itself, 32-bit float. Wire it into cv2.ft.filter for the one-shot version, or into cv2.ft.FT02D_components / cv2.ft.FT02D_inverseFT if you want to touch the coefficients in between (that's the compression/analysis path the module was written for).

    Install

    ComfyUI Manager → search ComfyUI CV, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/bmad4ever/comfyui_cv
    pip install -r comfyui_cv/requirements.txt
    

    Python ≥3.12, ComfyUI on the V3 node API, restart afterwards. Dependency is opencv-contrib-python-headless~=5.0.0.93 - and contrib is not optional for this node family. cv2.ft doesn't exist in plain opencv-python, so if half the pack's categories are missing from your node search (no fisheye, no ft, no aruco), the shared cv2 binary has been overwritten:

    python ComfyUI/custom_nodes/comfyui_cv/tools/repair_opencv_contrib.py --check
    python ComfyUI/custom_nodes/comfyui_cv/tools/repair_opencv_contrib.py --apply
    

    Common issues

    createKernel isn't in the node list at all. Same contrib story; the pack builds its registry from the installed build, so a function your OpenCV lacks simply doesn't produce a node.

    SINUS themed errors. You found a way to pass it anyway. Don't; LINEAR is all this build has.

    The filter output looks virtually identical to the input. Radius 0 (see above) or a radius that's tiny relative to the image.

    Everything is a grey haze. Radius far too large. The forward transform simply has too few coefficients to describe the picture, and the inverse gives you back a blurry abstraction. Halve it and look again.

    Categoryimage/CV/low-level/ft

    Inputs (3)

    NameTypeDefaultDescription
    functionCOMBOLINEARFunction type could be one of the following: - **LINEAR** Linear basic function.
    radiusINT0-2147483648–2147483647Radius of the basic function.
    chnINT0-2147483648–2147483647Number of kernel channels. The function creates kernel from predefined functions.

    Outputs (1)

    NameTypeDescription
    nparrayNPARRAY—