source-part-segmentation

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

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.
当源图像包含重叠或相互接触的设计部件时,请在
contour-to-mesh
之前使用此方法。 其输出并非"美观的掩码",而是下游几何流程必须遵循的真值部件清单。

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.
  • 源图像、线框、贴花或纹理图集;
  • 可选的手动种子清单,包含命名部件、多边形、种子点、粗略矩形或HSV/颜色范围;
  • 源清单,包含结构/装饰/上下文分类以及预期的部件数量。

Workflow

工作流程

  1. Choose the cleanest modality: alpha, edge, dark-line, bright-on-dark, color-band, or atlas region.
  2. Extract contours and hierarchy to identify candidate objects, holes, nested details, and strokes.
  3. If components touch, run distance-transform marker watershed first.
  4. 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.
  5. Classify masks as
    structural
    ,
    decorative
    ,
    face_feature
    ,
    aura_context
    , or
    validation_only
    .
  6. Pass structural masks to
    contour-to-mesh
    ; pass feature masks/landmarks to
    landmark-fit-repair
    ; pass atlas regions to
    atlas-uv-fitting
    .
  1. 选择最清晰的模态:alpha通道、边缘、暗线、暗底亮纹、色带或图集区域。
  2. 提取轮廓和层级结构,以识别候选对象、孔洞、嵌套细节和笔触。
  3. 如果组件相互接触,首先运行距离变换标记分水岭算法。
  4. 如果分水岭算法出现过分割或欠分割,切换为种子分割:
    • 创建命名部件种子(
      bbox
      、
      polygon
      或
      seed_point
      + 可选的泛洪/HSV容差);
    • 每个命名的结构部件保存为一个掩码;
    • 明确标记模糊的重叠区域,而非将其合并。
  5. 将掩码分类为
    structural
    、
    decorative
    、
    face_feature
    、
    aura_context
    或
    validation_only
    。
  6. 将结构掩码传入
    contour-to-mesh
    ;将特征掩码/地标传入
    landmark-fit-repair
    ;将图集区域传入
    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

种子清单模式

json
{
  "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
.
json
{
  "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"}
  ]
}
允许的
mode
值:
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.
  • scripts/segment_source_parts.py
    :从图像生成组件掩码和JSON报告,支持可选的分水岭算法。
  • scripts/seeded_part_masks.py
    :将命名种子清单转换为确定性的命名掩码和部件清单。

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.
  • OpenCV的轮廓/层级/矩是基础测量层。
  • OpenCV距离变换 + 标记分水岭是处理接触组件的首选自动分割方法。
  • 活动轮廓细化可在分割后优化粗略的掩码边界。