Comfy-Org / Comfy-Org/ComfyUI

Resize Image/Mask loses the batch layout when Lanczos resizes a mask to one row

Open Beginner friendly
#16,208 0 comments 0 reactions 0 assignees View on GitHub
Potential Bug
Dominant language
Python
Stars
133k
Forks
15.7k
Avg merge
1d 7h
Merged PRs (30d)
158

Description

### Custom Node Testing

- [ ] I have tried disabling custom nodes and the issue persists (see [how to disable custom nodes](https://docs.comfy.org/troubleshooting/custom-node-issues#step-1%3A-test-with-all-custom-nodes-disabled) if you need help)

### Expected Behavior

Resizing two masks to 16×1 should return a mask tensor shaped `(2, 1, 16)`. Passing it to MaskToImage should produce two images shaped `(2, 1, 16, 3)`.

### Actual Behavior

ResizeImageMask returns `(2, 16)` with Lanczos. MaskToImage then interprets this as one mask and returns `(1, 2, 16, 3)`, merging the two batch items into one two-row image.

The grayscale path in `comfy.utils.lanczos` returns `[B, H, W]` instead of restoring `[B, 1, H, W]`. The resize node then squeezes dimension 1, which removes the height when it is 1.

### Steps to Reproduce

Run this from the ComfyUI checkout with its Python dependencies installed. It calls only the built-in nodes on CPU. Reproduced on current master `6f3895ed8d1e0f1d5fad11b48b3f159f7de1cc15` (0.35.0).

```python
from comfy.cli_args import args
args.cpu = True

import torch
from comfy_extras.nodes_post_processing import ResizeImageMaskNode, ResizeType
from comfy_extras.nodes_mask import MaskToImage

mask = torch.ones(2, 8, 16)
resized = ResizeImageMaskNode.execute(mask, "lanczos", {
"resize_type": ResizeType.SCALE_DIMENSIONS,
"width": 16,
"height": 1,
"crop": "disabled",
}).result[0]
print("resized mask:", tuple(resized.shape))
print("converted image:", tuple(MaskToImage.execute(resized).result[0].shape))
```

### Debug Logs

```powershell
torch/jit/_script.py:1491: FutureWarning: `torch.jit.script` is deprecated. Please switch to `torch.compile` or `torch.export`.
warnings.warn(
resized mask: (2, 16)
converted image: (1, 2, 16, 3)
```

### Other

Windows, Python 3.12.14, PyTorch 2.14.0+cpu, Pillow 12.3.0.

Related history: #12679 fixed transposed width/height for grayscale Lanczos output, but the channel axis is still missing. This report covers the remaining shape loss.

Contributor guide

Open the contributing guide

Research direction

Start with the grayscale path in comfy.utils.lanczos and ResizeImageMaskNode in comfy_extras/nodes_post_processing.py, using the supplied CPU reproduction as the first check. The fix is complete when resizing a two-item mask to 16×1 preserves the channel dimension and MaskToImage returns shapes (2, 1, 16) and (2, 1, 16, 3).

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
computer-vision
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
84/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.