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

cv2.ft.FT12D_createPolynomMatrixHorizontal

An OpenCV helper matrix, exposed because the generator wraps everything

By bmad4ever·Created 4 months ago·Updated 14 days ago· 1
cv2.ft.FT12D_createPolynomMatrixHorizontal
    • nparray
    ◄radius0►
    ◄chn0►

    Let's be straight about this one. cv2.ft.FT12D_createPolynomMatrixHorizontal builds an internal helper matrix for the F¹ fuzzy-transform pipeline, and OpenCV's entire documentation for it is one line: it creates the helper horizontal matrix for F¹-transform processing, and "it is used for gradient computation." That's it. There's no tutorial, no example, no shipped workflow in this pack that uses it, and the pack's own docs classify its whole family of ~470 generated wrappers as raw and uncurated.

    So this article is mostly a "do you actually want this?" check, plus what the two inputs do.

    The inputs

    • radius - the radius of the basic function, i.e. the same r that makes the transform's window (2r+1) square. It has to match the kernel you're working with.
    • chn - the number of channels the matrix is being built for. Match your image: 3 for BGR, 1 for greyscale.

    One output, nparray - the matrix itself, 32-bit float. Both widgets open at 0, and neither default does anything useful: radius 0 is a degenerate 1×1 basis and 0 channels matches nothing you'd feed it. If you're seeing a nonsensical result, those are the two numbers to look at first.

    Do you need it?

    Probably not. If your goal is a gradient, use cv2.Sobel, cv2.Scharr, or the pack's cv2.getDerivKernels (which hands you the separable pair behind both). Those are well documented, well understood, and fast.

    This node is for one narrow case: you're recreating the F¹ gradient step yourself rather than calling FT12D_components / FT12D_polynomial and letting them do the internal work. The polynomial basis the F¹ transform fits has a horizontal and a vertical term - the c01 and c10 coefficients in the polynomial variant, average horizontal and vertical gradient - and each direction has its own helper matrix. This is the horizontal one, the x-side term. Its sibling FT12D_createPolynomMatrixVertical is the y-side.

    Where it's genuinely handy is inspection. Build the matrix, look at it with Inspect CV Data, and you can see the shape of the basis the fit is using - which is more than the one-line documentation will tell you. As a way of learning what the fuzzy transform is doing internally, that's worth one run.

    Install

    Manager → search ComfyUI CV, or:

    cd ComfyUI/custom_nodes
    git clone https://github.com/bmad4ever/comfyui_cv
    pip install "opencv-contrib-python-headless~=5.0.0.93"
    

    Restart ComfyUI. ft ships only in contrib wheels, and because all four OpenCV distributions share a single site-packages/cv2, installing plain opencv-python can silently empty the contrib submodules and make this node disappear. tools/repair_opencv_contrib.py --check tells you whether that's your problem. Python ≥ 3.12, recent V3-API ComfyUI, nothing to download.

    Where people get burned

    • Both defaults are wrong. Radius 0 and 0 channels, every time.
    • Mismatched radius. A helper matrix built for radius 3 has no meaning against a kernel built for radius 8.
    • Expecting an image. It's a matrix NPARRAY; a preview node will min-max normalise it into a meaningless grey rectangle.
    • Expecting support. This is the least-travelled corner of a pack that ships ~470 raw wrappers plus hundreds of curated nodes. No workflow in the repo uses the F¹ polynomial machinery, so there is nobody to copy from - read OpenCV's ft module source or documentation before leaning on it.
    Categoryimage/CV/low-level/ft

    Inputs (2)

    NameTypeDefaultDescription
    radiusINT0-2147483648–2147483647Radius of the basic function.
    chnINT0-2147483648–2147483647Number of channels. The function creates helper horizontal matrix for $F^1$-transfrom processing. It is used for gradient computation.

    Outputs (1)

    NameTypeDescription
    nparrayNPARRAY—