Scans a directory of photos, first eliminates frames below a sharpness threshold, then selects the sharpest acceptable photo from each burst. Face quality breaks sharpness ties, helping you avoid both blurry shots and the frame where somebody blinked.
-
Scan — reads images from the input directory, pulling the EXIF capture timestamp (falls back to file modified time) and a perceptual hash of each one.
-
Group — chains images into a "burst" when consecutive shots (by timestamp) are both close in time (
--time-gap, default 3s) and close in perceptual hash (--hash-threshold, default 10). Images that don't match anything nearby become their own singleton group, so unrelated photos are never lumped together. -
Score — detects every face in every image and scores it on:
Criterion How it's measured Sharpness Laplacian variance over the face region, normalized against the other shots in its group for the subscore; eligibility is determined separately by the raw sharpness minimum below Eyes open Eye-aspect-ratio from face-mesh landmarks — catches full blinks and half-closed eyes Not occluded Face-detector confidence, which drops when part of the face is covered or out of frame Natural expression Penalizes a wide-open jaw (mid-word/yawn) or lopsided mouth corners (grimace/smirk); small reward for lifted corners (smile) Facing the camera Yaw/pitch estimated from landmark geometry (nose position relative to eyes/forehead/chin) Centered in frame Distance from the face's center to the image's center Reasonable size Penalizes tiny/background faces Each face's subscores are combined into a weighted total (see
WEIGHTSnear the top ofmain.pyif you want to rebalance them). For images with more than one face, the image's score is the area-weighted average across faces, so the main subject matters more than someone in the background. -
Pick & arrange — images below the minimum sharpness are eliminated first. From the remaining images, the sharpest eligible image in each group is "shortlisted," with the face score breaking sharpness ties. If a group has no eligible image with a detected face, it picks the sharpest eligible frame instead. A group with no eligible images has no winner. Shortlisted and eliminated photos are arranged according to
--layout(see below), andscore.csvrecords every image's subscores so you can see why a particular shot won.
python3 -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtWhy
mediapipe==0.10.14, not the latest? The current mediapipe 1.0.x "Tasks" API hard-crashes on some macOS versions with a Metal-service bug inside Google's own compiled binary (an uncatchable native abort, not fixable from application code). 0.10.14 uses mediapipe's oldersolutionsAPI instead — CPU-only, bundled models, no external downloads, no GPU dependency, and it's what this script is built against. It requires Python ≤ 3.13.
python3 main.py /path/to/photosBy default (--layout ugly), shortlisted photos stay exactly where they
are and eliminated photos are moved into /path/to/photos/ugly/.
score.csv always stays in the input directory.
| Layout | Shortlisted photos | Eliminated photos |
|---|---|---|
ugly (default) |
stay in place | moved to ugly/ |
beauty |
moved to beauty/ |
stay in place |
split |
moved to beauty/ |
moved to ugly/ |
score.csv is always written to the input directory, regardless of --layout.
Photos are moved, not copied — pick --dry-run first if you want to
check the results before anything is relocated. Pass --link to symlink
into ugly/beauty instead of moving, if you'd rather leave your library
untouched. --ugly-dir and --beauty-dir override the default subfolder
locations, and --report overrides where score.csv is written.
Any file already inside the ugly/beauty folder is skipped from scanning
(so a second run doesn't re-ingest its own output) —
if your library happens to have its own subfolder named ugly or beauty
(e.g. an "ugly sweater party" album), point --ugly-dir/--beauty-dir
somewhere else to avoid the collision. The tool prints how many files it
skipped for this reason.
| Flag | Default | Description |
|---|---|---|
--time-gap |
3.0 |
Max seconds between shots to count as the same burst |
--hash-threshold |
10 |
Max perceptual-hash distance to count as the same scene |
--min-detection-confidence |
0.5 |
Min face-detector confidence |
--max-faces |
5 |
Max faces to analyze per image |
--min-sharpness |
100 |
Minimum raw Laplacian variance for an image to be eligible; lower or raise this based on Sharpness Raw values in score.csv |
--detector-model |
1 |
0 = short-range (<2m), 1 = full-range |
--layout |
ugly |
File arrangement mode: ugly, beauty, or split (see above) |
--ugly-dir |
<input_dir>/ugly |
Where eliminated photos go |
--beauty-dir |
<input_dir>/beauty |
Where shortlisted photos go |
--link |
off | Symlink into place instead of moving the originals |
--report |
<input_dir>/score.csv |
Where to write score.csv |
--skip-singletons |
off | Leave sharp photos with no similar match in place instead of shortlisting them |
--top-n |
off | Only shortlist the N sharpest eligible group winners |
--top-percent |
off | Only shortlist the top X% sharpest eligible group winners (0-100, rounded up, minimum 1) |
--dry-run |
off | Score and write score.csv only; don't move or symlink any photos |
--top-n and --top-percent are mutually exclusive and apply after the
one-winner-per-group selection — they trim the shortlist down further, they
don't shortlist more than one photo per group. score.csv gets a
Shortlisted column showing exactly which files made the final cut vs.
which were just the best of their group but got trimmed. With
--skip-singletons, sharp photos that have no similar match among the
scanned images (and therefore aren't part of a burst) are scored and listed
in score.csv, but are not shortlisted or moved. Blurry photos are still
eliminated, including single-photo groups.
Sharpness is the first selection filter. A readable image must meet the
minimum raw Laplacian variance (default 100) set by --min-sharpness to
be eligible; images below this floor are eliminated before a group winner
is chosen. Laplacian variance depends on image detail and crop size, so use
score.csv from a dry run to tune the threshold for your photos. Within each
group, the sharpest eligible image with a detected face wins, with the
combined face score breaking sharpness ties. If no eligible image has a
detected face, the sharpest eligible image wins. When --top-n or
--top-percent is used, eligible group winners are ranked sharpest-first
in the same way. If no image in a group meets the minimum, no winner is
selected and all readable images in that group are eliminated. Under the
default ugly layout, eliminated photos are moved to ugly/; the beauty
layout leaves them in place, while split moves them to ugly/. The raw
sharpness value and whether it passed the minimum are included in score.csv.
Start with --dry-run on a new photo set and check score.csv before
letting it move anything — it's the quickest way to see if --time-gap or
--hash-threshold need adjusting for your camera's burst behavior.
Every image gets a row, with subscores reported as percentages (0-100, not 0-1):
| Column | Meaning |
|---|---|
Group ID |
Which burst/singleton group the image belongs to |
File |
Path to the image |
Group Winner |
Whether this was the sharpest eligible image in its group (image score breaks sharpness ties) |
Shortlisted |
Whether this image actually made the final cut (after --skip-singletons/--top-n/--top-percent) |
Group Size |
Number of images in the group |
Faces Detected |
Number of faces found in the image |
Error |
Set if the image couldn't be read/scored |
Image Score (%) |
The image's overall score (area-weighted average across faces) |
Sharpness Raw |
Raw Laplacian variance over face crops (area-weighted), or the whole image if no face was detected |
Sharpness Pass |
Whether the image meets the --min-sharpness threshold |
Sharpness (%), Eyes Open (%), Unoccluded (%), Expression (%), Facing Camera (%), Centered (%), Face Size (%) |
Subscores for the image's top-scoring face |
- Bursts not grouping? Raise
--hash-threshold(perceptual hash is not shift-invariant, so a subject that moves noticeably between frames, or a camera that reframes slightly, can push the distance above the default). - Unrelated photos grouped together? Lower
--hash-thresholdor--time-gap. - Scoring weights live in the
WEIGHTSdict near the top ofmain.py— e.g. bumpeyes_openif blinking is your main complaint, or dropcenteredto near-zero if your subject isn't expected to be centered.
MIT — see LICENSE.