Nodes/opencv-comfyui/OpenCV textureFlattening_1
ComfyUI Node

OpenCV textureFlattening_1

TextureFlattening_1 — the same flattening, with a second number

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV textureFlattening_1
  • src
  • mask
  • dst
  • nparray
low_threshold
high_threshold
kernel_size

First, the honest answer to "what's different about this one?": probably nothing you'll ever notice. textureFlattening_0 and textureFlattening_1 are two overloads of the same cv2 function that the pack's code generator expanded into separate nodes. OpenCV's .pyi type stubs declare the function multiple times with slightly different signatures, the generator numbered each one, and out popped two near-identical nodes. Same inputs, same output, same behavior. If you loaded this page because you can't tell them apart, that's because there's nothing to tell apart - use whichever your workflow happened to reference.

What the node itself does is genuinely useful, though: it smooths away the fine texture in an image outside a mask you provide, while leaving the masked region untouched. That's the prep step for seamless cloning - flat the area you're blending into so a Poisson-style clone doesn't fight the existing grain. People who do face swaps and product compositing run into exactly this problem: the color gradient across the seam is fine, but the surface texture mismatch is what gives it away. textureFlattening removes that mismatch before the blend, deterministically, in milliseconds, no model involved.

Inputs and outputs that matter

  • src (NPARRAY) - the image to flatten.
  • mask (NPARRAY) - the region to keep textured. Everything outside it gets flattened.
  • low_threshold / high_threshold (FLOAT) - edge thresholds; what sits between them is treated as texture to remove.
  • kernel_size (INT) - smoothing kernel. Larger = flatter but heavier.

The optional dst is OpenCV's call-by-reference out-parameter, exposed as an input. Leave it alone - the README's standing advice across the whole pack is to avoid the optional dst slots. The output is a single nparray, which goes back into the OpenCV chain or through Nparrays2Image to become a regular IMAGE.

Installation

The pack installs once and covers both siblings - ComfyUI Manager, search "OpenCV", or:

cd ComfyUI/custom_nodes
git clone https://github.com/geroldmeisinger/opencv-comfyui

Restart, then make sure OpenCV is the contrib build (pip install opencv-contrib-python); textureFlattening only exists in the cv2.photo module that contrib ships. No models to download.

Common issues

This node is where a batch-size bug bites: Image2Nparray refuses anything but batch_size==1, so if you're flattening a stack of frames, split them first (ImageFromBatch, length=1). And if you feed it a grayscale-input-requiring path, the img.type() == CV_8UC1 assertion error tells you to convert with cvtColor first. Both are documented in the pack README - this is an auto-generated pack with rough edges, and the README is refreshingly honest about them.

Categoryimage/OpenCV

Inputs (6)

NameTypeDefaultDescription
srcNPARRAY
maskNPARRAY
low_thresholdFLOAT
high_thresholdFLOAT
kernel_sizeINT
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY