English
Character Image to SVG Animation Asset Pipeline: ComfyUI, Grounded-SAM, OpenPose, and vtracer
The first step in 2D animation is not interpolation or rigging. It is asset preparation: turning one flat character image into separate layers that can move, be corrected, and be exported independently. If a character remains a single raster image, later keyframes, skeletal rigs, and expression swaps become hard to control.
That is why I added a browser-side tool to the site: Animation Asset Lab. It converts a local character or anime image into SVG, layered PNG files, and an asset manifest. Processing happens in the browser only. The file is not uploaded and the server does not store the result.
1. Why segmentation comes first
The goal is to change a flat character picture into an editable structure. Typical layers include hair, face, eyes, clothes, arms, legs, shadows, and highlights. Once those layers exist, an animation system can assign anchors, rotation centers, masks, and keyframes.
Mathematically, the image can be treated as a pixel function:
I(x, y) = [R, G, B, A]
Segmentation assigns each pixel to a layer label:
L(x, y) in {0, 1, 2, ..., K - 1}
Ideally, one piece of hair or clothing lands in one label, while adjacent but semantically different regions are separated. That label map becomes the base for SVG vectorization, PNG layer export, and animation rigging.
2. The local browser pipeline
The first website version does not call a cloud AI model or load a huge browser model. It uses a lightweight local pipeline:
- Decode the image locally with Canvas.
- Run edge-preserving upscaling to keep cel-style hard edges readable.
- Use RGB color clustering to approximate character segmentation.
- Filter tiny connected components.
- Export transparent PNG files for each layer.
- Convert horizontal pixel runs into SVG paths.
- Write a
manifest.jsonfile with dimensions, colors, layer area, and segment counts.
This is not a replacement for SAM. It is a fast draft tool that avoids server compute and server storage. It works best with clean character art, transparent backgrounds, hard line art, and cel shading. For complex backgrounds, translucent hair, gradients, or real photos, the offline SAM workflow is more reliable.
3. Production local pipeline: ComfyUI + Grounded-SAM + vtracer
For cleaner production assets, run the heavier pipeline on your own machine rather than uploading private images to the website. The basic script is sam_vtracer_pipeline.py; the complete production coordinator is comfyui_grounded_sam_vtracer_pipeline.py.
The production workflow has three layers:
Multi-view character references
-> ComfyUI: IP-Adapter locks character identity
-> ComfyUI: ControlNet OpenPose forces an exploded layout
-> Grounded-SAM: text prompts cut semantic parts
-> vtracer: transparent PNG parts become SVG paths
-> Python: stable IDs are injected into character-rig-layered.svg
3.1 Character identity lock: IP-Adapter
IP-Adapter is not just a loose style reference. It encodes front views, side views, outfit details, and close-ups as image conditions. For animation assets, this solves character consistency: hair color, eye color, ears, scars, accessories, and clothing silhouettes should remain the same across generated sheets.
The downloadable comfyui_exploded_character_workflow.template.json uses placeholders so the script can upload local reference images to local ComfyUI and replace __REFERENCE_IMAGE_1__. Node names differ across ComfyUI custom-node installations, so this is an editable API workflow template rather than a hosted service.
3.2 Pose stripping: OpenPose exploded view
Normal character illustrations often place an arm across the torso, hair over the shoulder, or a weapon in front of the legs. Those images may look good, but they are poor rigging assets. The goal of exploded layout is to keep head, torso, left arm, right arm, legs, tail, and accessories separated.
I added an exploded OpenPose skeleton reference. Export it to PNG if your ControlNet workflow expects a bitmap, then feed it into OpenPose ControlNet. ComfyUI should generate a flat-background character part sheet rather than a single overlapping full-body pose.
3.3 Semantic matting: Grounding DINO + SAM
Coordinate cropping is fragile because each seed changes exact positions and proportions. Grounded-SAM is better for automation: Grounding DINO locates text prompts such as left arm, wolf head, and headband; SAM converts each detected box into a precise alpha mask.
The downloadable part_prompts.example.json provides a default part list. The script writes a transparent PNG for each part and records the prompt, score, and bounding box in the manifest.
3.4 SVG assembly: stable IDs and rig assets
vtracer converts each transparent part PNG into clean SVG paths. Python then combines those paths into one SVG and wraps each part with a stable ID:
<g id="left-arm">...</g>
<g id="right-arm">...</g>
<g id="wolf-head">...</g>
This step matters. Without stable IDs, animation software or a browser runtime cannot reliably find the left arm, right arm, head, and accessories. With stable IDs, the next articles can build anchors, parent-child layers, rigs, and keyframes on top of those parts.
4. Why upscaling belongs before vectorization
Low-resolution anime images often show jagged edges, broken line art, and mixed colors after scaling. A vectorizer sees those artifacts as real boundaries and may create many short paths, which makes the SVG larger and dirtier.
Upscaling or edge-preserving resampling should happen before vectorization. The goal is not to invent detail. The goal is to stabilize contours and make same-color regions more coherent. The browser tool uses a light hard-edge upsample and sharpening step. A heavier local workflow can replace that with an anime-focused upscaler such as a local Real-ESRGAN anime model.
5. How to review the generated asset pack
After generating assets, do not only ask whether the SVG looks attractive. Ask whether it can animate:
- Are hair, face, clothes, and arms separated into usable layers?
- Is the SVG too large or too fragmented?
- Do layer PNG files preserve transparency?
- Do the manifest area and segment counts look reasonable?
- Can you identify anchor points for later rigging?
If the result is too fragmented, raise the detail threshold or reduce the target layer count. If character structures are mixed together, segment with SAM locally first and then vectorize each mask with vtracer.
6. Where this fits in the 2D animation column
This is the first step in the 2D animation principles column: asset generation. The next steps can cover anchors, parent-child layers, skeletal rigs, keyframes, easing curves, interpolation, masks, and camera movement. Those topics need clean assets first.
Use the tool here: Animation Asset Lab. It is best for quickly checking whether a character image can be separated into layers. For finished work, combine the offline script, manual cleanup, and animation software.
Chinese
人物图片转 SVG 动画资产管线:ComfyUI、Grounded-SAM、OpenPose 与 vtracer
Open as a full page2D 动画制作的第一步不是直接补间,也不是马上画骨骼,而是先把角色拆成可以独立移动、独立修正、独立导出的资产层。一个人物图片如果仍然是单张像素图,后续无论用关键帧、骨骼还是表情替换,都会很难控制局部运动。
因此我在实用功能页加入了一个浏览器端工具:动画资产生成器。它把输入的人物或动漫角色图片转成 SVG、分层 PNG 和资产清单。处理过程只在浏览器里发生,不上传文件,也不占用服务器存储。
一、为什么先做分割与分层
动画资产的核心目标是把“整张角色图”改造成“可操作的结构”。常见图层包括头发、脸、眼睛、衣服、手臂、腿、阴影和高光。分层之后,动画系统才能对每一层设置锚点、旋转中心、遮罩关系和关键帧。
如果用数学方式描述,原图可以看成像素函数:
I(x, y) = [R, G, B, A]
分割的目标是给每个像素分配一个图层标签:
L(x, y) in {0, 1, 2, ..., K - 1}
理想情况下,同一块头发或衣服应该落在同一个标签里,相邻但语义不同的区域应该分开。这个标签图就是后续 SVG 矢量化、PNG 图层导出和动画绑定的基础。
二、浏览器工具采用的本地管线
网站上的第一版工具不调用云端 AI,也不加载大型模型。它使用的是轻量浏览器管线:
- 用 Canvas 在本地解码图片。
- 进行边缘保留上采样,尽量保留动漫赛璐璐硬边。
- 用 RGB 颜色聚类近似分割角色区域。
- 用连通域过滤去掉太小的碎片。
- 为每个图层生成透明 PNG。
- 把每个图层的水平像素 run 写成 SVG path。
- 导出
manifest.json,记录尺寸、颜色、图层面积和分块数量。
这不是 SAM 的替代品,而是一个不消耗服务器算力的快速草稿工具。它适合干净角色图、透明背景、硬边线稿和赛璐璐上色。对于复杂背景、半透明发丝、渐变阴影或真实照片,离线 SAM 管线更可靠。
三、生产级离线管线:ComfyUI + Grounded-SAM + vtracer
如果要获得更接近生产资产的结果,推荐在本机跑离线脚本,而不是把图片上传到服务器。基础脚本是 sam_vtracer_pipeline.py;更完整的生产脚本是 comfyui_grounded_sam_vtracer_pipeline.py。
生产级流程可以拆成三层:
多角度角色参考图
-> ComfyUI: IP-Adapter 锁定角色特征
-> ComfyUI: ControlNet OpenPose 强制拆件排版
-> Grounded-SAM: 用文本 prompt 抠出语义部件
-> vtracer: 透明 PNG 部件转 SVG
-> Python: 注入稳定 id,合并为 character-rig-layered.svg
3.1 角色特征锁定:IP-Adapter
IP-Adapter 的作用不是简单“参考风格”,而是把正脸、侧脸、服饰细节和局部特写编码成图像条件。对于动画资产,它解决的是角色一致性问题:发色、瞳孔、耳朵形状、刀疤、饰品和服装轮廓应该在每张生成图里保持同一套视觉身份。
离线模板 comfyui_exploded_character_workflow.template.json 使用占位符,让脚本把参考图上传到本机 ComfyUI 后替换为 __REFERENCE_IMAGE_1__。实际节点名会因 ComfyUI 插件版本不同而变化,所以模板是可编辑的 API 工作流,而不是服务器端固定服务。
3.2 姿态剥离:OpenPose Exploded View
传统立绘经常有手臂压住胸口、头发盖住肩膀、武器挡住腿的问题。这样的图即使画得漂亮,也不适合作为可绑定资产。拆件排版的目标是让头、躯干、左臂、右臂、腿、尾巴和饰品互不遮挡。
我放了一个 拆件 OpenPose 骨架参考图。你可以把它导出成 PNG,然后喂给 ControlNet OpenPose。这样 ComfyUI 生成的不是“完整站姿角色”,而是一张纯色背景上的“散装角色部件板”。
3.3 语义级抠图:Grounding DINO + SAM
坐标裁剪不可靠,因为生成图里的部件大小和位置会随 seed 变化。Grounded-SAM 更适合自动化:Grounding DINO 先根据文本找框,例如 left arm、wolf head、headband;SAM 再把框内真实轮廓变成 alpha mask。
下载的 part_prompts.example.json 给出了默认部件清单。脚本会为每个部件输出透明 PNG,并在 manifest 中记录文本 prompt、检测分数和边界框。
3.4 SVG 装配:稳定 ID 与骨骼资产库
vtracer 负责把每个透明 PNG 部件转成干净 SVG path。最后 Python 会把这些路径合并进一个 SVG,并给每个组写入稳定 ID:
<g id="left-arm">...</g>
<g id="right-arm">...</g>
<g id="wolf-head">...</g>
这一步非常关键。没有稳定 ID,后续动画软件或网页运行时就无法可靠地找到左臂、右臂、头部和饰品;有了稳定 ID,才可以继续写锚点、父子层级、骨骼绑定和关键帧。
四、超分辨率为什么放在矢量化前
很多动漫图像在缩放后会出现锯齿、断线和颜色混合。矢量化算法看到这些噪声后,会生成大量短路径,导致 SVG 变大、边缘变脏。
所以超分辨率或边缘保留上采样应该放在矢量化之前。目标不是凭空生成细节,而是让轮廓更稳定,让同色区域更连贯。浏览器工具采用轻量的硬边上采样和锐化;离线工作流可以替换成本机 anime upscaler,例如 Real-ESRGAN 动漫模型或其他本地超分工具。
五、资产包应该怎样复核
生成资产后,不要只看 SVG 是否好看。更重要的是检查它是否适合动画:
- 头发、脸、衣服和手臂是否被拆成可操作层。
- SVG 是否过大,是否包含过多碎片。
- 图层 PNG 是否保留透明背景。
- manifest 中的面积和分块数量是否合理。
- 后续绑定时是否能找到旋转锚点。
如果图层过碎,可以提高细节阈值或减少目标图层数。如果角色结构混在一起,可以先用离线 SAM 分割,再用 vtracer 单独矢量化每个 mask。
六、这篇文章在 2D 动画专栏中的位置
这篇是 2D 动画原理专栏的第一步:资产生成。后续可以继续写锚点、父子层级、骨骼绑定、关键帧、缓动曲线、补间、遮罩和镜头运动。只有先把角色拆成干净资产,后面的动画原理才有落地对象。
直接使用入口:动画资产生成器。它适合在浏览器里快速验证一个角色图是否能拆层;真正要做作品时,再把离线脚本、人工修图和动画软件结合起来。
The first step in 2D animation is not interpolation or rigging. It is asset preparation: turning one flat character image into separate layers that can move, be corrected, and be exported independently. If a character remains a single raster image, later keyframes, skeletal rigs, and expression swaps become hard to control.
That is why I added a browser-side tool to the site: Animation Asset Lab. It converts a local character or anime image into SVG, layered PNG files, and an asset manifest. Processing happens in the browser only. The file is not uploaded and the server does not store the result.
1. Why segmentation comes first
The goal is to change a flat character picture into an editable structure. Typical layers include hair, face, eyes, clothes, arms, legs, shadows, and highlights. Once those layers exist, an animation system can assign anchors, rotation centers, masks, and keyframes.
Mathematically, the image can be treated as a pixel function:
I(x, y) = [R, G, B, A]
Segmentation assigns each pixel to a layer label:
L(x, y) in {0, 1, 2, ..., K - 1}
Ideally, one piece of hair or clothing lands in one label, while adjacent but semantically different regions are separated. That label map becomes the base for SVG vectorization, PNG layer export, and animation rigging.
2. The local browser pipeline
The first website version does not call a cloud AI model or load a huge browser model. It uses a lightweight local pipeline:
- Decode the image locally with Canvas.
- Run edge-preserving upscaling to keep cel-style hard edges readable.
- Use RGB color clustering to approximate character segmentation.
- Filter tiny connected components.
- Export transparent PNG files for each layer.
- Convert horizontal pixel runs into SVG paths.
- Write a
manifest.jsonfile with dimensions, colors, layer area, and segment counts.
This is not a replacement for SAM. It is a fast draft tool that avoids server compute and server storage. It works best with clean character art, transparent backgrounds, hard line art, and cel shading. For complex backgrounds, translucent hair, gradients, or real photos, the offline SAM workflow is more reliable.
3. Production local pipeline: ComfyUI + Grounded-SAM + vtracer
For cleaner production assets, run the heavier pipeline on your own machine rather than uploading private images to the website. The basic script is sam_vtracer_pipeline.py; the complete production coordinator is comfyui_grounded_sam_vtracer_pipeline.py.
The production workflow has three layers:
Multi-view character references
-> ComfyUI: IP-Adapter locks character identity
-> ComfyUI: ControlNet OpenPose forces an exploded layout
-> Grounded-SAM: text prompts cut semantic parts
-> vtracer: transparent PNG parts become SVG paths
-> Python: stable IDs are injected into character-rig-layered.svg
3.1 Character identity lock: IP-Adapter
IP-Adapter is not just a loose style reference. It encodes front views, side views, outfit details, and close-ups as image conditions. For animation assets, this solves character consistency: hair color, eye color, ears, scars, accessories, and clothing silhouettes should remain the same across generated sheets.
The downloadable comfyui_exploded_character_workflow.template.json uses placeholders so the script can upload local reference images to local ComfyUI and replace __REFERENCE_IMAGE_1__. Node names differ across ComfyUI custom-node installations, so this is an editable API workflow template rather than a hosted service.
3.2 Pose stripping: OpenPose exploded view
Normal character illustrations often place an arm across the torso, hair over the shoulder, or a weapon in front of the legs. Those images may look good, but they are poor rigging assets. The goal of exploded layout is to keep head, torso, left arm, right arm, legs, tail, and accessories separated.
I added an exploded OpenPose skeleton reference. Export it to PNG if your ControlNet workflow expects a bitmap, then feed it into OpenPose ControlNet. ComfyUI should generate a flat-background character part sheet rather than a single overlapping full-body pose.
3.3 Semantic matting: Grounding DINO + SAM
Coordinate cropping is fragile because each seed changes exact positions and proportions. Grounded-SAM is better for automation: Grounding DINO locates text prompts such as left arm, wolf head, and headband; SAM converts each detected box into a precise alpha mask.
The downloadable part_prompts.example.json provides a default part list. The script writes a transparent PNG for each part and records the prompt, score, and bounding box in the manifest.
3.4 SVG assembly: stable IDs and rig assets
vtracer converts each transparent part PNG into clean SVG paths. Python then combines those paths into one SVG and wraps each part with a stable ID:
<g id="left-arm">...</g>
<g id="right-arm">...</g>
<g id="wolf-head">...</g>
This step matters. Without stable IDs, animation software or a browser runtime cannot reliably find the left arm, right arm, head, and accessories. With stable IDs, the next articles can build anchors, parent-child layers, rigs, and keyframes on top of those parts.
4. Why upscaling belongs before vectorization
Low-resolution anime images often show jagged edges, broken line art, and mixed colors after scaling. A vectorizer sees those artifacts as real boundaries and may create many short paths, which makes the SVG larger and dirtier.
Upscaling or edge-preserving resampling should happen before vectorization. The goal is not to invent detail. The goal is to stabilize contours and make same-color regions more coherent. The browser tool uses a light hard-edge upsample and sharpening step. A heavier local workflow can replace that with an anime-focused upscaler such as a local Real-ESRGAN anime model.
5. How to review the generated asset pack
After generating assets, do not only ask whether the SVG looks attractive. Ask whether it can animate:
- Are hair, face, clothes, and arms separated into usable layers?
- Is the SVG too large or too fragmented?
- Do layer PNG files preserve transparency?
- Do the manifest area and segment counts look reasonable?
- Can you identify anchor points for later rigging?
If the result is too fragmented, raise the detail threshold or reduce the target layer count. If character structures are mixed together, segment with SAM locally first and then vectorize each mask with vtracer.
6. Where this fits in the 2D animation column
This is the first step in the 2D animation principles column: asset generation. The next steps can cover anchors, parent-child layers, skeletal rigs, keyframes, easing curves, interpolation, masks, and camera movement. Those topics need clean assets first.
Use the tool here: Animation Asset Lab. It is best for quickly checking whether a character image can be separated into layers. For finished work, combine the offline script, manual cleanup, and animation software.
Search questions
FAQ
Who is this article for?
This article is for readers who want a practice-level guide to Character Image to SVG Animation Asset Pipeline: ComfyUI, Grounded-SAM, OpenPose, and vtracer. It takes about 14 min and focuses on ComfyUI, IP-Adapter, OpenPose, Grounded-SAM.
What should I read next?
Use the related tutorials and project links below the article to continue through the closest topic hub.
Does this article include runnable code or companion resources?
Yes. Use the run notes, resource cards, and download links on the page to reproduce the example or inspect the companion files.
Can I try this concept in the browser playground?
Yes. The algorithm playground and knowledge map give you a faster way to inspect state changes after reading the explanation.
Article context
Algorithm Implementation Project
Implementation-focused notes around backtracking, bit operations, clustering, code, diagrams, and downloads.
Your next step
Open resourceThe first article in the 2D animation principles column: use ComfyUI IP-Adapter, OpenPose exploded layout, Grounded-SAM matting, and vtracer to build rig assets.
Open share centerCompanion resources
Algorithm Implementation Project / SOURCE
Basic SAM + vtracer script
Local reference script for character segmentation, PNG layers, and SVG vectorization.
Algorithm Implementation Project / SOURCE
ComfyUI + Grounded-SAM production script
Coordinates local ComfyUI, Grounding DINO, SAM, and vtracer to build SVG rig assets with stable IDs.
Algorithm Implementation Project / GUIDE
ComfyUI exploded character workflow template
Editable API workflow template for IP-Adapter identity locking and ControlNet OpenPose exploded layout.
Algorithm Implementation Project / DIAGRAM
Exploded OpenPose skeleton
Layout reference for separated head, torso, arms, and legs; export to PNG for ControlNet if needed.
Algorithm Implementation Project / DATASET
Animation part prompt list
Grounding DINO prompts for semantic matting: head, left arm, torso, tail, accessory, and more.
Project timeline
Published posts
- Character Image to SVG Animation Asset Pipeline: ComfyUI, Grounded-SAM, OpenPose, and vtracer The first article in the 2D animation principles column: use ComfyUI IP-Adapter, OpenPose exploded layout, Grounded-SAM matting, and vtracer to build rig assets.
Published resources
- Iris.csv dataset The 150-sample Iris dataset used by the K-means article.
- Iris_sort_K_mean.c source Includes standardization, K-means++ initialization, restarts, and SSE selection.
- K-means flowchart SVG flowchart for the C program execution path.
- Cluster visualization A 2D scatter projection using petal length and petal width.
- K-means zip package Contains dataset, source code, flowchart, and visualization.
- Gaoshu Lianxi PDF A public advanced calculus practice PDF for review or printing.
- Basic SAM + vtracer script Local reference script for character segmentation, PNG layers, and SVG vectorization.
- ComfyUI + Grounded-SAM production script Coordinates local ComfyUI, Grounding DINO, SAM, and vtracer to build SVG rig assets with stable IDs.
- ComfyUI exploded character workflow template Editable API workflow template for IP-Adapter identity locking and ControlNet OpenPose exploded layout.
- Exploded OpenPose skeleton Layout reference for separated head, torso, arms, and legs; export to PNG for ControlNet if needed.
- Animation part prompt list Grounding DINO prompts for semantic matting: head, left arm, torso, tail, accessory, and more.
- Algorithm Visualization share card A 1200x630 SVG card for eight queens, backtracking, bitmasks, and the playground.
- K-means iteration animation A Remotion clip showing sample assignment, centroid updates, and SSE reduction.
- Eight queens backtracking animation A Remotion clip showing row-by-row search, conflict pruning, and backtracking.
Current route
- Eight queens with classic backtracking Learning path step
- Bitwise optimization for the eight queens problem Learning path step
- K-means clustering on the Iris dataset in C Learning path step
- K-means companion downloads Learning path step
Next notes
- Add more runnable algorithm examples
- Expand downloadable example inputs
