Nodes/opencv-comfyui/OpenCV morphologyEx_1
ComfyUI Node

OpenCV morphologyEx_1

MorphologyEx_1 — the same mask cleaner, and the story behind every _0/_1 pair

By geroldmeisinger·Created about a year ago·Updated about a year ago· 35
OpenCV morphologyEx_1
  • src
  • kernel
  • dst
  • nparray
op
anchor
iterations
borderType
borderValue

morphologyEx_1 is morphologyEx_0's duplicate. Same inputs, same nparray output, same cv2.morphologyEx call under the hood. If you want the actual guide to morphology operations - the op codes for erode/dilate/open/close/gradient, the kernel from getStructuringElement_0, the literal-string anchor gotcha - read the _0 article. This one is short on purpose: you're here because you googled _1 and found a twin.

Why the twin exists

geroldmeisinger/opencv-comfyui is generated by parsing OpenCV's type stubs, and the generator emits one node per declared overload. cv2.morphologyEx appears twice in the stubs - MatLike and UMat - so you get morphologyEx_0 and morphologyEx_1. Both array types map to the same NPARRAY input, so the two nodes are functionally identical. This pattern is everywhere in the pack: minMaxLoc_0/1, multiply_0/1, moments_0/1, normalize_0/1. When the info_schema inputs match, treat the numbered variants as one node. (The exception is norm, where _0/1 and _2/3 genuinely differ.)

The one thing to take away

Use it to clean masks: op=4 (OPEN) kills specks, op=5 (CLOSE) fills holes, op=6 (GRADIENT) extracts mask edges. The kernel is an NPARRAY you build with getStructuringElement_0 from the same pack - there's no widget for it, which is the pack's least friendly feature. anchor and borderValue are Python-literal strings, e.g. (-1, -1) and (0, 0, 0, 0); malformed literals give invalid syntax (<unknown>, line 0).

Install

ComfyUI Manager → search "opencv-comfyui", or:

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

restart. Only dependency beyond the usual torch/numpy is opencv-contrib-python.

Pipeline

IMAGE → Image2Nparray → morphologyEx_1 → Nparrays2Image → IMAGE. Image2Nparray only accepts batch_size==1 (slice batches with ImageFromBatch). Feed it a grayscale mask, get a cleaned mask back.

Troubleshooting

  • invalid syntax (<unknown>, line 0) - fix your literal strings; (-1, -1) not (-1, -1.
  • No visible effect - kernel is (1, 1) or you typed an op code that isn't 2–9.
  • Which variant - _0 or _1, doesn't matter; pick _0 so your saved workflow matches other people's docs.
Categoryimage/OpenCV

Inputs (8)

NameTypeDefaultDescription
srcNPARRAY
opINT
kernelNPARRAY
anchorSTRING
iterationsINT
borderTypeINT
borderValueSTRING
dstoptNPARRAY

Outputs (1)

NameTypeDescription
nparrayNPARRAY