Documentation
¶
Overview ¶
Package rekha traces raster images into SVG.
Index ¶
Constants ¶
const ( TurnMinority = contour.Minority TurnMajority = contour.Majority TurnBlack = contour.Black TurnWhite = contour.White )
Turn policies.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Hierarchical ¶
type Hierarchical string
Hierarchical selects how colour shapes are layered in the output.
const ( // HierarchicalStacked paints every shape's outer contour, larger and // deeper shapes first, so each one covers what it encloses: no holes, // no seams between abutting colours. HierarchicalStacked Hierarchical = "stacked" // HierarchicalCutout paints each shape with its holes cut out, as // Phase 1 does for black on white. HierarchicalCutout Hierarchical = "cutout" )
Layering modes.
type Options ¶
type Options struct {
Preset Preset
Mode Mode
FilterSpeckle int // pixels; 0..1024
ColorPrecision int // bits; 1..8
PathPrecision int // decimals; 0..8
MaxColors int // palette cap; 0 = as many as ColorTolerance needs, up to 256
Threshold float64 // 0..1; pixels darker than this are foreground
AutoThreshold bool // choose Threshold with Otsu's method
TurnPolicy TurnPolicy // checkerboard resolution
SimplifyTolerance float64 // px; 0..10
CornerThreshold float64 // degrees; 0..180
FitTolerance float64 // px; 0.01..10
ColorTolerance float64 // OKLab distance 0..1 at which colours merge (white to black is 1)
Palette []color.NRGBA // fixed palette, at most 256 distinct entries; empty = quantise
Hierarchical Hierarchical
Refine RefineOptions // spline mode only
Stroke float64 // px, 0..4, default 0; polygon/spline colour shapes are stroked in their fill to hide hairline seams between fitted edges when viewed enlarged
// Deprecated: use Stroke. CutoutStroke is read when Stroke is 0.
CutoutStroke float64
Gradients bool // colour presets: merge adjacent bands that form one linear ramp into a gradient fill
GradientTolerance float64 // 0..1, default 0.03; RMS sRGB distance (channels 0..1) a ramp may leave
// NoMark leaves out the generator mark: by default the SVG root
// carries data-generator="rekha <version>" and a comment naming
// Rekha and its repository. Neither changes how the image renders.
NoMark bool
// Progress, when set, is told how far Segment and Finish have got:
// stage names quantise, label, ramps (Segment; no count) and
// outlines, nest, edges, refine, curves (Finish; done of total, total
// 0 when a stage has no count). Under parallel work it may be called from several
// goroutines at once and counts may arrive out of order. It must be
// quick: a stage reports at most once per whole percent.
Progress Progress
}
Options controls a trace. One struct backs the CLI, the HTTP API and the WebAssembly entry point; Validate is the single source of truth for ranges.
func DefaultOptions ¶
func DefaultOptions() Options
DefaultOptions returns the bw/spline defaults, PresetOptions(PresetBW).
func PresetOptions ¶
PresetOptions returns the defaults for preset p. An unknown preset returns the bw defaults with Preset set to p, which Validate rejects.
type Progress ¶
Validate checks every field in struct order and returns the first failure as a *ValidationError, or nil. Progress receives Options.Progress reports.
type RefineOptions ¶
type RefineOptions struct {
Enabled bool
Sweeps int // 1..10; passes over the contour's pieces
MaxIter int // 1..200; L-BFGS iterations per piece
Weights refine.Weights // prior weights, finite and non-negative
MergeSplit bool // merge smooth joints, split bad fits
Primitives bool // replace near-circles by exact circles
}
RefineOptions controls the Phase 3 refinement of spline output: each fitted contour is optimised against the input's anti-aliasing (Yang et al. 2016), its segments merged and split, and circles recognised.
type Result ¶
type Result struct {
Width, Height int
Gradients []svg.LinearGradient
Radials []svg.RadialGradient
Paths []svg.Path
}
Result is a traced image: filled paths in pixel coordinates, and the gradients (Options.Gradients) that some of them are filled with.
func TraceReader ¶
TraceReader decodes an image (PNG, JPEG or GIF) and traces it.
type Segmentation ¶
type Segmentation struct {
Width, Height int
Palette []color.NRGBA // final palette after cleanup; bw: {white, black}
Labels []uint8 // palette index per pixel
Second []uint8 // second-nearest palette index per pixel
Blend []uint8 // 128..255, share of Labels' colour in the pixel
// Ramps, when Options.Gradients merged bands, has one entry per
// palette index: the linear ramp that fills it, or nil for a flat
// colour. Nil altogether when no option asked for ramps.
Ramps []*gradient.Ramp
// contains filtered or unexported fields
}
Segmentation is an image reduced to a palette and a label per pixel: the input to Finish, and the hand-off point for callers that quantise themselves.
func Segment ¶
func Segment(img image.Image, o Options) (*Segmentation, error)
Segment reduces img to a Segmentation under o. The bw preset thresholds grey exactly as Phase 1 and labels foreground 1 on a {white, black} palette; the colour presets quantise in OKLab (or snap to o.Palette), then despeckle, absorb anti-aliasing slivers and compact the palette.
func (*Segmentation) Finish ¶
func (s *Segmentation) Finish(o Options) (*Result, error)
Finish traces every colour of s, orders the shapes (stacked: nesting depth, outer contours only, consecutive paths of one colour sharing a <path>; cutout: colour then scan order, holes cut out, one path per shape), fits each contour under o.Mode and returns the paths with their palette fills. White shapes at depth 0 are left out.
type TurnPolicy ¶
type TurnPolicy = contour.TurnPolicy
TurnPolicy decides how a boundary walk resolves a 2×2 checkerboard.
type ValidationError ¶
ValidationError reports the first invalid field.
func (*ValidationError) Error ¶
func (e *ValidationError) Error() string
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
rekha
command
Command rekha traces raster images into SVG.
|
Command rekha traces raster images into SVG. |
|
rekha-bench
command
Command rekha-bench runs reference tracers over the corpus and scores them.
|
Command rekha-bench runs reference tracers over the corpus and scores them. |
|
rekha-serve
command
Command rekha-serve is an HTTP front for Rekha: POST /v1/trace returns an SVG; caps on bytes, pixels, time, concurrency and queue keep one client from exhausting the host.
|
Command rekha-serve is an HTTP front for Rekha: POST /v1/trace returns an SVG; caps on bytes, pixels, time, concurrency and queue keep one client from exhausting the host. |
|
rekha-wasm
command
Command rekha-wasm is the WebAssembly build of Rekha: it installs a global "rekha" object with segment, finish, free, trace and version.
|
Command rekha-wasm is the WebAssembly build of Rekha: it installs a global "rekha" object with segment, finish, free, trace and version. |
|
internal
|
|
|
apiopts
Package apiopts turns the option fields of the WebAssembly and HTTP entry points into rekha.Options: a JSON object (wasm) or string fields (HTTP form or query), seeded by the preset exactly as the CLI does.
|
Package apiopts turns the option fields of the WebAssembly and HTTP entry points into rekha.Options: a JSON object (wasm) or string fields (HTTP form or query), seeded by the preset exactly as the CLI does. |
|
bench
Package bench runs external tracers as black boxes over a corpus and scores their SVG output against the input pixels.
|
Package bench runs external tracers as black boxes over a corpus and scores their SVG output against the input pixels. |
|
bitmap
Package bitmap holds a packed 1-bit image and the grey/threshold steps that produce it from a decoded picture.
|
Package bitmap holds a packed 1-bit image and the grey/threshold steps that produce it from a decoded picture. |
|
cli
Package cli holds helpers shared by the rekha command-line entry point.
|
Package cli holds helpers shared by the rekha command-line entry point. |
|
colour
Package colour converts sRGB to the OKLab perceptual colour space, in which the quantiser measures colour differences.
|
Package colour converts sRGB to the OKLab perceptual colour space, in which the quantiser measures colour differences. |
|
contour
Package contour walks the boundaries between foreground and background pixels along pixel edges ("cracks") and groups the resulting loops into shapes with holes.
|
Package contour walks the boundaries between foreground and background pixels along pixel edges ("cracks") and groups the resulting loops into shapes with holes. |
|
corpus
Package corpus generates the deterministic synthetic test images used by the benchmark harness.
|
Package corpus generates the deterministic synthetic test images used by the benchmark harness. |
|
corpus/gen
command
Command gen writes the synthetic corpus as PNG files.
|
Command gen writes the synthetic corpus as PNG files. |
|
fit
Package fit turns dense boundary points into cubic Bézier segments using the least-squares scheme described by Schneider in Graphics Gems (1990).
|
Package fit turns dense boundary points into cubic Bézier segments using the least-squares scheme described by Schneider in Graphics Gems (1990). |
|
geom
Package geom holds the lattice and vector primitives shared by the contour, simplification and fitting stages.
|
Package geom holds the lattice and vector primitives shared by the contour, simplification and fitting stages. |
|
gradient
Package gradient merges adjacent quantised colour bands that together form one linear colour ramp, and fits each merged region a two-stop linear gradient in pixel coordinates.
|
Package gradient merges adjacent quantised colour bands that together form one linear colour ramp, and fits each merged region a two-stop linear gradient in pixel coordinates. |
|
latency
Package latency times Segment and Finish per preset over a directory of images and prints a markdown table; the same code runs natively and under WebAssembly (go_js_wasm_exec maps os to Node's fs), so the two tables compare like for like.
|
Package latency times Segment and Finish per preset over a directory of images and prints a markdown table; the same code runs natively and under WebAssembly (go_js_wasm_exec maps os to Node's fs), so the two tables compare like for like. |
|
metrics
Package metrics scores traced output: pixel fidelity and SVG size.
|
Package metrics scores traced output: pixel fidelity and SVG size. |
|
par
Package par runs independent work items on GOMAXPROCS workers.
|
Package par runs independent work items on GOMAXPROCS workers. |
|
planar
Package planar builds the shared-boundary map of a label image: the crack loops of every colour, cut at the vertices where three colours meet (or two meet diagonally) into arcs, each arc shared by the two regions on its sides.
|
Package planar builds the shared-boundary map of a label image: the crack loops of every colour, cut at the vertices where three colours meet (or two meet diagonally) into arcs, each arc shared by the two regions on its sides. |
|
quant
Package quant builds a colour palette for an image and maps its pixels onto it.
|
Package quant builds a colour palette for an image and maps its pixels onto it. |
|
rasttest
Package rasttest is a test-only nonzero-winding scanline filler, the rule SVG applies by default.
|
Package rasttest is a test-only nonzero-winding scanline filler, the rule SVG applies by default. |
|
refine
Package refine moves the control points of fitted curves to match the input's anti-aliasing: a bezigon is rasterised by exact area coverage and optimised against a soft coverage mask with the priors of Yang et al.
|
Package refine moves the control points of fitted curves to match the input's anti-aliasing: a bezigon is rasterised by exact area coverage and optimised against a soft coverage mask with the priors of Yang et al. |
|
region
Package region cleans a per-pixel label map before tracing: specks and anti-aliasing slivers are merged into their neighbours and the palette is compacted.
|
Package region cleans a per-pixel label map before tracing: specks and anti-aliasing slivers are merged into their neighbours and the palette is compacted. |
|
svg
Package svg writes traced paths as a compact, deterministic SVG document.
|
Package svg writes traced paths as a compact, deterministic SVG document. |
