TS Crop To Mask
Crop to the interesting part, process only that
- images
- mask
- cropped_images
- cropped_masks
- crop_data
- width
- height
The crop-and-restore pattern is one of the oldest tricks in the book: instead of running a heavy model over a whole 4K frame, crop to the region that actually matters - a face, an object - process just that at full detail, then paste it back. It's how you get an 8K face from a model that caps at 1K. TS Crop To Mask is the front half of that workflow: it crops a batch of images around a mask region, with padding, a resolution clamp, fixed aspect, and - the part most crop nodes skip - inter-frame smoothing for video.
You pair it with the pack's TS Restore From Crop, which pastes the processed crop back into the original frame with feathered seams. The README's framing is the use case: "running an upscaler or face restorer on a small ROI of a high-resolution image without burning VRAM on the full frame." The inpainting doc's crop-and-stitch discussion is the same idea from a different angle - process only the masked region, leave everything else untouched.
How it works
You feed it images and a mask. The node finds the bounding box of the mask's non-zero area, pads it by padding pixels, crops the images to that box, and rounds the crop up to a multiple of divide_by (default 32 - the VAE-friendly size). max_resolution caps the shorter side, so a huge region gets downscaled to fit - that's the VRAM guard.
The two interesting controls are the video ones:
fixed_mask_frame_index- default 0 means per-frame crops (the mask moves each frame). Set it to a 1-based frame index and the whole batch uses that one frame's mask as a fixed crop. That's how you keep a talking head stable - the crop doesn't chase the mask around.interpolation_window_size- averages crop geometry over N neighboring frames, smoothing crop motion. 0 is off. For video, this is the difference between a crop that glides and one that judders.
There's also fixed_crop_size + fixed_width/fixed_height if you want every crop forced to a specific aspect ratio regardless of the mask.
The outputs
cropped_imagesandcropped_masks- the processed region, ready for your upscaler/restorer.crop_data- the geometry blob you feed into TS Restore From Crop to paste the result back in the right place. Don't lose this wire; it's the whole "put it back" contract.width/height- the crop's dimensions, for downstream sizing.
Installing it
Part of comfyui-timesaver (ComfyUI Manager → "Timesaver", or manual clone + pip install -r requirements.txt + restart). No model files - pure tensor cropping.
Gotchas
The trap is treating it as a still-image node when you're working with video: if the mask bounces around, the crop will too. That's what fixed_mask_frame_index and interpolation_window_size exist for - set a fixed frame and smooth the window, and the crop stops swimming. And divide_by is a round-up, not a round-down: the crop can come out a bit larger than the mask bounding box, which is intentional (VAE needs the alignment) but surprises people who expected pixel-exact bounding boxes. If you crop-then-restore with a model that changes resolution (some upscalers do), check the width/height outputs against your restore node's expectations before running a long batch.
Inputs (11)
| Name | Type | Default | Description |
|---|---|---|---|
| images | IMAGE | Batch of images to crop around the mask region. | |
| mask | MASK | Mask that defines the region to crop. The bounding box of its non-zero area sets the crop. | |
| padding | INT | 640–320 | Extra pixels added around the mask bounding box before cropping. |
| divide_by | INT | 321–64 | Rounds the crop dimensions up to a multiple of this value (e.g. 32 for VAE-friendly sizes). |
| max_resolution | INT | 720320–2048 | Caps the shorter side of the crop. Larger crops are downscaled to this limit. |
| fixed_mask_frame_index | INT | 00–9999 | 1-based frame whose mask defines one fixed crop for the whole batch. 0 = per-frame crop. |
| interpolation_window_size | INT | 00–100 | Smooths crop motion across frames by averaging over this many neighbouring frames. 0 = off. |
| force_gpu | BOOLEAN | true | Run the crop on GPU when CUDA is available; otherwise falls back to CPU. |
| fixed_crop_size | BOOLEAN | false | Force every crop to the fixed_width x fixed_height aspect ratio instead of following the mask. |
| fixed_width | INT | 102464–4096 | Target crop width when fixed_crop_size is enabled. |
| fixed_height | INT | 102464–4096 | Target crop height when fixed_crop_size is enabled. |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| cropped_images | IMAGE | — |
| cropped_masks | MASK | — |
| crop_data | CROP_DATA | Crop geometry passed to TS Restore From Crop to paste the result back. |
| width | INT | Width of the cropped output. |
| height | INT | Height of the cropped output. |