Character Images to SVG Assets: Layers, Segmentation and Checks
Character Images to SVG Assets: Layers, Segmentation and Checks
Search
Ask the AI

Character Images to SVG Assets: Layers, Segmentation and Checks

Preparing assets for 2D animation starts with 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:

  1. Decode the image locally with Canvas.
  2. Run edge-preserving upscaling to keep cel-style hard edges readable.
  3. Use RGB color clustering to approximate character segmentation.
  4. Merge tiny components into spatially adjacent regions with the nearest color.
  5. Export transparent PNG files for each layer.
  6. Trace closed contours with a small seam overlap, then write SVG paths.
  7. Write a manifest.json file with dimensions, colors, layer area, and segment counts.

The browser version clusters colours and exports layers. It suits simple backgrounds and distinct colour regions. One colour layer may contain several body parts. Complex backgrounds, translucent hair and occlusion require semantic segmentation, matting or repainting as appropriate. SAM supplies prompted segmentation masks; inspect each part before using it.

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 offline workflow uses the following steps:

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 Image conditioning with IP-Adapter

IP-Adapter encodes reference images as image conditions to guide appearance. Compare hair, eyes, ears, accessories and clothing against the reference after generation. Conditioning does not guarantee identical character details across sheets. The word “lock” in the original diagram below describes that intended outcome.

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 conditions and part layout

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.

Use the layout reference to plan the sheet. OpenPose ControlNet conditions generation on a human pose; a skeleton image alone does not guarantee separated, riggable parts. A part sheet also needs layout constraints, occlusion checks and, where necessary, repainting. Check which bitmap and pose condition the workflow actually reads.

3.3 Semantic segmentation with Grounding DINO + SAM

Grounding DINO locates candidate boxes from prompts such as left arm, wolf head and headband; SAM then predicts masks from those boxes. The supplied script selects the highest-scoring box for each prompt, converts its SAM mask to a Boolean selection and copies the original pixels. It neither estimates fractional edge alpha nor reconstructs occluded anatomy.

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

With vtracer installed, the script can convert transparent PNGs to SVG paths and attach stable part IDs. Without it, PNG output remains available. Inspect small paths and edges after conversion:

<g id="left-arm">...</g>
<g id="right-arm">...</g>
<g id="wolf-head">...</g>

Stable IDs let scripts and runtimes locate the arms, head and accessories. A rig can also use object indices or another resource map. Export, binding and playback need a consistent mapping between identifiers and parts.

4. Compare resizing and vectorisation choices

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.

Before vectorisation, compare the original image with edge-preserving resampling and any super-resolution output. The browser version uses lightweight enlargement and sharpening. A generative upscaler such as Real-ESRGAN may add details absent from the source; inspect outlines, line art and character features afterwards. Enlargement cannot recover occluded content.

5. How to review the generated asset pack

Check whether the parts support the intended animation:

  • 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. If joints still show white dots, inspect shared geometry, transparent-pixel RGB, and skinning weights instead of only adding a stroke.

Review assets against the intended animation

Three computable measures can supplement the checklist above when checking whether an asset pack is suitable for animation.

First, is the joint actually cut apart? This is the most damaging failure and the easiest to miss. Vectorisation splits along colour boundaries, and at elbows, shoulders and knees the two parts are usually the same colour (one sleeve), so the resulting boundary can land anywhere across the joint — or merge upper arm and forearm into a single piece.

For rigid cut-out animation, create independently rotatable parts at the intended joints and set their pivots and drawing order. Both endpoints of a bone can lie in one part. A continuous mesh can also bend through weights from multiple bones. Bounding boxes help locate parts but cannot establish whether a joint was split correctly.

Overlapping rigid parts can cover regions exposed during rotation. The required overlap depends on contours, pivots, angles and drawing order. The original 15% is an illustrative tuning value, not an acceptance standard. Check gaps and double edges across the poses used in the animation.

Second, has path complexity run away? Vectorisation quality cannot be judged visually alone, because noise-generated path fragments are invisible in a thumbnail while making both runtime performance and later editing painful.

Node count divided by contour length can compare complexity at a fixed resolution and tracing configuration. The original one-node-per-20–40-pixels and one-per-3–5-pixels examples, including 0.025–0.05 and 0.2 in the code below, are tuning examples. Scaling changes density per pixel; curvature and fitting error also affect the required count. Evaluate geometric error before adjusting tracing settings or simplifying paths.

density = node_count / path_length_px
# healthy 0.025 to 0.05    noisy > 0.2

Layer areas can reveal fragmentation when compared with the intended part layout. Keep the original “three largest layers exceed 60%” as a trial condition for a particular asset, rather than a general criterion. Characters with many limbs, expression layers or accessories can have different distributions. A large colour cluster need not represent one semantic part.

Why these checks belong before rigging

A future tool version could check joint coverage, path complexity and area distribution. The current browser manifest records dimensions, clustering parameters, layer pixel counts and connected components; the offline manifest records prompts, detection scores and boxes. Neither version automatically performs all three acceptance checks.

When a part fails to follow a bone, inspect the binding, pivot, weights and part boundaries. When editing stutters or the SVG grows large, inspect path counts and vectorisation settings. A symptom alone does not identify the faulty stage.

Checking joint contours and part identifiers before binding can reduce later rework. Whether regenerated assets preserve weights and keyframes depends on topology, IDs and the binding map.

Store any added acceptance measures in manifest.json with their method, resolution and threshold source, so the next person can repeat the checks.

6. Where this fits in the 2D animation column

This is the asset-preparation stage of the 2D animation series. The following articles cover anchors, parent-child transforms, bones, keyframes, interpolation and masks. Each stage needs assets suited to its binding method.

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, then continue with the 2D Animation Principles series for bones, IK, skinning, and keyframes.

Leave a Reply

Scroll down