High-Resolution People Removal (remove-people)
Use this skill whenever a user asks to remove people (or similar unwanted subjects) from a photograph without altering anything else, especially when preserving high/native resolution (e.g., 12–60+ MP camera exports), original framing, color grading, and pixel-level fidelity outside the edited regions.
Core principle: Never run a full high-resolution photograph directly through a ~1 MP image generator and return that output. Full-frame generation degrades resolution, shifts structural geometry (horizons, curbs, lines), and alters global color/grain. Instead, extract native-resolution localized patches around the people, inpaint each patch at ≥1× native pixel density, sub-pixel align and color-match each patch, and composite only the tight feathered people + shadow masks back onto the untouched original.
Bundled Helper Script
Retrieve scripts/patch_toolkit.py using get_skill_resources (or run it directly from the skill directory). It depends only on Pillow (PIL) and provides five subcommands:
inspect <image>— checks dimensions, megapixels, EXIF orientation, and metadata, and flags likely uploader downscaling (<= 1024 px).grid <image> <out.png> [--box x0,y0,x1,y1] [--step 100] [--scale 1.0]— renders a labeled coordinate grid for accurate patch and mask coordinates.crop <image> <out.png> --box x0,y0,x1,y1— extracts a native-resolution, EXIF-oriented patch crop.align <orig_crop> <gen_crop> <out_aligned.png> [--ref x0,y0,x1,y1 ...] [--color-ref x0,y0,x1,y1 ...] [--diff out_diff.png]— finds optimal(dw, dh, dx, dy)alignment on unoccluded reference regions, applies subtle per-channel color-gain matching, and outputs an amplified4×diff map.composite <orig_image> <out_image> --config composite.json [--diff out_diff.png]— composites tight feathered masks (with optional hard-edge foreground occluder protection) onto the untouched original, preserves EXIF/ICC/DPI, and prints the exact-zero-change pixel percentage.
Step-by-Step Workflow
Step 1: Inspect the Source File & Catch Uploader Downscaling
- View the image with
view_fileand run:python3 patch_toolkit.py inspect <input_image> - Check for attachment downscaling: Chat uploaders frequently downscale raw image attachments to
<= 1024 pxon the long edge and strip EXIF.- If the user expects high-resolution output (e.g. 12–20+ MP) and the staged file is
<= 1024 px, tell them immediately and ask them to upload the original inside a.ziparchive (which bypasses image upload resizing). - If the input is a
.zip, extract it, clean up macOS__MACOSXartifacts if present, and verify the extracted dimensions.
- If the user expects high-resolution output (e.g. 12–20+ MP) and the staged file is
- Always normalize orientation consistently via
ImageOps.exif_transpose(handled automatically bypatch_toolkit.py) before measuring coordinates.
Step 2: Map Every Person, Shadow, and Occluder on a Coordinate Grid
- Generate a labeled coordinate grid over the affected area (or full image if people are scattered):
python3 patch_toolkit.py grid <input_image> scratch/grid.png --box x0,y0,x1,y1 --step 100 --scale 0.5 - View
scratch/grid.pngand inventory:- Every foreground person and background person (including tiny distant figures and partial limbs/clothing peeking between objects).
- Cast shadows on the ground/tiles/walls belonging to those people, plus personal belongings they are holding or sitting on.
- Hard foreground occluders adjacent to people (iron gates, sign edges, pillars, railings, window frames) that must stay razor-sharp and untouched.
- Clean unoccluded gaps between groups of people where separate patches can terminate without ever overlapping masked content.
Step 3: Plan Native-Resolution, Non-Splitting Patches
Design one or more rectangular crop boxes around the people following these rules:
- Match native pixel density (
>= 1.0×oversampling):generate_imagetypically outputs ~1024–1264 pxon the long edge (1200×896for4:3,1264×848for3:2,1024×1024for1:1).- Size each crop box to
~800–1000 pxon the long edge (in native photo pixels) matching a supportedgenerate_imageAspectRatio(1:1,4:3,3:2,3:4,2:3). - This guarantees the inpainted pixels are
1.1×–1.3×oversampled relative to the native image—zero blur or resolution drop at 100% zoom. - For low-resolution inputs (
< 1000 pxwide), a single localized crop around the people band is sufficient.
- Never split a foreground person across two patches: Every person (or tightly overlapping crowd cluster) should sit comfortably inside a single patch.
- Include strong geometric anchors on all sides: Leave
>= 10–20%unoccluded margin above, below, and beside the people (tile seams, curbs, horizons, foliage, brickwork, frames) so the generator preserves exact perspective and alignment has crisp reference zones. - Extract crops:
python3 patch_toolkit.py crop <input_image> scratch/patch1_orig.png --box x0,y0,x1,y1
Step 4: Inpaint Each Patch with Strict Fidelity Constraints
Invoke generate_image (in parallel across patches) passing ImagePaths: [".../scratch/patchN_orig.png"] and the exact matching AspectRatio.
Craft each prompt with these explicit requirements:
- Enumerate the specific people, background figures, and cast shadows present in that patch.
- Specify exactly what natural background should replace them (e.g., continuing exact perspective tile joints, curb height, fallen leaves, tree trunks, brickwork).
- Explicitly forbid moving, shifting, cropping, recoloring, relighting, softening, or adding new objects (no invented pillars, signs, benches, etc.).
- Instruct the model to keep lighting, contrast, sharpness, and photographic grain identical to the original crop.
Step 5: Sub-Pixel Alignment, Diff Verification & Color-Gain Matching
Generative outputs often have slight aspect rounding (e.g., 1200×896 vs exact 4:3 1200×900, causing a ~4 px height/offset shift) and tiny ~0.5–1.5% brightness drift.
- Run
alignon each patch using unoccluded--refboxes (e.g., clean pavement below and clean foliage/sky above the people) and an unoccluded--color-refbox (typically smooth neutral ground/pavement/wall where seams would be most visible):python3 patch_toolkit.py align scratch/patch1_orig.png <gen_patch1.jpg> scratch/patch1_aligned.png \ --ref x0,y0,x1,y1 --ref x0,y0,x1,y1 \ --color-ref x0,y0,x1,y1 \ --diff scratch/patch1_diff.png - Inspect the
4×diff map (scratch/patchN_diff.png) viaview_file:- Pass criterion: Structural lines (tile seams, curbs, horizons, branches, frames) outside the people are nearly black (mean abs diff typically
<= 6–8on smooth surfaces), and only the people + their cast shadows light up brightly. - Fail criterion: If structural lines shifted significantly or the generator hallucinated unwanted objects, regenerate that patch with tighter anchor instructions before proceeding. Never composite a geometrically shifted patch.
- Pass criterion: Structural lines (tile seams, curbs, horizons, branches, frames) outside the people are nearly black (mean abs diff typically
Step 6: Build Tight Feathered Masks & Composite onto the Untouched Original
- Create a
scratch/composite.jsonconfig defining each patch's globalbox,aligned_path, tightshapes(in global image coordinates covering only the people + cast shadows),featherradius (typically~3–5 pxfor ~1K images,~8–12 pxfor 15–30 MP images), and optionalprotect_polygons+protect_feather(1–3 px) to keep adjacent hard foreground occluders (gates, signs, poles) 100% untouched:Supported shape types:{ "patches": [ { "box": [540, 3720, 1500, 4440], "aligned_path": "/abs/path/scratch/patch1_aligned.png", "feather": 10, "protect_feather": 2.5, "shapes": [ {"type": "rounded_rect", "box": [648, 3835, 845, 4345], "radius": 24}, {"type": "rounded_rect", "box": [815, 3955, 1115, 4195], "radius": 20} ], "protect_polygons": [ [[540, 3720], [663, 3720], [652, 4440], [540, 4440]] ] } ] }rounded_rect,rect,ellipse,polygon. - Whenever possible, keep each patch's masked islands separated across clean unoccluded gaps so adjacent patches never fight over conflicting hallucinated backgrounds. If two patches must share a masked region, cross-fade smoothly in an overlap zone where both patches match.
- Run the composite:
python3 patch_toolkit.py composite <input_image> <output_image> \ --config scratch/composite.json --quality 96 \ --diff scratch/final_diff.png- Preserves original resolution, EXIF, DPI, and ICC color profile (
subsampling=0for JPEG).
- Preserves original resolution, EXIF, DPI, and ICC color profile (
Step 7: 1:1 Native Zoom & Diff QA Before Delivery
Always visually inspect before delivering to the user:
- Crop
1:1native-resolution views of every edited region (around600–900 pxwide) and inspect them withview_filefor:- Any missed background person, shoe, limb, or ghost cast shadow.
- Any visible brightness/color transition seam across flat tiles, walls, or sky.
- Any misalignment or kink in straight lines (tile joints, curbs, railings).
- Any bleed or halo over adjacent protected foreground edges.
- Inspect
scratch/final_diff.png(8×amplified) and verify the reportedExact-zero-change pixelspercentage (typically>85–95%for street/architecture photos) confirms literally nothing outside the people + shadows changed. - If any minor defect appears (e.g., a stray cast shadow outside the mask or a slightly tight mask edge), adjust
composite.jsonand re-runcompositein seconds—no need to re-rungenerate_image.
Step 8: Deliver Clearly
- Save the final full-resolution image in the workspace alongside the original (e.g.,
<stem>_no_people.<ext>). - Copy the final image (and optionally a zoomed comparison strip of the edited zone) into the conversation artifact directory and present it in a clean user-facing markdown artifact so the user can inspect the true composited result directly (rather than only intermediate
generate_imagepatches). - State the exact output resolution, preserved metadata, and untouched-pixel percentage concisely.