Meux Mask Loader
Load a mask and force it to match your image's size
- reference_image
- mask
The most annoying thing about hand-feeding masks into ComfyUI is the size mismatch. You've got a 1024×1024 image, a mask that's 512×512, and now every inpaint or compositing node downstream is throwing shape errors or silently doing something weird. MeuxMaskLoader exists to kill that specific pain: it loads a mask (local file or URL, like its sibling MeuxImageLoader) and, crucially, requires you to plug in a reference_image so the mask can be resized to match. No reference, no run - the node raises a clear error if you forget.
How it works
Everything about the local/URL loading is inherited from the pack's image loader: same download caching to ComfyUI/input/meux_downloads, same download_timeout / max_download_mb / verify_ssl trio, same URL-hash filename scheme. The mask-specific logic happens after the image is in hand.
First it extracts a mask from whatever you loaded, using the mask_channel selector. alpha_or_luminance (the default) is the smart pick: it uses the alpha channel when the file has one, otherwise falls back to grayscale luminance. You can also force alpha, luminance, or a specific red/green/blue channel if you loaded a color image that encodes the mask in one band.
Then comes the part that makes this node worth installing: if the extracted mask isn't the same size as reference_image, it's resized with nearest-neighbor interpolation to match - fast, and it preserves hard mask edges instead of smearing them like bilinear would. resize_to_reference defaults to on. Turn it off if you'd rather get an explicit size-mismatch error than a resized mask.
The mask_invert toggle handles the other classic gotcha, and you'll flip it at least once.
The inversion trap
This is where people burn five minutes. For the alpha path, the node outputs 1 - alpha - white where the image is transparent, not where it's opaque. That's deliberate and matches how ComfyUI's inpainting masks work (white = the region to regenerate), but it's the opposite of what you get from a typical cutout PNG where opaque = subject. If your mask comes out backwards - subject white instead of background - hit mask_invert. Note the luminance path doesn't invert, so behavior differs by channel. Just know the toggle exists and check it on your first run.
Inputs and outputs
The ones you'll actually touch:
reference_image(IMAGE, required) - plug the image the mask belongs to. This is what the mask gets aligned to.source_type+mask_image/mask_url- same local-or-URL switch as the image loader.mask_channel-alpha_or_luminanceis fine for most files; go specific if you know the mask lives in a particular channel.mask_invertandresize_to_reference- the two toggles that fix real-world files.
Single output: mask (MASK), native ComfyUI format. The README's recommended wiring is MeuxImageLoader.image into this node's reference_image, then the resulting mask into whatever mask pipeline you're running. It plays nicely with the pack's MeuxMaskFillHoles if the loaded mask has holes.
Installing and pitfalls
Install is the whole pack:
cd ComfyUI/custom_nodes
git clone https://github.com/fchangjun/Baidu_Meux_ComfyTools.git
cd Baidu_Meux_ComfyTools
pip install -r requirements.txt
Restart ComfyUI after. Or use ComfyUI Manager and search "Baidu Meux ComfyTools".
The shared pack caveat applies here too: the requirements pull in transformers, torchvision, realesrgan and scipy even though mask loading only needs Pillow and numpy - heavy for a loader, and the usual source of version conflicts with other packs. And remember the size-mismatch error message is in Chinese ("遮罩尺寸...与 reference_image 尺寸...不一致"); if you see it, either turn resize_to_reference on or resize upstream.
Inputs (13)
| Name | Type | Default | Description |
|---|---|---|---|
| reference_image | IMAGE | — | |
| source_type | COMBO | local | 2 options: local, url |
| mask_image | COMBO | 1 options: example.png | |
| mask_urlopt | STRING | — | |
| filename_hintopt | STRING | — | |
| persist_to_inputopt | BOOLEAN | true | — |
| overwrite_existingopt | BOOLEAN | false | — |
| download_timeoutopt | FLOAT | 10.001–120 | — |
| max_download_mbopt | FLOAT | 20.001–200 | — |
| verify_sslopt | BOOLEAN | true | — |
| mask_channelopt | COMBO | alpha_or_luminance | 6 options: alpha_or_luminance, luminance, alpha, red, green, blue |
| mask_invertopt | BOOLEAN | false | — |
| resize_to_referenceopt | BOOLEAN | true | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |