skills/cv/connected-components-centroid-extraction/SKILL.md
Extracts object centers from 3D segmentation masks using connected-component labeling and centroid computation.
npx skillsauth add wenmin-wu/ds-skills cv-connected-components-centroid-extractionInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
After segmenting a 3D volume into a binary or multi-class mask, convert pixel-level predictions into discrete object detections. Connected-component labeling groups contiguous voxels, then each component's centroid gives the object's 3D coordinate. Essential for particle picking, cell detection, and nodule localization.
import cc3d
import numpy as np
def extract_centroids(segmentation, threshold=0.5):
binary = (segmentation > threshold).astype(np.uint8)
labels, n = cc3d.connected_components(binary, return_N=True)
centroids = []
for label_id in range(1, n + 1):
coords = np.argwhere(labels == label_id)
centroids.append(coords.mean(axis=0))
return np.array(centroids) # shape: (N, 3) — z, y, x
cc3d or scipy.ndimage.label)np.argwhere().mean()cc3d is 2-10x faster on large volumescc3d.connected_components with connectivity=26data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF