Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

fix(video): video-frames erases a speck far from the body before the edge check

Soohong Kim9f1f2a15560d
diff --git a/CHANGELOG.md b/CHANGELOG.md
index fcfbb49..60207a0 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,9 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the
## Unreleased
+- **Fix: `video-frames` erases a speck far from the body before the edge check.** A fleck the model drew drifting across the background survives the matte as a few pale pixels; where it crossed an edge band in one frame, the edge check read it as the subject framed too tight and refused the clip, and `video-loop --anchor motion-auto`, which never cleans a frame, kept it in the loop and widened every cell to reach it. Now every keyed frame has its specks erased before anything reads it (`frames.drop_specks`): a piece of the frame — its opaque pixels, corners joining them — under 1 % of the body (`SPECK_MIN_FRACTION`, at least 8 px) and more than a tenth of the body's height from it (`SPECK_APART`). Small pieces near the body are the subject's own and stay: the outline's loose pixels, a shadow drawn under a shoe, a part of a shoe the matte cut loose. Each report row gains `specks`, how many its frame lost, and the report `specks` (`dropped`, `frames` and the rule's numbers); a frame with no speck is not written again, so its bytes are as before. `video-loop`'s own pass on a cut that is not motion-reviewed (`--anchor none|feet|body`) erases every island of solid pixels under the same 1 % as before, pixel for pixel, through the same function (a run-based labelling, about twenty times faster than the pixel-by-pixel search it replaces). [docs/video-pipeline.md](docs/video-pipeline.md#3-frames--extract-key-check-the-edges).
+- **`tests/video/test_edge_speck_lead_in.py`** keys a body on magenta with five pale pixels in its right edge band in one frame: before this the frames were refused as framed too tight, now the fleck is erased (`specks: 1`) and no frame touches the edge; a shadow under the feet, a loose pixel by the outline and a far block too large to be a speck are kept; `video-loop`'s own reading still erases the loose pieces. A walker on magenta with a fleck drifting far from it, keyed and cut `--anchor motion-auto`, is cut 49 px wide, the walker alone (147 px before).
+
- **Fix: `video-follow` replaces the loop's files only once all of them are written.** The strip, the GIF and the WebP were written over the loop's before the record was, so a run that failed on the record — `follow.follow_loop` given numpy numbers, an int64 of which has no JSON form (`TypeError`) — or on an animation's check left a moved strip beside a record that did not say so. Now the strip, GIF, WebP and record are written and checked in a scratch directory beside the loop (`.follow.*`), each under its own name, and moved over the loop's files after the record is written; a run that fails on the way leaves all four as they were (the strip as cut is still kept as `follow.source.png`, as on a refusal). `follow_loop` reads its regions, `gain`, `freq` and `zeta` as the floats the command line gives, so numpy numbers, or plain ints, write the strip and record that the same numbers as floats write, byte for byte (a caller that passed plain ints finds them recorded as floats, `80.0` where it was `80`). `loop.verify_animation` closes the file it checks. The command's output, its strip, GIF, WebP and record, and `--help` are as before, byte for byte. [docs/video-pipeline.md](docs/video-pipeline.md#6-follow-through--video-follow).
- **`tests/video/test_follow.py`** moves a chest and a smaller head region given as int64, int32, float32, float64 and plain int coordinates, as the rows of an int64 array, and with a float32 `gain`: each writes the strip, GIF, WebP and record the float coordinates write, byte for byte (before this the int64 run failed on the record with the strip already moved). A run made to fail on its record or on its WebP's check, on a loop as cut and on one already followed, leaves the strip, GIF, WebP and record as they were, and nothing beside them but `follow.source.png`.
diff --git a/docs/video-pipeline.md b/docs/video-pipeline.md
index 79812d8..d73f318 100644
--- a/docs/video-pipeline.md
+++ b/docs/video-pipeline.md
@@ -568,8 +568,19 @@ survives untouched on (8, 162, 24), (5, 200, 10) or pure-key backgrounds. Choose
away from the subject's hues ([chroma-alpha.md](chroma-alpha.md)) — that rule now covers
the painted key's darker variants too.
-The report also carries per-frame alpha coverage and an **edge-contact check**: any
-opaque pixel in the top/left/right 4-pixel bands fails the run. Each contact pixel is
+Every keyed frame first has its **specks** erased (`drop_specks`): a piece of the frame — its
+opaque pixels, corners joining them — under 1 % of the frame's largest piece, the body
+(`SPECK_MIN_FRACTION`, at least 8 px), and more than a tenth of the body's height away from it
+(`SPECK_APART`). That is a fleck the model drew drifting across the background, which survived the
+matte. Small pieces near the body stay: the outline's loose pixels, a shadow drawn under a shoe,
+a part of a shoe the matte cut loose. A frame with no speck is not written again; each report
+row says how many its frame lost (`specks`) and the report totals them (`specks.dropped`,
+`specks.frames`). Without this a fleck that crossed an edge band in one frame was read as the
+subject framed too tight, and `--anchor motion-auto`, which never cleans a frame, kept it in
+the loop's cells and widened them to reach it.
+
+The report also carries per-frame alpha coverage and an **edge-contact check**, read after the
+specks are gone: any opaque pixel in the top/left/right 4-pixel bands fails the run. Each contact pixel is
classified by its *raw* colour — the declared key's hue family is **`residual`**
(background the matte did not erase), anything else is **`subject`** — and the two
defects fail with different messages: residual-only contact points at `video-canvas`
diff --git a/sprite_gen/video/frames.py b/sprite_gen/video/frames.py
index d61978e..beee2eb 100644
--- a/sprite_gen/video/frames.py
+++ b/sprite_gen/video/frames.py
@@ -24,6 +24,16 @@ from a `video-canvas --fit tight` frame is clipped on purpose, but a frame where
leftover key background reaches the edge is still a keying defect. A frame where the
subject touches the edge carries key-tinted fringe pixels beside it and is accepted with
them. The contacts stay in the report.
+
+A **speck** is not the subject either: a fleck the model drew drifting across the background,
+well away from the body, that survived the matte. Every keyed frame has its specks erased
+(`drop_specks`) before the edge check reads it, so a few pale pixels drifting through the edge
+band far from the body are erased rather than read as the subject framed too tight. A speck is
+small — under `SPECK_MIN_FRACTION` of the frame's largest component, the body — and far: more
+than `SPECK_APART` of the body's height from it. Its pixels are every opaque one (what the edge
+check reads), corners joining them. Near the body, small detached pieces are the subject's own
+and stay: the outline's loose pixels one transparent pixel off, a shadow drawn under a shoe, a
+shoe's part the matte cut loose. How many each frame lost is in its report row (`specks`).
"""
from __future__ import annotations
@@ -65,6 +75,13 @@ SPILL_REFERENCE_MAX = 0.005 # the still's own key material ≤ the engine's sma
SPILL_REFERENCE_MARGIN = 1
SPILL_REFERENCE_MAX_PIXELS = 6_000_000
EDGE_MAX_PIXELS = 0 # any opaque pixel on the top/left/right edge band = contact
+# Specks (`drop_specks`). A component under SPECK_MIN_FRACTION of the frame's largest one, or under
+# SPECK_MIN_PX, is small; more than SPECK_APART of the largest one's height from it, far. `video-loop`
+# reads the size by the same two numbers when it erases the loose pieces of a cut (`drop_specks` with
+# its own reading, see run_loop).
+SPECK_MIN_FRACTION = 0.01
+SPECK_MIN_PX = 8
+SPECK_APART = 0.1
# Edge decontamination (`sprite_gen.frames.decontam`). A decoded frame's chroma is blurred by
# 4:2:0 while its luma is not, so frames use the video fit. One palette serves the whole clip,
# learned on the first frame, so the colours an edge may take cannot change between frames.
@@ -127,6 +144,83 @@ def extract(clip: Path, raw_dir: Path, stream_index: int | None = None) -> list[
return files
+def _components(solid: np.ndarray, *, diagonal: bool = False) -> tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray]:
+ """The components of a boolean picture, as runs of each row: (row, first column, column past the
+ last, component of the run, pixels per component). A run touches a run of the row above when their
+ columns overlap (4-connected), or with `diagonal` also when they meet at a corner (8-connected)."""
+ reach = 1 if diagonal else 0
+ rows, width = solid.shape
+ edges = np.diff(np.pad(solid.astype(np.int8), ((0, 0), (1, 1))), axis=1)
+ ys, starts = np.nonzero(edges == 1)
+ stops = np.nonzero(edges == -1)[1]
+ parent = list(range(len(ys)))
+
+ def root(k: int) -> int:
+ while parent[k] != k:
+ parent[k] = parent[parent[k]]
+ k = parent[k]
+ return k
+
+ bounds = np.searchsorted(ys, np.arange(rows + 1))
+ for y in range(1, rows):
+ a, a_end = int(bounds[y - 1]), int(bounds[y])
+ b, b_end = a_end, int(bounds[y + 1])
+ while a < a_end and b < b_end:
+ if starts[a] < stops[b] + reach and starts[b] < stops[a] + reach:
+ ra, rb = root(a), root(b)
+ if ra != rb:
+ parent[max(ra, rb)] = min(ra, rb)
+ if stops[a] < stops[b]:
+ a += 1
+ else:
+ b += 1
+ labels = np.array([root(k) for k in range(len(ys))], dtype=np.int64)
+ sizes = np.bincount(labels, weights=stops - starts, minlength=len(ys)).astype(np.int64)
+ return ys, starts, stops, labels, sizes
+
+
+def _near(mask: np.ndarray, reach: int) -> np.ndarray:
+ """Every pixel within `reach` px of `mask`, each way and diagonally (a square of side 2 reach + 1)."""
+ for axis in (0, 1):
+ n = mask.shape[axis]
+ total = np.cumsum(np.pad(mask.astype(np.int32), [(reach + 1, reach) if a == axis else (0, 0) for a in (0, 1)]), axis=axis)
+ mask = (np.take(total, np.arange(2 * reach + 1, 2 * reach + 1 + n), axis=axis)
+ - np.take(total, np.arange(n), axis=axis)) > 0
+ return mask
+
+
+def drop_specks(image: Image.Image, *, alpha_over: int = 0, diagonal: bool = True,
+ apart: float = SPECK_APART) -> tuple[Image.Image, int]:
+ """Erase the specks: (the image, components erased). A component is the pixels over `alpha_over`,
+ joined side by side (and at corners with `diagonal`); a speck is one under SPECK_MIN_FRACTION of
+ the largest, or under SPECK_MIN_PX, whose every pixel is more than `apart` of the largest one's
+ height from it (0: wherever it is). An image with no speck comes back as it was given, the same
+ object; otherwise a copy with the specks' pixels set to (0, 0, 0, 0)."""
+ rgba = np.asarray(image.convert("RGBA"))
+ ys, starts, stops, labels, sizes = _components(rgba[..., 3] > alpha_over, diagonal=diagonal)
+ if not len(ys):
+ return image, 0
+ largest = int(sizes.argmax())
+ small = sizes < max(SPECK_MIN_PX, int(sizes[largest]) * SPECK_MIN_FRACTION)
+ small[np.setdiff1d(np.arange(len(sizes)), labels)] = False # only the roots are components
+ if small.any() and apart > 0:
+ body = labels == largest
+ reach = int(apart * (int(ys[body].max()) - int(ys[body].min()) + 1))
+ near = np.zeros(rgba.shape[:2], dtype=bool)
+ for y, x0, x1 in zip(ys[body], starts[body], stops[body]):
+ near[y, x0:x1] = True
+ near = _near(near, reach)
+ for y, x0, x1, label in zip(ys, starts, stops, labels):
+ if small[label] and near[y, x0:x1].any():
+ small[label] = False
+ if not small.any():
+ return image, 0
+ out = rgba.copy()
+ for y, x0, x1 in zip(ys[small[labels]], starts[small[labels]], stops[small[labels]]):
+ out[y, x0:x1] = 0
+ return Image.fromarray(out, "RGBA"), int(small.sum())
+
+
def edge_contact(image: Image.Image) -> dict[str, int]:
"""Opaque pixels in the top/left/right edge bands (the floor edge is expected contact)."""
alpha = image.convert("RGBA").getchannel("A")
@@ -251,10 +345,14 @@ def key_frames(
spill_require_hue=spill == "full", decontam=decontam, decontam_fit=DECONTAM_FIT,
decontam_palette=clip_palette, decontam_edge_band=EDGE_ROWS)
image = Image.open(dst).convert("RGBA")
+ # The specks go before anything reads the frame: the edge band, the coverage, the loop.
+ image, specks = drop_specks(image)
+ if specks:
+ image.save(dst)
hist = image.getchannel("A").histogram()
w, h = image.size
alpha_zero_pct = round(100 * hist[0] / (w * h), 2)
- row = {"frame": src.name, "alpha_zero_pct": alpha_zero_pct, "route": stats.get("route")}
+ row = {"frame": src.name, "alpha_zero_pct": alpha_zero_pct, "route": stats.get("route"), "specks": specks}
if decontam != "off":
done = stats["decontam"]
if done.get("applied"):
@@ -282,6 +380,8 @@ def key_frames(
"frames": len(rows),
"alpha_zero_pct_min": min(r["alpha_zero_pct"] for r in rows),
"alpha_zero_pct_max": max(r["alpha_zero_pct"] for r in rows),
+ "specks": {"dropped": sum(r["specks"] for r in rows), "frames": sum(1 for r in rows if r["specks"]),
+ "min_fraction": SPECK_MIN_FRACTION, "min_px": SPECK_MIN_PX, "apart": SPECK_APART},
"edge_contacts": contacts,
"edge_policy": "off" if not check_edges else ("subject-allowed" if allow_subject else "refuse"),
"rows": rows,
diff --git a/sprite_gen/video/loop.py b/sprite_gen/video/loop.py
index e9fb15e..ef983af 100644
--- a/sprite_gen/video/loop.py
+++ b/sprite_gen/video/loop.py
@@ -37,7 +37,6 @@ import os
import shutil
import subprocess
import sys
-from collections import deque
from dataclasses import dataclass
from pathlib import Path
from typing import Any
@@ -54,13 +53,13 @@ from sprite_gen.video import legs as legs_mod
from sprite_gen.video import period as period_mod
from sprite_gen.video import repair as repair_mod
from sprite_gen.video import rife as rife_mod
+from sprite_gen.video.frames import drop_specks
ANALYSIS_SIZE = 96 # thumbnail edge for the distance matrix
STRIP_MAX_CELLS = 64 # upper bound on cells even when they are narrow
STRIP_MAX_WIDTH = 32000 # Chrome refuses images wider than ~32767 px; the cap is on PIXELS — a 650 px cell allows only 49 cells (2026-09-09 wolf idle: 64 cells = 41,664 px, unrenderable)
STRIP_MAX_HEIGHT = 520
SEAM_RATIO_MAX = 2.0 # loop seam / mean adjacent distance inside the cycle
-SPECK_MIN_FRACTION = 0.01 # detached components smaller than this fraction of the body are keying specks
PERIODICITY_MIN = 0.15 # the period must dip at least 15% below the profile mean (flat profile = no repeat)
# Where the gait fallback writes the frames it scaled back (removed once the strip is built).
FALLBACK_FRAMES_DIR = ".gait-fallback-frames"
@@ -553,40 +552,6 @@ def pinned_cycle(D: np.ndarray, *, seam_max: float) -> dict[str, Any]:
"pin_tolerance": max(seam_max * inner, PIN_NOISE_MAX), "period_global": None, "periodicity": None}
-def _drop_specks(image: Image.Image, min_fraction: float) -> tuple[Image.Image, int]:
- """Erase detached alpha components smaller than `min_fraction` of the largest one."""
- a = np.asarray(image)[..., 3] > 16
- H, W = a.shape
- seen = np.zeros_like(a, dtype=bool)
- comps: list[list[tuple[int, int]]] = []
- for y in range(H):
- for x in range(W):
- if a[y, x] and not seen[y, x]:
- q = deque([(y, x)])
- seen[y, x] = True
- pts: list[tuple[int, int]] = []
- while q:
- cy, cx = q.popleft()
- pts.append((cy, cx))
- for dy, dx in ((1, 0), (-1, 0), (0, 1), (0, -1)):
- ny, nx = cy + dy, cx + dx
- if 0 <= ny < H and 0 <= nx < W and a[ny, nx] and not seen[ny, nx]:
- seen[ny, nx] = True
- q.append((ny, nx))
- comps.append(pts)
- if not comps:
- return image, 0
- big = max(len(c) for c in comps)
- px = image.load()
- dropped = 0
- for c in comps:
- if len(c) < max(8, big * min_fraction):
- for y, x in c:
- px[x, y] = (0, 0, 0, 0)
- dropped += 1
- return image, dropped
-
-
def _scrub(image: Image.Image) -> int:
px = image.load()
n = 0
@@ -1245,10 +1210,12 @@ def run_loop(
scrubbed = specks = 0
for k, f in enumerate(files[i : i + L]):
im = Image.open(f).convert("RGBA")
- # Motion review is pixel preserving: cleanup belongs to the keyed input.
+ # Motion review is pixel preserving: cleanup belongs to the keyed input (`video-frames` erases
+ # the specks far from the body). The other cuts erase every loose piece of solid pixels under
+ # the speck size, wherever it is: the outline's islands and a drawn shadow as well.
if anchor not in ("motion", "motion-auto"):
scrubbed += _scrub(im)
- im, d = _drop_specks(im, SPECK_MIN_FRACTION)
+ im, d = drop_specks(im, alpha_over=16, diagonal=False, apart=0)
specks += d
frames.append(im)
diff --git a/tests/video/test_edge_speck_lead_in.py b/tests/video/test_edge_speck_lead_in.py
new file mode 100644
index 0000000..e375277
--- /dev/null
+++ b/tests/video/test_edge_speck_lead_in.py
@@ -0,0 +1,109 @@
+# SPDX-License-Identifier: Apache-2.0
+"""A fleck far from the body is not the subject touching the edge.
+
+* `video-frames` erases a speck — a small piece far from the body — before the edge check reads the frame.
+"""
+from __future__ import annotations
+
+import json
+import math
+import shutil
+from pathlib import Path
+
+import numpy as np
+import pytest
+from PIL import Image
+
+from sprite_gen.video import align, canvas, frames as frames_mod, gait_fallback, loop
+from tests.video import test_gait_fallback as walks
+
+MAGENTA = (255, 0, 255)
+BODY = (180, 60, 30)
+FLECK = (255, 180, 220) # a pale pink the magenta matte keeps, not the key's hue
+
+
+# --- the key stage's specks ---------------------------------------------------------------------------------
+
+
+def _raw(tmp_path: Path, n: int, paint) -> list[Path]:
+ """`n` frames of a 30 x 70 body on magenta, `paint(k, image)` adding to frame k."""
+ d = tmp_path / "raw"
+ d.mkdir()
+ files = []
+ for k in range(n):
+ image = Image.new("RGB", (120, 100), MAGENTA)
+ image.paste(BODY, (20, 20, 50, 90))
+ paint(k, image)
+ files.append(d / f"frame-{k:04d}.png")
+ image.save(files[-1])
+ return files
+
+
+def test_a_fleck_far_from_the_body_is_erased_before_the_edge_check(tmp_path):
+ # Five pale pixels crossing the right edge band in one frame, 66 px from a body 70 px tall: the edge
+ # check read them as the subject framed too tight, and the clip was sent back for a wider canvas.
+ def fleck(k, image):
+ if k == 1:
+ image.paste(FLECK, (116, 50, 119, 51))
+ image.paste(FLECK, (117, 51, 119, 52))
+ files = _raw(tmp_path, 3, fleck)
+ report = frames_mod.key_frames(files, tmp_path / "keyed", key="magenta")
+ assert report["edge_contacts"] == [] and report["edge_policy"] == "refuse"
+ assert [row["specks"] for row in report["rows"]] == [0, 1, 0]
+ assert report["specks"]["dropped"] == 1 and report["specks"]["frames"] == 1
+ keyed = Image.open(tmp_path / "keyed" / "frame-0001.png").convert("RGBA")
+ assert keyed.getpixel((117, 50))[3] == 0 and keyed.getpixel((35, 50))[3] == 255
+ assert all(row["edge"] == {"top": 0, "left": 0, "right": 0} for row in report["rows"])
+
+
+def test_small_pieces_near_the_body_and_a_large_one_far_from_it_are_the_subjects(tmp_path):
+ # A small shadow drawn 2 px under the feet, a loose pixel one off the outline (both under the speck
+ # size, 21 px here), and a block far from the body but too large to be a speck: all kept.
+ def pieces(k, image):
+ image.paste((40, 40, 40), (30, 92, 40, 93))
+ image.putpixel((51, 40), (200, 50, 50))
+ image.paste((60, 160, 60), (80, 30, 100, 60))
+ files = _raw(tmp_path, 2, pieces)
+ report = frames_mod.key_frames(files, tmp_path / "keyed", key="magenta")
+ assert [row["specks"] for row in report["rows"]] == [0, 0] and report["specks"]["dropped"] == 0
+ keyed = Image.open(tmp_path / "keyed" / "frame-0000.png").convert("RGBA")
+ assert keyed.getpixel((35, 92))[3] > 0 and keyed.getpixel((51, 40))[3] > 0 and keyed.getpixel((90, 45))[3] > 0
+
+
+def test_the_loop_cut_reads_its_loose_pieces_as_before():
+ """`video-loop`'s own pass on a cut that is not motion-reviewed: every island of solid pixels (alpha over
+ 16, side by side) under the speck size, wherever it is — the outline's islands and a drawn shadow too."""
+ image = Image.new("RGBA", (60, 60), (0, 0, 0, 0))
+ image.paste((200, 0, 0, 255), (10, 5, 40, 45)) # 1200 px: a speck is under 12
+ image.paste((40, 40, 40, 255), (12, 48, 22, 49)) # a 10 px shadow, 3 px under the body
+ image.putpixel((41, 20), (200, 0, 0, 255)) # one transparent column off the body
+ image.putpixel((42, 21), (200, 0, 0, 255)) # ... joined to the pixel above only at a corner
+ cut, dropped = frames_mod.drop_specks(image.copy(), alpha_over=16, diagonal=False, apart=0)
+ assert dropped == 3 and all(cut.getpixel(xy)[3] == 0 for xy in ((15, 48), (41, 20), (42, 21)))
+ assert cut.getpixel((20, 20))[3] == 255
+ # The key stage keeps all three: within a tenth of the body's height of it.
+ keyed, kept = frames_mod.drop_specks(image)
+ assert kept == 0 and keyed is image
+
+
+def test_a_motion_auto_loop_of_a_clip_with_a_fleck_is_cut_without_it(tmp_path):
+ # The fleck drifts across the background far from the walker, never into the edge band: keyed and cut
+ # with `--anchor motion-auto`, which never cleans a frame, the cells are only as wide as the walker.
+ raw = tmp_path / "raw"
+ raw.mkdir()
+ files = []
+ for k in range(73):
+ image = Image.new("RGBA", (280, 180), MAGENTA + (255,))
+ image.alpha_composite(walks.walker(k))
+ x = 250 - 2 * (k % 25)
+ image = image.convert("RGB")
+ image.paste(FLECK, (x, 40, x + 3, 42))
+ files.append(raw / f"frame-{k:04d}.png")
+ image.save(files[-1])
+ report = frames_mod.key_frames(files, tmp_path / "keyed", key="magenta")
+ assert all(row["specks"] == 1 for row in report["rows"])
+ out = loop.run_loop(tmp_path / "keyed", tmp_path / "out", fps=24.0, state="walk", min_len=None, max_len=None,
+ n_out=None, seam_max=loop.SEAM_RATIO_MAX, name="w", report_path=None, anchor="motion-auto",
+ repair="off")
+ walker_width = walks.walker(0).getchannel("A").getbbox()
+ assert out["strip"]["w"] <= walker_width[2] - walker_width[0] + 2 * 8 + 8 # the walker, its margins, a little sway
diff --git a/tests/video/test_video_pipeline.py b/tests/video/test_video_pipeline.py
index 17fc224..edf23ac 100644
--- a/tests/video/test_video_pipeline.py
+++ b/tests/video/test_video_pipeline.py
@@ -472,7 +472,7 @@ def test_drop_specks_erases_detached_slivers_only() -> None:
im.putpixel((x, y), (200, 0, 0, 255))
im.putpixel((0, 0), (200, 0, 0, 255)) # a 1-px speck
im.putpixel((1, 0), (200, 0, 0, 255))
- out, dropped = loop_mod._drop_specks(im, 0.01)
+ out, dropped = frames_mod.drop_specks(im, alpha_over=16, diagonal=False, apart=0) # the loop cut's reading
assert dropped == 1 and out.getpixel((0, 0))[3] == 0 and out.getpixel((20, 20))[3] == 255