Finds scanner faults in 16-bit film scans: streaks, bands, misregistration, focus falloff, clipping, remapped codes.
Find a file
2026-11-18 22:55:38 -05:00
tests film-scan-health: Finds scanner faults in 16-bit film scans: streaks, bands, misregistration, focus falloff, clipping, remapped codes. 2026-11-18 22:55:38 -05:00
.gitignore film-scan-health: Finds scanner faults in 16-bit film scans: streaks, bands, misregistration, focus falloff, clipping, remapped codes. 2026-11-18 22:55:38 -05:00
commons.toml film-scan-health: Finds scanner faults in 16-bit film scans: streaks, bands, misregistration, focus falloff, clipping, remapped codes. 2026-11-18 22:55:38 -05:00
LICENSE film-scan-health: Finds scanner faults in 16-bit film scans: streaks, bands, misregistration, focus falloff, clipping, remapped codes. 2026-11-18 22:55:38 -05:00
README.md film-scan-health: Finds scanner faults in 16-bit film scans: streaks, bands, misregistration, focus falloff, clipping, remapped codes. 2026-11-18 22:55:38 -05:00
scan_health.py film-scan-health: Finds scanner faults in 16-bit film scans: streaks, bands, misregistration, focus falloff, clipping, remapped codes. 2026-11-18 22:55:38 -05:00

film-scan-health

Finds scanner faults in 16-bit film scans: clipping, full-length streaks and bands, color channel misregistration, focus falloff, missing codes from a remap table, and whether a higher resolution actually adds detail.

Problem

While testing a film scanner driver, an agent needed to tell scanner faults (a dust line on the sensor, a lamp flicker band, red and blue layers out of register, a focus tilt, a driver gain table that skips codes) apart from picture content, on 16-bit TIFFs too big to eyeball. General image quality tools score "sharpness" or "noise" for photos; none of them look for the faults a scanner makes.

Usage

python -I scan_health.py health SCAN.tif [SCAN.tif ...]
python -I scan_health.py codes SCAN.tif              # histogram gaps, remap tables
python -I scan_health.py compare A.tif B.tif         # two scans of the same frame
python -I scan_health.py resolution LOW.tif HIGH.tif [--crops DIR]

health on a synthetic frame with a 3% streak planted at column 700 of green and red shifted 2 px:

frame.tif  1600x1200  2400.0 dpi
  R: clipped 0.000%; full-length column streaks: worst 1x noise, 0 over 6x; full-length row bands: worst 2x noise, 0 over 6x
  G: clipped 0.000%; full-length column streaks: worst 10x noise, 2 over 6x; full-length row bands: worst 2x noise, 0 over 6x
  B: clipped 0.000%; full-length column streaks: worst 1x noise, 0 over 6x; full-length row bands: worst 2x noise, 0 over 6x
  R vs G registration: +2.00, -0.00 px (confidence 0.98)
  B vs G registration: +0.00, -0.00 px (confidence 0.89)
  fine grain per area (1.00 = sharpest; a soft corner or side reads low):
    1.00  0.95  0.92
    1.00  0.98  1.00
    0.99  0.97  0.97
  RESULT: LOOK: G streaks at columns [700, 703]; R is 2.0 px off green (color fringes)

How it works

  • Streaks and bands. Each pixel minus the mean of its neighbors 3 px away across the line direction (picture content mostly cancels), scaled by the square root of the level (evens out shot noise), then averaged along each column or row with the top and bottom 5% trimmed. The key step: a scanner line runs the whole length, while a straight edge in the picture (a rail, a table edge) covers only part of it. So the scan is cut into 6 pieces along the line, each piece scored on its own, and a position is flagged only if it stands out (over 6x the robust noise) in at least 5 of the 6. That keeps straight picture edges from reading as faults without any object detection. The outer 10% of the frame is skipped (holder and film edges).
  • Registration. Phase correlation of red and blue against green on high-passed detail in a center crop, so color differences in the picture don't bias it. Film grain sits in all three layers, which is what gives phase correlation something to lock onto.
  • Focus. Fine-grain energy, normalized by level, per tile of a 3x3 grid. Grain is uniform across a frame, so a tile with much less of it (under 0.6 of the best) is soft.
  • Codes. Histogram of each channel in its 1-99% band; unused codes are tested for a repeat spacing by autocorrelation. A strong repeat means a gain or offset table in the scanner or driver.
  • Resolution. The same physical square (picked where detail is strongest) from both scans, windowed, and its power spectrum in bands up to each scan's Nyquist limit, in cycles/mm so the two are comparable. Flat power past the low scan's limit means the extra pixels hold noise.

Tested on

  • python -I tests/test_scan_health.py: synthetic film-like scans with known faults: a clean frame (no false alarms), a 3% column streak, red shifted 2 px, a 1.25x gain table (one code in five missing), a repeat scan shifted 3 px and 2 px, and a 1200/2400 dpi pair. About 3 seconds.
  • Real use: one session of 16-bit RGB negative scans from a dedicated 35 mm film scanner, used to check a driver patch between scans (2026-11-18).

Known limits

  • A streak of 1.5% of the level under heavy grain reads about 5x noise, below the 6x flag. Faint dust lines on grainy film can be missed; the worst Nx noise figure shows how close it came.
  • A streak is also reported 3 columns to one side ([700, 703] above): the neighbor-difference kernel gives it a side lobe. Treat a pair 3 apart as one line.
  • Focus reads low for areas that are out of focus in the picture (a soft background), not only for scanner focus faults. Look at the picture before blaming the scanner.
  • compare assumes the same size and dpi; its noise figure reads high when the shift is sub-pixel.
  • resolution needs a dpi tag in both files and assumes the film didn't move between scans.
  • 16-bit only (codes assumes 65536 levels). Expects RGB or single-channel TIFF.

Requirements

Python 3.10+, numpy, tifffile, opencv-python (or opencv-python-headless).