Crop a region, edit it big, paste it back
You give it a frame and a box around something small; it writes an enlarged crop for
the image model, then takes the model's edit and pastes back only that region. Every
pixel outside the box (and, in the default mask, every pixel the model didn't change)
stays exactly as it was. Use it whenever a fix is smaller than the frame: a whole-frame
edit garbles small lettering and every extra full-frame pass smooths grain and
background faces. The edits themselves are in nano-banana-rerender-small-print
(print and logos) and nano-banana-remove-small-object (badges, pins, stains).
Run it
Write references/crop_paste.md's script into the project folder as crop_paste.py,
unchanged, and run it with exec python. Every command prints JSON.
exec python crop_paste.py crop --image <frame> --box x0,y0,x1,y1 --scale 6 --out <job>/refs/shot09_last_crop.png
exec python crop_paste.py match-cut --image <frame> --box x0,y0,x1,y1 --other <other pinned frame> --center x,y --out <job>/refs/shot09_last_match.png
exec python crop_paste.py paste --image <frame> --box x0,y0,x1,y1 --edit <model output> [--mask changed|circle] --out <frame>_<letter>.png
exec python crop_paste.py patch-box --original <approved still> --edited <full-frame edit> --box x0,y0,x1,y1 --out <patched>.png
- Boxes are square and in the working frame's pixels. The edit is asked for at 1:1, so
a non-square box comes back stretched.
crop,match-cutandpasteconform the frame to 1920×1080 first (centre-crop to 16:9, then Lanczos) unless you pass--no-conform, which keeps the image's own pixels (a 2752×1536 2K still). Use the same choice forcropandpaste. Find the box on a gridded crop of the frame. --scale: 6 for print and logos (a 200 px box becomes 1200 px, so the prop fills the model's image), 4 for a removal (~256 px at 2K becomes 1024 px).paste --mask changed(the default, for print): the edit is shrunk back with Lanczos, and only pixels whose mean RGB difference from the crop exceeds--threshold 14(0–255) go back, grown 5 px and softened 2 px. Hands, hair and grain the model left alone stay original.paste --mask circle(for a removal): a circle centred on the box, touching its shorter side, feathered by--featherpx. Centre the box on the object. The right feather depends on the surface (a knit, skin, a flat wall): start at the default 8 px, paste two or three widths, and let the person pick on a review page before patching every frame.match-cutcuts the same prop from the shot's other pinned frame at the same scale as the box crop: the box is scaled by the zoom between the two frames, measured unless you pass--match-scale(other-frame px per this frame's px; 0.94 when this frame is pushed in 6% from the other).--centeris the prop's centre in the other frame at 1080p. Give it to the model as the print-placement reference.patch-boxis for an edit already made on the whole frame: it aligns the edit to the original (zoom about the centre plus shift), then keeps it only inside the box through a mask feathered 12 px. A whole-frame edit comes back 0.5–1% zoomed with every pixel nudged (PSNR ~23–26 dB against the approved still), so never use it unaligned.
What you get
crop: the enlarged crop plus frame_size, box, crop_size, enlarged_size and
square. paste: the patched frame plus mask_px (pixels the mask took, > 0.5) and
changed_px (pixels that differ from the input at all). match-cut: the reference and
the match_scale used. patch-box: the patched frame and the alignment
(match, zoom, shift_px) it applied.
Check it
changed_pxshould be a small patch: a badge removal changed about 9k px and left the face and grain bit-identical. A count near the whole box on a print fix means the model re-lit or re-grained the crop: re-run the edit, don't paste it.- Look at the patched frame at 100% around the box edge for a seam, and next to the input on a review page. Judge a logo at playback size too.
- For grain inside the patch, compare
python-measure-detailon the patch before and after. - After a patch, conform a
--no-conform2K result to 1080p withpython-conform-to-1080p.
Why a crop, and how the references are conditioned for it: guide-keep-small-details.


