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

cv2.ft.createKernel1

Building a fuzzy kernel from your own basis

By bmad4ever·Created 4 months ago·Updated 15 days ago· 1
cv2.ft.createKernel1
  • A
  • B
  • nparray
◄chn0►

cv2.ft.createKernel1 is the escape hatch of OpenCV's fuzzy-transform module. cv2.ft.createKernel builds you a kernel from a predefined basic function and a radius (LINEAR only, on this OpenCV build). createKernel1 skips the preset entirely: you hand it two matrices, A and B, and it builds the kernel from those. It's the node for people who want a fuzzy partition that isn't the triangular default - and it's honest to say that's a small group of people.

Both live in ComfyUI CV (bmad4ever), the pack wrapping OpenCV 5.0 as ComfyUI nodes: roughly 470 generated raw cv2.* wrappers plus a curated layer. This is a raw one. No tooltips beyond the parameter descriptions, no guard rails.

How it differs from createKernel

A fuzzy kernel encodes a partition of unity: overlapping membership functions whose values sum to 1 across the image, laid down over a grid whose spacing is the radius. createKernel generates that from the preset. createKernel1 takes two 2-D basis matrices and constructs the kernel from them, per channel. OpenCV's own documentation for it is a single line - "creates kernel from the given matrices" - so this is the part of the module where you experiment rather than follow a spec.

The three inputs:

  • A - the first basis matrix, an NPARRAY-flavoured socket (it accepts an IMAGE/MASK link too, per the pack's usual conversion rule: an IMAGE becomes a BGR uint8 array, frame 0 of a batch).
  • B - the second basis matrix, same socket type.
  • chn - the channel count the kernel is built for: 3 for BGR, 1 for grayscale, matching the image it will filter.

Output is a single NPARRAY kernel, 32-bit float, ready for cv2.ft.filter, cv2.ft.FT02D_components, or cv2.ft.FT02D_inverseFT - the same consumers as the preset kernel, because downstream nothing cares how the kernel was made.

Where do A and B come from in a ComfyUI graph? That's the honest friction with this node. They're matrices you author or compute: Parse Matrix for a delimited text block you paste in, CV Points for a small literal array, CV Concat Arrays / CV Reshape Array to assemble one, or whatever upstream cv2 node produces the shape you want. If you're reaching for createKernel1 because the LINEAR preset is too blunt but you don't have a specific membership function in mind, the more productive experiment is usually to keep createKernel, change the radius, and see what the scale knob alone does.

Install

ComfyUI Manager → 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 and a recent ComfyUI (the pack is written against the V3 node API); restart ComfyUI after installing. The one dependency is opencv-contrib-python-headless~=5.0.0.93, and for this node family contrib is the whole story: cv2.ft is a contrib module, so on a plain opencv-python wheel this node doesn't exist. Because all four OpenCV pip distributions share a single site-packages/cv2, installing the non-contrib wheel over the contrib one empties the contrib submodules without complaining. The pack's own repair tool is the diagnostic:

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

Common issues

A shape mismatch error from cv2. A and B have to be consistent with each other and with chn; the kernel is built by combining them per channel, and cv2 validates the result. Print the arrays (Inspect CV Data, CV Array Shape) before feeding them in - the wrapper's error message names the argument shapes it passed, which usually makes the mismatch obvious.

The filtered result looks wrong in a way that has structure. With an anisotropic or shifted partition you can get structured artefacts rather than a smooth approximation - that's the transform faithfully doing what you asked. Compare against a createKernel kernel at the same radius to see how much of the effect is your basis and how much is the transform.

A grey/black output. Kernel values need to behave like membership weights. Random or unnormalised matrices will produce a reconstruction that's simply dark - again, the transform is doing its job; the partition is the bug.

Missing node. Contrib wheel overwritten: run the check above, and --apply with ComfyUI stopped.

Categoryimage/CV/low-level/ft

Inputs (3)

NameTypeDefaultDescription
ANPARRAY,IMAGE,MASK - - - Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
BNPARRAY,IMAGE,MASK - - - Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
chnINT0-2147483648–2147483647 - - -

Outputs (1)

NameTypeDescription
nparrayNPARRAY—