Krita Lineart Reconstruction Skill
Package and execute a validated, production-ready 1x native Krita lineart reconstruction pipeline from a raster reference illustration.
This skill is agent-agnostic: mathematical trajectory synthesis, topological skeleton tracing, calibration, and validation are strictly isolated from Krita RPC/MCP/CLI execution via scripts/krita_adapter.py.
Hard Production Scope Boundaries
- Native
1xresolution only: Do not enable2xsupersampling or combined2x + adaptivescaling. Bothadaptive_subdivision.pyandstroke_planner.pyrejectresolution_scale != 1/supersample_factor != 1. - Lineart only: Outputs crisp
#000000ink on a dedicatedLineartpaint layer (RGBA U8,300 dpi,sRGB-elle-V2-srgbtrc.icc). Does not perform flat colouring, shading, gradients, ambient occlusion, lighting stacks, or rendering. - Native Krita brushes only: Synthesizes strokes exclusively through calibrated brush presets (
d) Ink-3 Gpenandb) Basic-5 Sizefor wide graphic fills) rather than importing rasterized overlays.
Core Pipeline Workflow
-
Reference Analysis & Ink Extraction (
scripts/ink_analysis.py):- Two-tier thresholding captures solid dark ink (
inv > 42.0) and delicate low-contrast ridges (local_dark > 14.0 & inv > 18.0relative to Gaussiansigma = 4.0), plus optional bounding-box fine overrides (region_overrides) for dense tight gaps such as iris concentric rings. - Detects bold graphic black cores via Euclidean Distance Transform (
edt >= 2.8 px, area>= 20 px) and extracts iso-distance sweep contours (1.35 .. 16.20 px). - Skeletonizes remaining ink, prunes short quantization spurs (
<= 4iterations), splices collinear trajectories across degree>= 3junctions (cos <= -0.68), refines centerlines to sub-pixel precision (refine_ridge_subpixel), and splits at sharp corners (> 72 deg) or540 pxmax span.
- Two-tier thresholding captures solid dark ink (
-
Spline Fitting & Validated Adaptive Vertex Density (
scripts/bezier_core.py,scripts/adaptive_subdivision.py):- Fits G1-continuous piecewise cubic Bézier segments with least-squares optimal tangent handles.
- Refines chord sampling with Priority-Queue Recursive Cubic Bézier Subdivision (validated in Experiment 2 at
1x), capping vertices per stroke at Krita's hard limit of128points while maintaining tight tolerances on chord sagitta, tangent angle deflection, curvature-arc product, pressure taper fidelity, and straight chord length.
-
Krita 6.0.4 Brush & Coordinate Calibration (
scripts/pressure_calibration.py,scripts/stroke_planner.py):- Integrates optical line width along local normals with valley-stopping (
max_half = 4.8 px) to avoid neighboring-strand bloat. - Selects dual-regime Empirical
d) Ink-3 Gpenpressure curves (GPEN_THINwhenbrush_size <= 4.5 px;GPEN_STDwhenbrush_size > 4.5 px) orb) Basic-5 Sizetables defined inconfigs/pressure_tables_krita604.json. - Shifts both vertex samples and Bézier control points by
+0.58 px(PIXEL_CENTER_SHIFT) to align stroke dabs with Krita pixel centers, and orders strokes across Stages 1–6 (graphic cores -> outer silhouettes -> focal zones -> interior structure -> fine wisps).
- Integrates optical line width along local normals with valley-stopping (
-
Execution & Closed-Loop Visual Feedback (
scripts/reconstruct_lineart.py,scripts/refinement.py):- Execute via
KritaAdapterindry_run(portable JSON batch export),http_bridge(POST /rpc), orkrita_mcp_cli(krita-mcp --call) using batches of<= 32strokes (strictly<= 64perdraw_brushcall). - Export rendered canvas grayscale and optionally run
--feedback-canvas <png>(Stage 7) to synthesize targeted micro-strokes wherever reference strokes were missed (dist >= 1.35 px) or under-darkened.
- Execute via
-
Validation & Handoff (
scripts/validate_lineart.py):- Verify manifest schema limits, compute full-canvas & regional
SSIM,PSNR_dB,Contour_F1(1.5 px),Exact_Pixel_F1(0.5 px),Fine_Detail_Recall,Narrow_Gap_Preservation, and generate red/blue/dark-gray alignment diff PNGs. - Once lineart passes validation, hand off to
krita-flat-colouring.
- Verify manifest schema limits, compute full-canvas & regional
Quick CLI Invocation
Plan strokes offline, validate manifest bounds, and emit portable Krita MCP batch JSON:
python3 skills/krita-lineart-reconstruction/scripts/reconstruct_lineart.py \
--input path/to/reference.png \
--preset skills/krita-lineart-reconstruction/examples/sample_region_preset.json \
--output-manifest out/lineart_manifest.json \
--batch-dir out/batches \
--mode dry_run
Run live against an active Krita 6.0.4 session:
python3 skills/krita-lineart-reconstruction/scripts/reconstruct_lineart.py \
--input path/to/reference.png \
--output-manifest out/lineart_manifest.json \
--mode http_bridge \
--doc-name Character_Lineart
Reference Guides & Configs
references/architecture.md— Module layout and agent-agnostic isolation boundaries.references/bezier-and-sampling.md— G1 cubic Bézier fitting, Priority-Queue Recursive Subdivision vs. legacy sampler, and why supersampling is excluded.references/calibration.md—+0.58 pxcoordinate calibration and dual-regimeInk-3 Gpen/Basic-5 Sizetables.references/krita-interface.md— Krita 6.0.4 native bridge protocol, hard schema caps, and error handling.references/validation.md— Fidelity metrics, closed-loop residual feedback, and pass criteria.references/troubleshooting.md— Diagnosing missing details, vertex clipping, and bridge errors.configs/default_config.json&configs/pressure_tables_krita604.jsonexamples/workflow_example.md