CommunityImagegithub.com

krita-lineart-reconstruction

Reconstruct clean, native Krita lineart at native 1x resolution using G1 cubic Bezier fitting, Priority-Queue Recursive Cubic Bezier Subdivision, dual-regime Krita 6.0.4 brush pressure calibration, +0.58 px coordinate calibration, and closed-loop visual feedback. Strictly scoped to lineart only (no supersampling, no flat colouring, no shading or autonomous rendering).

What is krita-lineart-reconstruction?

krita-lineart-reconstruction is a Claude Code agent skill that reconstruct clean, native Krita lineart at native 1x resolution using G1 cubic Bezier fitting, Priority-Queue Recursive Cubic Bezier Subdivision, dual-regime Krita 6.0.4 brush pressure calibration, +0.58 px coordinate calibration, and closed-loop visual feedback. Strictly scoped to lineart only (no supersampling, no flat colouring, no shading or autonomous rendering).

Works with~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/ashdawgthegoat/krita-illustration-skills/tree/HEAD/skills/krita-lineart-reconstruction

Installed? Explore more Image skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

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 1x resolution only: Do not enable 2x supersampling or combined 2x + adaptive scaling. Both adaptive_subdivision.py and stroke_planner.py reject resolution_scale != 1 / supersample_factor != 1.
  • Lineart only: Outputs crisp #000000 ink on a dedicated Lineart paint 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 Gpen and b) Basic-5 Size for wide graphic fills) rather than importing rasterized overlays.

Core Pipeline Workflow

  1. 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.0 relative to Gaussian sigma = 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 (<= 4 iterations), splices collinear trajectories across degree >= 3 junctions (cos <= -0.68), refines centerlines to sub-pixel precision (refine_ridge_subpixel), and splits at sharp corners (> 72 deg) or 540 px max span.
  2. 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 of 128 points while maintaining tight tolerances on chord sagitta, tangent angle deflection, curvature-arc product, pressure taper fidelity, and straight chord length.
  3. 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 Gpen pressure curves (GPEN_THIN when brush_size <= 4.5 px; GPEN_STD when brush_size > 4.5 px) or b) Basic-5 Size tables defined in configs/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).
  4. Execution & Closed-Loop Visual Feedback (scripts/reconstruct_lineart.py, scripts/refinement.py):

    • Execute via KritaAdapter in dry_run (portable JSON batch export), http_bridge (POST /rpc), or krita_mcp_cli (krita-mcp --call) using batches of <= 32 strokes (strictly <= 64 per draw_brush call).
    • 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.
  5. 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.

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

Individual skills in this repo

This repo contains 1 individual skill — each has its own dedicated page.

Related Skills