Metadata-Version: 2.4
Name: openfilmkit
Version: 0.4.0
Summary: Free film scanning and negative conversion from the command line, built on SANE
Author-email: Aidan Siegel <openfilmkit@aidansiegel.com>
License-Expression: GPL-3.0-or-later
Project-URL: Homepage, https://github.com/aidansiegel/OpenFilmKit
Keywords: film,scanner,sane,negative,digitization
Classifier: Development Status :: 2 - Pre-Alpha
Classifier: Environment :: Console
Classifier: Operating System :: MacOS
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Multimedia :: Graphics :: Capture :: Scanners
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: numpy>=1.24
Requires-Dist: pillow>=10
Requires-Dist: tifffile>=2024.1.30
Requires-Dist: imagecodecs>=2024.1.1
Provides-Extra: clean
Requires-Dist: opencv-python-headless<5,>=4.8; extra == "clean"
Dynamic: license-file

# OpenFilmKit

Free film scanning and negative conversion from the command line, for macOS and Linux, built on
[SANE](http://www.sane-project.org/).

**Status: early development.** Capture, conversion and cleanup work; the first scanner it targets
is the Plustek OpticFilm 8200i SE. Expect changes.

## Install

```sh
brew install aidansiegel/openfilmkit/openfilmkit
openfilmkit doctor
```

The formula builds OpenFilmKit's own SANE runtime (a pinned upstream commit plus the fixes in
`patches/`), kept separate from Homebrew's `sane-backends`. On Linux, `openfilmkit doctor` prints
the one command that installs the USB permission rule.

`pip install "openfilmkit[clean]"` installs conversion and cleanup only, on macOS, Linux or
Windows. `scan` needs the SANE runtime that the Homebrew formula builds (or build it yourself from
a checkout with `tools/build_sane.py`); on Windows, scan with SilverFast or VueScan instead (below).

## Use

```sh
openfilmkit doctor                      # driver, scanner, identification
openfilmkit roll new roll-07 --film color-negative --stock kodak-gold200
openfilmkit scan roll-07 --frames 6     # linear 48-bit TIFF masters, one frame at a time
openfilmkit convert roll-07/masters/frame-01.tif
openfilmkit clean roll-07               # dust and holder edges, on new copies
```

Every command takes `--json`. Masters are never changed; every conversion and cleaned copy has a
recipe beside it that says exactly how it was made.

- `scan --full-area` scans the driver's whole area instead of its default selection.
- `convert` picks the film's response curve from `openfilmkit stocks` / `openfilmkit profiles`
  (142 profiles digitized from manufacturers' data sheets). `--tiff` writes a 16-bit TIFF at full
  resolution instead of a JPEG (see below).
- `clean` removes dust and fibers and trims film-holder edges, always on a new copy. Eyes and
  mouths, and the camera's date stamp, are left untouched by dust removal; faces are found in any
  orientation, so sideways frames are covered. Options:
  - `--no-dust` trims holder edges only; run `clean` again later for dust.
  - `--no-crop` keeps the holder edges; `--no-faces` skips face detection.
  - `--color` also corrects levels and color cast; `--straighten DEGREES`, `--lift-shadows GAMMA`
    and `--red-eye` do what they say.
  - `--scratches` also finds scratches and larger debris with a trained model and fills them with
    a generative model (see below).
  - On a roll folder, it cleans only conversions without a copy made with the same options.

### Files you get

| File | From | What it is |
|---|---|---|
| Master | `scan` | Linear 48-bit TIFF straight from the scanner, never changed. |
| Processed master | `convert --tiff`, then `clean` | 16-bit TIFF, sRGB with the profile embedded, lossless compression, full resolution. The file to edit, archive or upload (Immich takes it as the original). |
| Viewing copy | `convert`, then `clean` | 8-bit JPEG for sharing and web pages; `clean` can also make one from a processed master (`--output frame.jpg`). |

`clean` works on a 16-bit TIFF at full depth: it makes every decision on an 8-bit copy, exactly
as for a JPEG, and applies color, cropping, straightening, shadows and dust fills at 16 bits, so
smooth skies and shadows keep tens of thousands of levels instead of 256. The processed master is
sRGB for now: until the scanner is profiled (M4 in the roadmap), conversion assumes sRGB
primaries, so a wider color space would hold no extra color.

### Scratches

`clean --scratches` adds a second pass for what dust removal leaves: scratches, fibers and debris.
Microsoft's scratch-detection model from "Bringing Old Photos Back to Life" finds them, and
MI-GAN, a generative inpainting model, fills them. Faces get a lower threshold and extra speck
finders, catchlights and the camera's date stamp are protected, and dark marks are left as scene.
Because the fill makes up picture where the damage was, it is off by default and a cleaned copy
made with it is recorded as generative processing. `--spare-long-lines` keeps long straight lines
(tile grout, wires) the model can mistake for scratches.

The two models (about 100 MB) are downloaded once, on first use, from this project's
[models-1 release](https://github.com/aidansiegel/OpenFilmKit/releases/tag/models-1) and checked
against their SHA-256; `openfilmkit models --fetch` gets them ahead of time. Both run in OpenCV.
A 33-megapixel scan takes about two minutes and 2.5 GB of memory.

## Scans from SilverFast or VueScan

`convert` also reads the raw scans SilverFast and VueScan save, so a scanner OpenFilmKit can't
drive yet, or a Windows PC (where SANE doesn't run), still gets the same conversion and cleanup.
Save the scan before any inversion or color correction:

- **SilverFast:** save the raw HDR (48-bit) or HDRi (64-bit, with infrared) scan, not a converted
  positive. Tested with an HDRi scan from SilverFast 9 and an OpticFilm 8200i.
- **VueScan:** in the Output tab, save a raw file as 48-bit RGB or 64-bit RGBI (raw files need the
  Professional edition). Not yet tested with a real VueScan file.

Uncompressed and compressed (LZW, ZIP) files both work. The infrared channel stays in your file
but isn't used yet. 8-bit scans are refused, and an already-inverted positive won't convert
correctly.

## Scanners

`openfilmkit scanners` lists the film scanners SANE supports and the ones OpenFilmKit has profiles
for. A scanner is identified by its driver's internal model ID, confirmed against its USB
descriptors, so settings meant for one hardware revision are never used on another.

## Data sources

- Film response curves: digitized from manufacturers' published characteristic-curve charts
  (Kodak, Fujifilm, Agfa, Konica; most via the [125px film document archive](https://125px.com/docs/film/)),
  and from Columbia University's [Database of Response Functions](https://www.cs.columbia.edu/CAVE/software/softlib/dorf.php)
  (M. D. Grossberg and S. K. Nayar, "Modeling the Space of Camera Response Functions", IEEE PAMI 2004).
  Each profile records its source, page and SHA-256; see `docs/FILM-STOCK-RESEARCH.md` and
  `tools/research/datasheets.json`. The data sheets themselves are not included.
- Scratch detection: Microsoft, [Bringing Old Photos Back to Life](https://github.com/microsoft/Bringing-Old-Photos-Back-to-Life)
  (Wan et al., CVPR 2020), MIT license; the official checkpoint converted to ONNX.
- Scratch fill: Picsart AI Research, [MI-GAN](https://github.com/Picsart-AI-Research/MI-GAN)
  (Sargsyan et al., ICCV 2023), MIT license (code and weights); the generator from the authors'
  ONNX pipeline. `tools/build_models.py` rebuilds both model files from the authors' originals.
- Face detection: YuNet (Shiqi Yu and others), `face_detection_yunet_2023mar.onnx` from the
  [OpenCV Zoo](https://github.com/opencv/opencv_zoo), MIT license
  (`openfilmkit/data/face_detection_yunet_LICENSE`), run through OpenCV.
- Scanner and model tables: generated from [SANE](http://www.sane-project.org/) (sane-backends,
  GPL-2.0-or-later with the SANE exception) at the commit in `packaging/sane-pin.json`.

## License

GPL-3.0-or-later. See [LICENSE](LICENSE).

Copyright © 2026 Aidan Siegel &lt;openfilmkit@aidansiegel.com&gt;
