ComfyUI-CorridorKey
1) Project name + one line summary
ComfyUI-CorridorKey is a ComfyUI custom node package that exposes a native CorridorKey node for CorridorKey-style coarse-mask refinement inside ComfyUI.
2) Problem statement and goals (what it does, what it does NOT do)
ComfyUI-CorridorKey adapts the intent of the upstream CorridorKey project for ComfyUI users who already build masks inside ComfyUI. Instead of running a separate command-line application and instead of bundling extra mask-generation tools such as VideoMaMa or GVM, this node accepts:
- an
IMAGEinput - a coarse
MASKinput produced by other ComfyUI nodes
It then performs an edge-aware matte refinement pass and returns:
- a refined alpha
MASK - a selected preview
IMAGEbased on the requested output mode - dedicated
IMAGEoutputs for foreground, processed, and comp previews
Goals:
- Keep the integration native to ComfyUI's standard custom-node format.
- Reuse existing ComfyUI nodes for coarse mask creation.
- Keep runtime dependencies small and compatible with a typical ComfyUI Python environment.
- Provide a deterministic, testable baseline refinement pipeline that is safe to run locally.
- Track upstream
CorridorKeychanges safely and surface newer verified commits without blindly overwriting local custom-node code.
Non-goals:
- This project does not reimplement the full upstream research model or ship upstream CorridorKey checkpoints.
- This project does not recreate
VideoMaMa,GVM, or any separate mask-proposal pipeline. - This project does not download models, call external services, or require network access at runtime.
- This project does not write output files to disk; it only returns ComfyUI node outputs.
- This project does not auto-overwrite its own code from the upstream
CorridorKeyrepository, because that repository is not the same codebase as this ComfyUI custom node.
3) Features (current + clearly marked planned)
Current features:
- One ComfyUI node:
CorridorKey - Accepts batched
IMAGEtensors andMASKtensors - Broadcasts a single mask across an image batch when needed
- Validates shapes, value ranges, and numeric settings
- Exposes upstream-inspired controls for:
Gamma SpaceDespill StrengthAuto-DespeckleDespeckle SizeRefiner Strength- output mode selection (
FG,Matte,Processed,Comp)
- Performs deterministic edge-aware mask smoothing, spill suppression, and comp preview generation
- Returns refined alpha mask plus selected output, foreground, processed, and comp preview images
- On module load, performs a best-effort background check for newer upstream commits that have no failing GitHub check-runs
- Includes pytest coverage for the core processor
Planned features:
- Planned: optional backend that can call a true upstream CorridorKey-compatible runtime if the user provides one
- Planned: trimap output for downstream compositing workflows
- Planned: preset profiles tuned for hair, glass, and semi-transparent edges
- Planned: optional preview compositing against solid-color backgrounds
4) Requirements (Python version, OS, dependencies)
- Python: 3.10 or newer
- OS: Windows, Linux, or macOS where ComfyUI runs
- Runtime dependencies:
torch(normally already present in the ComfyUI Python environment)numpyPillow
- Development dependencies:
pytestruffblackmypy
5) Quick start (venv, install, run)
This repository is meant to live under ComfyUI's custom_nodes directory.
Recommended ComfyUI installation:
- Clone this repository into
ComfyUI/custom_nodes/. - Install the runtime dependencies into the same Python environment ComfyUI uses.
- Restart ComfyUI.
Typical install flow:
cd ComfyUI\custom_nodes
git clone <repo-url> ComfyUI-CorridorKey
cd ComfyUI-CorridorKey
python -m pip install -r requirements.txt
After that, restart ComfyUI and the CorridorKey node should appear.
If you are using ComfyUI Portable on Windows and want to be explicit about the embedded Python:
cd ComfyUI_windows_portable\ComfyUI\custom_nodes
git clone <repo-url> ComfyUI-CorridorKey
..\..\python_embeded\python.exe -m pip install -r .\ComfyUI-CorridorKey\requirements.txt
Manual install also works:
- Copy the
ComfyUI-CorridorKeyfolder intoComfyUI/custom_nodes/. - Run
python -m pip install -r requirements.txtfrom inside that folder. - Restart ComfyUI.
Development install:
python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install -e .[dev]
Restart ComfyUI after installation. The node will appear under the CorridorKey category.
For a normal ComfyUI install, requirements.txt is the primary runtime dependency file. pyproject.toml is kept for editable installs and development tooling.
6) Configuration (env vars, config files, defaults)
The node does not require config files.
Runtime configuration is passed through node inputs:
gamma_space:sRGBorLinear, matching the upstream input interpretation conceptfeather_radius: integer blur radius used to soften the coarse mask before refinementedge_focus: float multiplier that strengthens image-edge preservationthreshold: float cutoff used to center the matte transitionpreserve_core: float band that locks obvious foreground/background valuesdespill_strength: normalized float from0.0to1.0that reduces green spill on semi-transparent foreground edgesrefiner_strength: float multiplier that strengthens the edge-aware matte correction passauto_despeckle: enables a small morphology-based cleanup passdespeckle_size: integer control for the minimum speckle scale to suppressoutput_mode: selects the primary preview output asFG,Matte,Processed, orComp
Defaults:
gamma_space = sRGBfeather_radius = 4edge_focus = 1.5threshold = 0.5preserve_core = 0.2despill_strength = 1.0refiner_strength = 1.0auto_despeckle = enableddespeckle_size = 400output_mode = Processed
Implementation note:
- The upstream app uses model-driven processing. This ComfyUI node mirrors the same user-facing control surface where practical, but the internal math is a deterministic local approximation built around the provided image and coarse mask.
- The upstream CLI uses a numeric prompt for
Auto-Despeckle Sizewith a default of400pixels. This node exposes the same value as an integer input rather than forcing a fixed dropdown.
Environment variables for upstream tracking:
CORRIDORKEY_AUTO_CHECK_UPSTREAM- Default:
1 - Set to
0to disable the background upstream check
- Default:
CORRIDORKEY_UPSTREAM_TIMEOUT_SECONDS- Default:
3.0 - Per-request timeout for GitHub API calls
- Default:
CORRIDORKEY_UPSTREAM_CHECK_DEPTH- Default:
15 - How many recent upstream commits to scan when looking for the newest verified commit
- Default:
The currently reviewed upstream head SHA and its last observed check state are pinned in corridor_key/upstream_sync.py.
7) Usage (examples, CLI/API examples if relevant)
Recommended ComfyUI flow:
- Load or generate an image.
- Create a coarse mask using existing ComfyUI nodes such as RMBG, SAM, Segment Anything, Florence-based tools, or manual masking nodes.
- Feed the
IMAGEand coarseMASKintoCorridorKey. - Choose
FG,Matte,Processed, orCompas the node's selected preview output. - Use the refined
MASKfor compositing, inpainting, EXR assembly, or export.
Node inputs:
image:IMAGEmask:MASKgamma_space:COMBOfeather_radius:INTedge_focus:FLOATthreshold:FLOATpreserve_core:FLOATdespill_strength:FLOATrefiner_strength:FLOATauto_despeckle:COMBOdespeckle_size:INToutput_mode:COMBO
Node outputs:
refined_mask:MASKselected_output:IMAGEforeground:IMAGEprocessed:IMAGEcomp:IMAGE
Example workflow idea:
Load Image->RMBG(or another segmentation node) ->CorridorKey->Preview Image- For EXR-oriented workflows, use the returned
foregroundandrefined_maskseparately and combine or export them with other ComfyUI nodes such ascocotools_io, instead of expecting this node to write EXR files directly.
There is no standalone CLI in this custom node package by design.
Upstream tracking behavior:
- On import, the package starts a small background check.
- It queries the upstream
nikopueringer/CorridorKeyGitHub repo. - It looks for the newest recent commit with at least one successful check-run and no failing check-runs.
- If such a commit is newer than the currently pinned verified upstream baseline, it logs that an upstream update is available for manual review.
- It does not automatically rewrite local files from upstream.
8) Architecture overview
High-level diagram in ASCII
IMAGE + coarse MASK
|
v
input validation
|
v
mask normalization
|
v
optional gamma handling
|
v
image luminance + edge map
|
v
refiner + despeckle
|
v
refined alpha MASK
|
v
despill + output assembly
| | |
v v v
FG Processed Comp
Key modules and responsibilities
nodes.py- ComfyUI-facing node class
- Defines
INPUT_TYPES, return types, and node metadata - Converts node inputs into the internal processor call
corridor_key/config.py- Dataclass for validated runtime settings
corridor_key/tensor_ops.py- Shared tensor validation, mask normalization, color helpers, and small image-processing helpers
corridor_key/processor.py- Pure processing pipeline for edge-aware matte refinement, despill, despeckle, and output assembly
corridor_key/upstream_sync.py- Best-effort GitHub API integration for verified-upstream commit checks
tests/test_processor.py- Unit tests for shape handling, validation, and output behavior
Data flow / request flow
- ComfyUI invokes
CorridorKey.run. - The node builds a
CorridorKeySettingsobject from numeric inputs. - The processor validates the image and mask tensors.
- A normalized mask batch is created and aligned to the image batch.
- The processor optionally adapts handling for
Gamma Space. - The processor derives luminance, computes an edge map, and applies the refiner pass.
- Optional despeckle cleanup is applied when enabled.
- The processor builds foreground, processed, and comp previews, including optional despill.
- The processor returns:
- refined mask
- selected output
- foreground
- processed
- comp
- ComfyUI receives the outputs without any file-system side effects.
- In parallel, an optional background task may query GitHub and log if a newer verified upstream commit is available.
9) Repository structure (tree)
ComfyUI-CorridorKey/
|-- README.md
|-- LICENSE
|-- requirements.txt
|-- pyproject.toml
|-- __init__.py
|-- nodes.py
|-- corridor_key/
| |-- __init__.py
| |-- config.py
| |-- tensor_ops.py
| |-- processor.py
| `-- upstream_sync.py
`-- tests/
`-- test_processor.py
10) Development
local dev loop
python -m pip install -e .[dev]
pytest -q
ruff check .
black --check .
mypy corridor_key
When changing behavior:
- Update
README.mdfirst if the behavior, architecture, setup, or workflow changes. - Keep the implementation aligned with the documented repository structure.
- Add or update pytest coverage for the changed logic.
- Restart ComfyUI and re-test the node in a simple image-plus-mask workflow.
testing strategy (pytest)
- Test pure processing code in
corridor_key/processor.py - Avoid ComfyUI runtime dependencies in the test suite where possible
- Cover:
- mask broadcasting
- parameter validation
- output shapes
- value range clamping
- output mode selection
- despeckle and despill edge cases
- verified-upstream selection policy for mocked GitHub metadata
lint/format rules (ruff + black or ruff format)
ruff check .for lintingblack .for formatting- Keep imports explicit and functions small
- Prefer readable tensor code over compact but opaque expressions
type checking (mypy or pyright if useful)
mypy corridor_key- Use standard type hints for public helpers and processor methods
- Keep the ComfyUI adapter lightweight and typed where practical
11) Error handling and logging (logging module, structured messages)
- Internal validation raises
ValueErrorwith specific, user-readable messages - The ComfyUI node catches nothing silently; invalid inputs should fail clearly
- Logging is intentionally minimal:
- a module-level logger may emit debug-level messages in the processor
- a background upstream checker may emit info-level status lines
- no print-based progress logging
- GitHub API checks use explicit short timeouts and fail closed
12) Security notes (inputs, secrets, safe defaults)
- No
eval,exec, or unsafe deserialization - No subprocess execution
- No model downloads or arbitrary network access during image processing
- No secrets are required
- All user-provided numeric inputs are validated and clamped to safe ranges
- File paths are not accepted as node inputs, so the node does not read or write arbitrary files
- The processor only operates on in-memory tensors returned by ComfyUI
- The optional upstream checker uses only GitHub's API with a short timeout, does not require tokens, and never executes remote code
13) Deployment (if applicable)
Deployment is simply installation as a ComfyUI custom node:
- Place this folder under
ComfyUI/custom_nodes/. - Install the package into the same Python environment used by ComfyUI.
- Restart ComfyUI.
There is no separate server, container, or packaged service in this repository.
14) Troubleshooting and FAQ
Q: Why does this node require a mask input?
A: This package intentionally reuses existing ComfyUI segmentation and masking nodes instead of duplicating them.
Q: Why does it not match the full upstream CorridorKey model exactly?
A: This implementation provides a native, deterministic refinement pass inspired by the same workflow goal, without bundling upstream research weights or optional external pipelines.
Q: My mask looks too soft.
A: Lower feather_radius, lower preserve_core, raise edge_focus, or raise refiner_strength.
Q: My mask looks too harsh.
A: Raise feather_radius slightly or lower threshold.
Q: Why is Processed not writing an EXR with alpha by itself?
A: ComfyUI nodes exchange in-memory tensors. This node returns separate foreground and refined_mask outputs so you can assemble or export EXR data elsewhere in the workflow.
Q: Why is the default despeckle_size so large?
A: The upstream CorridorKey CLI defaults Auto-Despeckle Size to 400 pixels. On small images, you may need to lower that value or disable auto-despeckle.
Q: Does this node auto-update itself from GitHub?
A: It automatically checks for newer upstream commits that appear verified, but it does not self-modify local code. The upstream repo is a different project, so updates should still be reviewed and ported intentionally.
15) Roadmap
- Add an optional pluggable backend for a true upstream-compatible inference engine
- Add trimap and confidence outputs
- Add more regression tests around semi-transparent regions
- Add a true RGBA or EXR-friendly packed output path if the surrounding ComfyUI ecosystem provides a stable tensor contract for it
- Add an example ComfyUI workflow JSON once the node behavior stabilizes
16) Contributing (branching, commit style, PR checklist)
Branching:
- Use short-lived feature branches from
main - Keep one focused change per branch
Commit style:
- Prefer imperative commit messages
- Example:
Add edge-aware CorridorKey refinement node
PR checklist:
- Update
README.mdfirst when behavior or structure changes - Run
pytest -q - Run
ruff check . - Run
black --check . - Run
mypy corridor_key - Confirm the node loads in ComfyUI
- Keep the public node contract backward compatible unless documented
17) License placeholder
This package is based on the workflow and licensing expectations stated by the upstream nikopueringer/CorridorKey repository.
Upstream license status:
- The upstream repository does not present a standard standalone SPDX license file in the root.
- Its README includes a custom license statement described by the author as effectively a variation of
CC BY-NC-SA 4.0. - The upstream README also states additional restrictions, including:
- no repackaging and resale of the tool
- no paid API inference service using the model without a separate agreement
- released variations or improvements should remain free and open source
- future forks or releases should keep the
Corridor Keyname
For this custom node, treat the upstream repository's licensing terms as the governing reference unless the repository owner explicitly relicenses this work.
This repository also includes a local LICENSE file that summarizes the same upstream-derived terms for convenience.
Source reference:
- Upstream repository:
https://github.com/nikopueringer/CorridorKey - Upstream licensing section:
README.md, sectionCorridorKey Licensing and Permissions