Clean Points (KDTree)
Knock the stray points out of your point cloud
- points
- Points3D
Point clouds from depth maps come with junk. Depth estimators hallucinate edges, transform operations scatter stray points, and anything you interpolate or import from a noisy PLY brings its own clutter. Clean Points (KDTree) is the pack's answer: it looks at every point, checks how isolated it is, and deletes the ones that don't have enough neighbors nearby.
The "KDTree" in the name is the mechanism, and it's the right tool for the job. A KD-tree is a spatial index that lets the node answer "who's near me?" for every point in the cloud in O(n log n) instead of checking every point against every other point. That matters because a 1024×1024 depth map produces a million-point cloud - the naive version would be hopelessly slow.
How it works
For each point, the node counts its nearest neighbors and measures the distance to its k-th nearest neighbor. A point survives only if that k-th neighbor is close enough. Think of it as an isolation test: if the k points nearest to you are all farther than the distance threshold, you're an outlier - you get deleted. This is a standard "statistical outlier removal" technique, the same one used in MeshLab and Open3D's remove_statistical_outlier, just exposed as a node.
The inputs that matter
- points - the
Points3Dcloud. - k (0–32, default 20) - how many neighbors a point needs nearby to be considered "part of the crowd." Higher = stricter, because a point must have more close neighbors to survive. 20 is a reasonable middle ground.
- m (0–1024, default 16) - the maximum distance, in the cloud's own units, to that k-th neighbor. This is your threshold dial: lower
mdeletes more, highermkeeps more. The default 16 assumes a fairly dense cloud - if you're cleaning an already-sparse one, raise it or you'll gut the thing.
Output: Points3D - the cleaned cloud. Same format, ready to render, transform, or export.
Install
Pack-standard: Manager → "ComfyUI_depthMapOperation", or:
cd ComfyUI/custom_nodes
git clone https://github.com/chri002/ComfyUI_depthMapOperation
Restart. No models to download; the deps (torch, numpy, opencv-python, scipy, pandas) are already in a stock ComfyUI - scipy is what provides the KD-tree.
Where people get burned
The defaults assume a dense cloud, and that's where beginners get tripped up. Run a low-quality Image To Points (Torch) cloud through the default k=20/m=16 and it can delete half your points, because with sparse input even real points don't have 20 neighbors within 16 units. If the output comes back anemic, raise m before touching k.
One more edge case straight from the source: if k is bigger than the number of points in your cloud (or the cloud is empty), the node returns an empty cloud rather than an error - a silent wipe. Keep k comfortably below your point count. And as with the whole pack, single-frame clouds only; no batches.
Inputs (3)
| Name | Type | Default | Description |
|---|---|---|---|
| points | Points3D | — | |
| k | INT | 200–32 | — |
| m | FLOAT | 16.000–1024 | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| Points3D | Points3D | — |