From bc234589e6f3bef637faec8d3bf09e29360ac8a2 Mon Sep 17 00:00:00 2001 From: aagami Date: Mon, 25 Aug 2025 14:30:50 +0300 Subject: [PATCH] Fix ImagePadForOutpaintTargetSize mask scaling bug MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When image and mask have different input dimensions and no downscaling is needed (scaling_factor >= 1), the mask was not being resized to match the image dimensions before padding, causing mismatched output sizes. Now ensures mask dimensions match image dimensions using F.interpolate with nearest-neighbor interpolation in both scaling branches. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- nodes/image_nodes.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/nodes/image_nodes.py b/nodes/image_nodes.py index 7cb9cae..3660d43 100644 --- a/nodes/image_nodes.py +++ b/nodes/image_nodes.py @@ -1137,7 +1137,13 @@ class ImagePadForOutpaintTargetSize: else: # If downscaling is not needed, use the original image dimensions image_scaled = image - mask_scaled = mask + if mask is not None: + # Ensure mask dimensions match image dimensions + mask_scaled = mask.unsqueeze(0) # Add an extra dimension for batch size + mask_scaled = F.interpolate(mask_scaled, size=(new_height, new_width), mode="nearest") + mask_scaled = mask_scaled.squeeze(0) # Remove the extra dimension after interpolation + else: + mask_scaled = mask # Calculate how much padding is needed to reach the target dimensions pad_top = max(0, (target_height - new_height) // 2)