A small, composable image-processing suite with two fronts on one core:
filmlab film— scanned film: 3F/.fffand 16-bit TIFF strips, auto frame splitting with format priors, C-41 orange-mask removal in density space, E-6 linear develop, per-roll config, batch export.filmlab lut—.cubeLUT looks for digital photos (JPG/TIFF/PNG and RAW via LibRaw), with a static HTML look-picker.
Stages are independent and composable: split a strip without colour
work, export untouched crops for another tool, or run the whole develop.
(The legacy filmdev command is kept as an alias for filmlab film.)
One Hasselblad X5 scan of a 120/645 C-41 strip: 4 frames detected
automatically, the scanner margin and the film's black edge trimmed, the
orange mask removed per channel in log density, then graded in
roll.toml. Each frame is centre-cropped to the film gate's 56:41.5
ratio, so a roll delivers as a consistent set. The middle panel is what
"correct but flat" looks like — density-domain inversion is linear, so a
roll usually needs a small exposure/black-point lift (see Flat results
below).
filmlab/
├── core/ colour encoding, tone, .cube LUT engine, ICC IO, contact sheet
├── film/ fff decoding, frame splitting, density develop, roll.toml, convert
└── digi/ LUT application + look-picker page (RAW via rawpy)
python3 -m pip install -e . # core (numpy, tifffile, Pillow, tomli-w)
python3 -m pip install -e ".[raw]" # + RAW support (rawpy/LibRaw)
python3 -m pip install -e ".[dev]" # + pytest / ruff / pre-commit (development)# geometry only: detect frames (+ column trim), write roll.toml
filmlab film split ROLL_DIR --format 645 --type e6 --camera "Bronica ETRSi"
# split + colour profile (film base / black / white balance) in one step
filmlab film analyze ROLL_DIR --format 645 --type c41 --stock "Portra 400"
# fast low-res render to verify edits in roll.toml
filmlab film preview ROLL_DIR
# full-resolution export -> ROLL_DIR/out/ (16-bit TIFF + JPEG, sRGB ICC)
filmlab film develop ROLL_DIR
# grading-free export -> ROLL_DIR/convert/<mode>/
filmlab film convert ROLL_DIR --mode raw # untouched scan values (negadoctor / archive)
filmlab film convert ROLL_DIR --mode linear # colour-normalised, no gamma (C1 / LR)develop and convert --mode linear estimate a missing colour profile
on demand (and write it back), so split alone is enough for slide film
that just needs cutting. Already-cut single-frame scans need no
--format: each file becomes one frame automatically.
--format accepts registered names or a fully parameterised spec:
| name | film | frame | pitch |
|---|---|---|---|
135 |
35mm | 36x24 | 38mm |
135hf |
35mm half frame | 18x24 | 19mm |
645 |
120 | 41.5x56 | 47mm |
66 |
120 | 56x56 | 60mm |
67 |
120 | 69x56 | 74mm |
69 |
120 | 84x56 | 93mm |
--format custom:film_width=61,frame_along=42,frame_across=56,pitch=47
Pitch is measured from the strip when detectable; the prior is only a
fallback. --type auto detects C-41 vs E-6 from the film base
(orange-mask ratio > 1.35).
- Decode —
.fffis a big-endian TIFF container; tifffile parses it, pixel access is a zero-copy memmap (rows are paged per frame). - Split — per-row brightness + texture over the central window; saturated texture-free fog rows excluded; gap-aware bridging of dark frame interiors; grid-anchor voting on the measured pitch; content column trim to the film gate.
- Develop — C-41:
D = log10(base / (raw - pedestal))per channel (dividing by the film base neutralises the orange mask and inverts in one step), grey-world WB from bright near-neutral pixels, per-frame dmax auto exposure. E-6: linear scale from per-channel film black to per-frame white. - Grade — black point, contrast, saturation, true sRGB transfer
curve, optional
.cubeLUT (grade.lutin roll.toml). - Export — 16-bit deflate TIFF with measured DPI + sRGB ICC
(
FILMDEV_sRGB_ICCoverrides the profile path), JPEG, contact sheet.
Everything split/analyze write is editable: frame bounds
([[strip]] frames, set the matching frame_sources entry to
"manual"), profile.*, grade.*, export.*. Develop always honours
the file, so a roll can be reproduced exactly later.
analyze also removes the scan border and locks the frame ratio:
- the scanner's white holder margin and the film's black edge are found on a render with the roll's grade (a neutral render under-detects, because the grade darkens a mid-grey edge to near-black);
- rows use the widest inset seen on the strip, columns the median profile across its frames — the gate sits at a fixed position, so one odd frame must not decide the crop;
- a 0.3 % pad is added on every side (a sliver of edge is worse than a
slightly tighter crop), then the box is centre-cropped to
frame_across / frame_along(56:41.5 for 645 ≈ 4:3); --ratio 4:3(or1.333) overrides that ratio; it is stored asfilm.ratioin roll.toml so later runs keep it.
Frame bounds stay in roll.toml, so anything can be overridden by hand.
Negative inversion is linear in density, so a freshly developed roll can
look grey, milky and under-saturated — no true blacks and a lot of
near-white. That is a tone problem, not a look problem: a LUT alone
will not fix it. Raise the black point and pull exposure down in
[grade], then re-run preview (a second or two):
[grade]
exposure = 0.75 # 1.0 can sit too high after inversion + sRGB
black_point = 0.06 # gives the shadows a floor
contrast = 1.15
saturation = 1.12Values are scene dependent — judge on the contact sheet, not one frame. On a measured roll this moved the 5th percentile from 0.35 to 0.09 and near-white pixels from 20 % to 4 %, with interior clipping at 3 %.
LUTs remain the style layer: apply them to the graded JPEGs with
filmlab lut apply and keep the TIFF master neutral (leave
grade.lut empty) so the look is easy to change later.
filmlab lut list # available looks
filmlab lut pick IMG_4032.jpg # -> lut_pick.html, compare all looks
filmlab lut apply ~/photos/trip --lut warm_film --strength 0.8
filmlab lut apply DSC_0421.NEF --lut faded_printLUT search order: ./luts, ~/.filmlab/luts, built-ins. The shipped
looks (warm_film, cool_clear, faded_print, mono_classic) are simple
formula-generated demos — for real film emulations, drop the free
RawTherapee film-simulation CLUTs
(Portra, Ektar, Gold, Velvia, ...) into ~/.filmlab/luts/. The same
library serves both fronts: a look that works on digital photos can
also grade film scans via grade.lut in roll.toml.
RAW notes: files decode via rawpy/LibRaw with camera white balance and no auto-brightness (consistent, predictable exposure), 16-bit throughout. Verified with Nikon Z 6_2 NEF; LibRaw covers the usual brands.
- firenzemc/imaconfilm — this
project began after reading its source. The density-domain develop model
(per-channel film-base division in log space) and the estimation
heuristics in
film/analysis.py— film-base detection from unsaturated red-channel pixels, the R/B base-ratio negative test, grey-world white balance on bright near-neutral pixels, the raw/linear export modes — are informed by that reading and reimplemented here. No code was copied from it. - darktable's negadoctor module — the original density-domain negative workflow that imaconfilm, and in turn this project, learned from.
- Single-frame C-41 scans have no unexposed gaps; the pedestal falls back to a low percentile (strips preferred).
- Frame bounds use the nominal frame length; unusual crops may need
manual
framesedits in roll.toml. - E-6 under artificial light keeps its cast (fix via
grade.wbor LUT). - Strips are assumed vertical (long axis = film advance direction).
python3 -m pip install -e ".[dev]"
pre-commit install # ruff lint + format run on every commit
pytest -q # 27 tests, ~0.1s (synthetic data, no samples needed)
ruff check . && ruff format --check .Tests cover the colour maths, the .cube engine, the format registry, roll.toml roundtrips, and the frame splitter on synthetic strips (including a dark night frame and a light-struck tail — the hard case).
Releases follow semantic versioning; CHANGELOG.md is the source of truth.
# 1. land changes with tests green
pytest -q && ruff check . && ruff format --check .
# 2. bump the version in pyproject.toml, add a CHANGELOG entry
# 3. build and validate the artefacts
python -m build && twine check dist/*
# 4. tag and publish
git tag -a vX.Y.Z -m "filmlab X.Y.Z" && git push origin main vX.Y.Z
gh release create vX.Y.Z dist/* --title "filmlab X.Y.Z" --notes-file notes.md
# 5. open the next cycle
# version = "X.Y.(Z+1).dev0"Install from a release: download the wheel from
Releases and
pip install filmlab-X.Y.Z-py3-none-any.whl (not on PyPI yet).
