PD_RemoveWhiteBorder
Getting a usable mask out of a white-background image, no model needed
- image
- image
- mask
Product shot on white, a logo, a scan of a drawing on white paper - the classic "I need to get the subject off this white background" problem. The heavyweight answer is BiRefNet or rembg (see the background-removal doc for the whole battlefield). The lightweight answer is this node: it thresholds the image, finds the white areas, and hands you an inverted mask that marks everything not white as the subject. No model, no download, works on a batch, fast.
Read the tooltip, because it's the author's own description and it's accurate: "白色区域检测灵敏度,0-100,值越大检测越严格" - white-region detection sensitivity, 0-100, higher = stricter. So threshold is your "what counts as white" knob.
How it works
It converts the image to grayscale, scales your 0-100 threshold to 0-255, and marks every pixel at or above it as white. Then it cleans the mask with a median blur plus open/close morphology - the kernel size adapts to image size and threshold, so a 4K photo gets heavier denoising than a 512px thumbnail. Finally it inverts the mask, so in the output mask, white = the non-white subject, black = the background you'd cut away.
That inversion is the thing everyone trips on. The node is named "RemoveWhiteBorder" but it doesn't remove anything - it gives you the mask that would let you remove it. White in the output mask is what stays.
The inputs and outputs
image(IMAGE) - your input. Batches fine.threshold(0-100, default 70) - sensitivity. Lower = more aggressive (more of the image counts as white); higher = stricter (only near-white counts).
Outputs: image (the original, untouched, so it's a passthrough) and mask (the inverted white-region mask, ready for compositing or a Remove Background-style workflow).
Installing it
Part of Comfyui_PDuse by 7BEII. ComfyUI Manager (search "PDuse") or:
cd ComfyUI/custom_nodes
git clone https://github.com/7BEII/Comfyui_PDuse.git
cd Comfyui_PDuse
pip install -r requirements.txt
Restart. It leans on opencv-python from the pack's requirements - no separate model downloads.
Where people get burned
The inverted mask is the number one trap: wire the output straight into a compositor expecting "white = cut out" and you'll cut the subject instead of the background. Second, thresholding is dumb and honest about it: it can't tell "white background" from "white shirt," so anything white inside the subject gets removed too. That's why the docstring says it detects all white regions including internal ones. For logos and clean product shots on white it's great; for a white wedding dress on a white wall it's a lost cause - that's what the model-based cutters are for. Start at threshold = 70 and nudge it; the morphology pass does real work, so don't crank it to 100 and wonder why nothing reads as white.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| threshold | INT | 700–100 | 白色区域检测灵敏度,0-100,值越大检测越严格 |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | — |
| mask | MASK | — |