Source Part Segmentation
Use this before contour-to-mesh when a source image contains overlapping or touching designed parts.
The output is not “nice masks”; it is a source-of-truth part inventory that downstream geometry must obey.
Inputs
- source image, wireframe, decal, or texture atlas;
- optional manual seed manifest with named parts, polygons, seed points, rough rectangles, or HSV/color ranges;
- source manifest with structural/decorative/context classification and expected part count.
Workflow
- Choose the cleanest modality: alpha, edge, dark-line, bright-on-dark, color-band, or atlas region.
- Extract contours and hierarchy to identify candidate objects, holes, nested details, and strokes.
- If components touch, run distance-transform marker watershed first.
- If watershed over/under-splits, switch to seeded segmentation:
- create named part seeds (
bbox, polygon, or seed_point + optional flood/HSV tolerance);
- save one mask per named structural part;
- mark ambiguous overlaps explicitly instead of merging them.
- Classify masks as
structural, decorative, face_feature, aura_context, or validation_only.
- Pass structural masks to
contour-to-mesh; pass feature masks/landmarks to landmark-fit-repair; pass atlas regions to atlas-uv-fitting.
Hard rules
- Do not infer repeated parts from symmetry; segment what the source shows.
- Do not merge overlapping components if the manifest expects separate structural meshes.
- Do not proceed to final modeling when part count differs between source images; write a conflict report or canonical policy.
- If automatic segmentation is ambiguous, write an ambiguity report and require or create manual seed rectangles/points.
- Keep stroke/line masks separate from filled-part masks; wireframe strokes are guides unless explicitly used as the contour boundary.
Seed manifest schema
{
"schema": "source_part_seed_manifest.v1",
"image": "path/to/source.png",
"parts": [
{"name":"leaf_top", "class":"structural", "bbox":[x,y,w,h], "mode":"non_background"},
{"name":"face_shell", "class":"structural", "polygon":[[x,y],[x,y],...], "mode":"polygon"}
]
}
Allowed mode values: polygon, bbox, non_background, dark_lines, bright_on_dark, hsv_range.
Scripts
scripts/segment_source_parts.py produces component masks and a JSON report from an image, with optional watershed.
scripts/seeded_part_masks.py converts a named seed manifest into deterministic named masks and a part inventory.
Sources distilled
- OpenCV contours/hierarchy/moments are the base measurement layer.
- OpenCV distance transform + marker watershed is the first automated split method for touching components.
- Active contour refinement can improve a rough mask boundary after segmentation.
1---2name: source-part-segmentation3description: Segment overlapping visual parts from source images, wireframes, texture atlases, and decals before mesh reconstruction. Use when a mascot/logo/template contains touching or overlapping components and exact structural part masks are needed before contour-to-mesh, UV fitting, or landmark repair.4---5
6# Source Part Segmentation
7
8Use this before `contour-to-mesh` when a source image contains overlapping or touching designed parts.
9The output is not “nice masks”; it is a **source-of-truth part inventory** that downstream geometry must obey.
10
11## Inputs
12
13- source image, wireframe, decal, or texture atlas;
14- optional manual seed manifest with named parts, polygons, seed points, rough rectangles, or HSV/color ranges;
15- source manifest with structural/decorative/context classification and expected part count.
16
17## Workflow
18
191. Choose the cleanest modality: alpha, edge, dark-line, bright-on-dark, color-band, or atlas region.
202. Extract contours and hierarchy to identify candidate objects, holes, nested details, and strokes.
213. If components touch, run distance-transform marker watershed first.
224. If watershed over/under-splits, switch to **seeded segmentation**:
23 - create named part seeds (`bbox`, `polygon`, or `seed_point` + optional flood/HSV tolerance);
24 - save one mask per named structural part;
25 - mark ambiguous overlaps explicitly instead of merging them.
265. Classify masks as `structural`, `decorative`, `face_feature`, `aura_context`, or `validation_only`.
276. Pass structural masks to `contour-to-mesh`; pass feature masks/landmarks to `landmark-fit-repair`; pass atlas regions to `atlas-uv-fitting`.
28
29## Hard rules
30
31- Do not infer repeated parts from symmetry; segment what the source shows.
32- Do not merge overlapping components if the manifest expects separate structural meshes.
33- Do not proceed to final modeling when part count differs between source images; write a conflict report or canonical policy.
34- If automatic segmentation is ambiguous, write an ambiguity report and require or create manual seed rectangles/points.
35- Keep stroke/line masks separate from filled-part masks; wireframe strokes are guides unless explicitly used as the contour boundary.
36
37## Seed manifest schema
38
39```json
40{
41 "schema": "source_part_seed_manifest.v1",
42 "image": "path/to/source.png",
43 "parts": [
44 {"name":"leaf_top", "class":"structural", "bbox":[x,y,w,h], "mode":"non_background"},
45 {"name":"face_shell", "class":"structural", "polygon":[[x,y],[x,y],...], "mode":"polygon"}
46 ]
47}
48```
49
50Allowed `mode` values: `polygon`, `bbox`, `non_background`, `dark_lines`, `bright_on_dark`, `hsv_range`.
51
52## Scripts
53
54- `scripts/segment_source_parts.py` produces component masks and a JSON report from an image, with optional watershed.
55- `scripts/seeded_part_masks.py` converts a named seed manifest into deterministic named masks and a part inventory.
56
57## Sources distilled
58
59- OpenCV contours/hierarchy/moments are the base measurement layer.
60- OpenCV distance transform + marker watershed is the first automated split method for touching components.
61- Active contour refinement can improve a rough mask boundary after segmentation.