lmimg guide

This guide explains how lmimg thinks about images, how a script reaches the host, and where the limits are. For copy-paste commands see the skill page; for exact signatures see the reference.

Overview

lmimg is a scripting host for raster images. It pairs a static ImageMagick raster and codec engine with a small original implementation of editing ideas known from GIMP: layers, masks, curves, selections, a light healing tool, LUTs, perspective and lens transforms, and selective-focus filters. It does not link GIMP or GEGL and does not use their source. Programs are written in the lmcode block language embedded in an LMScript file, so an image pipeline is a short text file that also checks its own numbers.

Architecture

Image model

An Image is a rectangle of RGBA pixels. Dimensions and coordinates are in pixels. Channel values are normalized to 0..1 in the API and stored as 8 bits per channel. Operations work directly on gamma-encoded sRGB values and there is no colour management, so grayscale, for example, is the Rec.709 luma of the encoded values.

Every edit mutates the image it is called on and returns that same image, which is what makes chains such as copy().levels(...).hsl(...).unsharp(...) work. The rule that follows is simple: call copy() whenever you need both the before and the after.

Sources of pixels

Compositing

There are two ways to combine images. blend composites one image onto another with a mode, an opacity and an offset. A Layers stack, created with img.layers(w, h), collects several images with add or masked and flattens them with render, the GIMP way. Both use straight-alpha source-over with the opacity applied to the source alpha, and both accept the same ten modes. Selections are rectangles that clear alpha outside; any other shape is expressed as an image mask.

Builders

Curve, Layers, Montage and Animation are builders: you add points, layers, tiles or frames and then use the result. A Curve is passed to curves or curves_rgb. A Montage renders a grid sheet with a column count, gap and background colour. An Animation saves a GIF whose frame delays are in centiseconds.

Measurement

lmimg treats numbers as first-class output. mean, stddev, min, max and pixel read values back; histogram exports 256 bins as CSV; psnr and ssim compare two images of equal size. The repository examples use these to assert their own claims, for example that a median filter beats a Gaussian blur on salt-and-pepper noise, or that a barcode reads back module by module.

Workflow

  1. Create the output directory in the outer script.
  2. Inside the block, create or open images, copy what must be preserved, and chain edits.
  3. Assert the properties that matter with img.assert_true and img.assert_close.
  4. Save files, and pass small facts back with lmcode_return_put.
  5. In the outer script, check r.ok and use r.result.
  6. Compile-check with lmscript --check while editing; inspect lmimg --lmcode-signatures when unsure of a parameter list.

Hosts combine through files: one repository example exports histograms as CSV and plots them with lmplot, another places lmimg thumbnails in an lmdraw diagram.

Limits

Licensing

The README, docs, images and examples are MIT licensed. Releases up to and including v0.1.3 were published under the MIT License; later binary releases are under the Lattice Systems Binary License 1.0. Third-party components keep their own licenses, printed by lmimg --notices.

Related pages