Nodes/comfyUI-TiledWan/TiledWan Inpaint Crop Improved
ComfyUI Node

TiledWan Inpaint Crop Improved

Inpaint moving objects in video without the flicker

By Baverne·Created about a year ago·Updated 7 months ago· 8
TiledWan Inpaint Crop Improved
  • image
  • mask
  • optional_context_mask
  • stitcher
  • cropped_image
  • cropped_mask
downscale_algorithmbilinear
upscale_algorithmbicubic
preresizefalse
preresize_modeensure minimum resolution
preresize_min_width1024
preresize_min_height1024
preresize_max_width16384
preresize_max_height16384
mask_fill_holestrue
mask_expand_pixels0
mask_invertfalse
mask_blend_pixels32
mask_hipass_filter0.10
extend_for_outpaintingfalse
extend_up_factor1.00
extend_down_factor1.00
extend_left_factor1.00
extend_right_factor1.00
context_from_mask_extend_factor1.20
output_resize_to_target_sizetrue
output_target_width512
output_target_height512
output_padding32
keep_window_sizefalse

If you've ever tried to inpaint a moving object across a video one frame at a time, you know the specific misery this node exists to fix: the mask slides around, so every frame crops a different region, and the result strobes like a broken neon sign. TiledWan Inpaint Crop Improved is the crop half of a two-node inpainting pair that solves it by thinking in video, not single images.

It's one of six nodes in Baverne's comfyUI-TiledWan pack, which exists to push Wan 2.1 VACE video inpainting past its native 832×480 / 81-frame wall (the TiledWan Video VACE Pipeline article covers that half). The crop node is a rework of lquesada's ComfyUI-Inpaint-CropAndStitch - the pack that made "crop, inpaint, stitch" the standard way to guarantee unmasked pixels stay untouched. Where the original assumed stills, this one was rebuilt for batches: per the pack README, it ignores size variation (which caused inconsistencies) and handles masks that appear and disappear over time.

How it works: you feed it a batch of frames plus a mask. It finds the tight box around the masked area, expands it into a context region, then runs a preprocessing chain on the mask - fill holes, expand by N pixels, optional invert, a feathered blur, and a high-pass threshold that kills weak or noisy mask values. Optionally it extends the canvas for outpainting and preresizes the input to a sane range. Finally it resizes the crop to your inpainting model's preferred resolution, pads it to a multiple you choose, and packages everything into a stitcher record so the matching TiledWan Inpaint Stitch Improved can put it back exactly.

The one setting that makes it video-aware is keep_window_size. Instead of letting each frame pick its own crop box, the node takes the largest window across the batch, forces every frame to use it, and linearly interpolates the box's position frame to frame. That's the anti-flicker trick, and it's why you should have it on whenever you're feeding actual footage.

The few inputs you'll actually touch:

  • keep_window_size - on for video, off for stills
  • context_from_mask_extend_factor (default 1.2) - how much surrounding context to keep. More helps the model understand the scene; too much just wastes generation budget
  • output_target_width / output_target_height (default 512×512) - set these to your model's native resolution; 832×480 if you're feeding Wan VACE
  • output_padding - keep it a multiple of 8 for VAE, 32 for many diffusion models

It also takes an optional mask (if you leave it empty, the whole image gets processed) and an optional_context_mask if you want to force areas into the crop without inpainting them.

Outputs: stitcher (STITCHER), cropped_image (IMAGE), and cropped_mask (MASK). Wire the image and mask into your inpainting stage, then feed the result plus stitcher into TiledWan Inpaint Stitch Improved. Depending on the build you have, the node may also expose a row of DEBUG outputs showing each intermediate stage - they're the author's debugging aids, and you can ignore them.

Install is the pack install: ComfyUI Manager (search "comfyUI-TiledWan"), or cd ComfyUI/custom_nodes && git clone https://github.com/Baverne/comfyUI-TiledWan, then restart. The pack declares no extra pip dependencies.

Two gotchas worth knowing. First, there's a guard: if you feed a batch without keep_window_size, output_resize_to_target_size must be on, because every frame in a batch has to come out the same size. Second, an unedited mask straight from Load Image sometimes arrives at the wrong shape; the node detects and fixes that, but a manually painted mask is more trustworthy - give it a clean pass before you commit to a long render.

Categoryinpaint

Inputs (27)

NameTypeDefaultDescription
imageIMAGEInput image(s) to be processed. Can be a single image or batch of images for video processing.
downscale_algorithmCOMBObilinearAlgorithm used when downscaling images. Bilinear provides good balance of quality and speed.
upscale_algorithmCOMBObicubicAlgorithm used when upscaling images. Bicubic provides better quality for upscaling.
preresizeBOOLEANfalseEnable to resize the original image before processing. Useful for normalizing input sizes.
preresize_modeCOMBOensure minimum resolutionMode for pre-resizing: minimum ensures image is at least the specified size, maximum caps the size, both enforces a range.
preresize_min_widthINT10240–16384Minimum width for pre-resize operation. Image will be upscaled if smaller.
preresize_min_heightINT10240–16384Minimum height for pre-resize operation. Image will be upscaled if smaller.
preresize_max_widthINT163840–16384Maximum width for pre-resize operation. Image will be downscaled if larger.
preresize_max_heightINT163840–16384Maximum height for pre-resize operation. Image will be downscaled if larger.
mask_fill_holesBOOLEANtrueFill holes in the mask using iterative morphological operations. Helps create more complete masked regions.
mask_expand_pixelsINT00–16384Expand the mask by this many pixels before processing. Useful for including more context around masked areas.
mask_invertBOOLEANfalseInvert the mask so that masked areas become unmasked and vice versa.
mask_blend_pixelsINT320–64Create a soft transition zone around mask edges. Higher values create smoother blending during stitching.
mask_hipass_filterFLOAT0.100–1Remove mask values below this threshold. Helps eliminate weak mask areas and noise.
extend_for_outpaintingBOOLEANfalseExtend the image canvas for outpainting. Adds padding around the image for generating content beyond original boundaries.
extend_up_factorFLOAT1.000.01–100Factor to extend image upward. 1.0 = no extension, 1.5 = 50% extension upward.
extend_down_factorFLOAT1.000.01–100Factor to extend image downward. 1.0 = no extension, 1.5 = 50% extension downward.
extend_left_factorFLOAT1.000.01–100Factor to extend image leftward. 1.0 = no extension, 1.5 = 50% extension leftward.
extend_right_factorFLOAT1.000.01–100Factor to extend image rightward. 1.0 = no extension, 1.5 = 50% extension rightward.
context_from_mask_extend_factorFLOAT1.201–100Expand the context area around the mask by this factor. 1.2 = 20% expansion in all directions. Larger values include more surrounding context for better inpainting.
output_resize_to_target_sizeBOOLEANtrueResize the output to specific dimensions. When disabled, output size depends on mask area and extend factor.
output_target_widthINT51264–16384Target width for output image when resize to target size is enabled. Should match your inpainting model's preferred resolution.
output_target_heightINT51264–16384Target height for output image when resize to target size is enabled. Should match your inpainting model's preferred resolution.
output_paddingCOMBO32Padding to ensure output dimensions are multiples of this value. Important for models that require specific dimension alignment (e.g., 8 for VAE, 32 for some diffusion models).
keep_window_sizeBOOLEANfalseMaintain consistent crop window size across all images in batch. Essential for video processing to avoid flickering. Uses maximum dimensions found and interpolates missing coordinates.
maskoptMASKMask defining areas to be inpainted. White areas will be inpainted, black areas will be preserved. If not provided, the entire image will be processed.
optional_context_maskoptMASKAdditional mask defining extra context areas to include in the crop. Useful for ensuring important surrounding details are preserved during inpainting.

Outputs (3)

NameTypeDescription
stitcherSTITCHERStitcher data containing all information needed to reconstruct the original image after inpainting. Pass this to InpaintStitchImproved.
cropped_imageIMAGECropped and processed image ready for inpainting. Contains the masked area plus surrounding context.
cropped_maskMASKProcessed mask corresponding to the cropped image. Shows which areas need to be inpainted.