From cdbb3155b7b8aa4a1d2256ab391466a77e1d39fb Mon Sep 17 00:00:00 2001 From: Edoardo Carmignani Date: Fri, 27 Feb 2026 17:46:26 +0100 Subject: [PATCH] fix(lanczos): correct dimension transposition for single-channel tensors movedim(-1, 0) on a 2D [H, W] tensor (grayscale/mask case) was swapping spatial dimensions instead of adding a channel axis, causing output masks to have width and height inverted when using the lanczos scale method. --- comfy/utils.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/comfy/utils.py b/comfy/utils.py index 0769cef44..690d94102 100644 --- a/comfy/utils.py +++ b/comfy/utils.py @@ -993,10 +993,11 @@ def bislerp(samples, width, height): def lanczos(samples, width, height): #the below API is strict and expects grayscale to be squeezed - samples = samples.squeeze(1) if samples.shape[1] == 1 else samples.movedim(1, -1) + if samples.ndim == 4: + samples = samples.squeeze(1) if samples.shape[1] == 1 else samples.movedim(1, -1) images = [Image.fromarray(np.clip(255. * image.cpu().numpy(), 0, 255).astype(np.uint8)) for image in samples] images = [image.resize((width, height), resample=Image.Resampling.LANCZOS) for image in images] - images = [torch.from_numpy(np.array(image).astype(np.float32) / 255.0).movedim(-1, 0) for image in images] + images = [torch.from_numpy(t).movedim(-1, 0) if (t := np.array(image).astype(np.float32) / 255.0).ndim == 3 else torch.from_numpy(t) for image in images] result = torch.stack(images) return result.to(samples.device, samples.dtype)