Nodes/ComfyUI-PIL/PIL Remove Black Dots (Mexx)
ComfyUI Node

PIL Remove Black Dots (Mexx)

The speckle-removal node that finishes your line art

By SoftMeng·Created 2 years ago·Updated 2 years ago· 7
PIL Remove Black Dots (Mexx)
  • image
  • result_img
threshold128
dot_size2

PIL Remove Black Dots (Mexx) cleans black speckle noise off line art. The README puts it bluntly: "给线稿脱色,去除一些黑色的噪点" - decolorize the line art, remove some black noise. If you've ever run a line-extraction filter on a photo and ended up with a snowstorm of tiny black flecks around the edges, you know exactly why this node exists.

It's the cleanup half of a two-node story. Its sibling in the SoftMeng/ComfyUI-PIL pack, PIL Effects (Mexx), extracts line art with its LINE0–LINE5 filters; those filters are aggressive and leave speckle behind. This node sits right after and sweeps the small stuff so your ControlNet lineart input (or your printable sketch) isn't full of dirt. Used alone it also works on any scan or sketch that's mostly white with black marks.

How it works

Two phases, both plain Pillow pixel loops. First it walks every pixel and any pixel where all three channels are above the threshold gets forced to pure white - that's the "decolorize" step that normalizes a noisy grayish background. Then the image is converted to grayscale and a loop removes dark pixels: if a pixel is below the threshold (i.e. dark) but its surrounding dot_size-by-dot_size neighborhood is entirely light, it's flipped to white. Small isolated specks die because nothing dark surrounds them; real strokes survive because they're part of a bigger dark region.

The removal pass actually runs three times back to back, which reads like copy-paste in the source but works out to "be thorough." It's batch-safe like the rest of the pack, so each frame of a video or image batch is cleaned independently.

Inputs

  • image - the IMAGE tensor to clean.
  • threshold - default 128. What counts as "light" vs "dark" on the 0–255 scale. Raise it to be more aggressive about whitening grayish backgrounds; lower it to preserve more faint pencil marks.
  • dot_size - default 2. How big a speck is small enough to remove (it looks at a dot_size×dot_size window). Push it up to eat larger flecks, but it starts eating thin line detail fast.
  • Output: a single result_img IMAGE.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/SoftMeng/ComfyUI-PIL

Restart ComfyUI, or search "ComfyUI-PIL" in ComfyUI Manager. No requirements.txt, no model downloads - just Pillow and numpy, which ComfyUI already bundles. The clone includes ~55 MB of Chinese fonts used by the pack's TITLE node, but this node itself doesn't need them.

Gotchas

This is a rough tool, not a smart one. The neighborhood check isn't a proper kernel - it samples a small window and it's weighted toward the top-left corner, so it can miss specks hugging a real line, and big dot_size values will start eating thin strokes that you wanted. For a production anime-style cleanup you'd reach for something ML-based, but for quick sketch prep this does the job with two ints. The author, SoftMeng, is better known for ComfyUI-DeepCache-Fix, and this pack is a tiny side project with zero community footprint - expect it to be simple, static, and fine for what it does.

CategoryComfyUI_Mexx

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
thresholdINT128
dot_sizeINT2

Outputs (1)

NameTypeDescription
result_imgIMAGE