{"record":{"id":"8ffbe2d0eef35fb5","repo":"Comfy-Org/ComfyUI","slug":"mask-must-have-the-same-aspect-ratio-as-the-image","errorCode":null,"errorMessage":"Mask must have the same aspect ratio as the image: image is {iw}x{ih}, mask is {mw}x{mh}.","messagePattern":"Mask must have the same aspect ratio as the image: image is (.+?)x(.+?), mask is (.+?)x(.+?)\\.","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"comfy_api_nodes/nodes_bria.py","lineNumber":283,"sourceCode":"        )\n        return IO.NodeOutput(await download_url_to_image_tensor(response.result.image_url))\n\n\ndef _mask_to_binary_image(mask: Input.Image, action: str) -> torch.Tensor:\n    binary = (mask > 0.5).float()\n    if not binary.any():\n        raise ValueError(\n            f\"The mask is empty, so there is nothing to {action}. Masks are binarized at 50%: \"\n            f\"areas painted at less than half opacity are ignored.\"\n        )\n    return convert_mask_to_image(binary)\n\n\ndef _validate_mask_aspect_ratio(image: Input.Image, mask: Input.Image) -> None:\n    ih, iw = image.shape[1], image.shape[2]\n    mh, mw = mask.shape[-2], mask.shape[-1]\n    if abs(iw * mh - ih * mw) > 0.01 * ih * mw:\n        raise ValueError(f\"Mask must have the same aspect ratio as the image: image is {iw}x{ih}, mask is {mw}x{mh}.\")\n\n\nclass BriaGenFill(IO.ComfyNode):\n\n    @classmethod\n    def define_schema(cls):\n        return IO.Schema(\n            node_id=\"BriaGenFill\",\n            display_name=\"Bria Generative Fill\",\n            category=\"partner/image/Bria\",\n            description=\"Generate objects or scenery inside a masked region of an image using Bria.\",\n            inputs=[\n                IO.Image.Input(\"image\"),\n                IO.Mask.Input(\n                    \"mask\",\n                    tooltip=\"White areas are filled with generated content, black areas are preserved. \"\n                    \"The mask is binarized before sending, so partially painted areas count as white. \"\n                    \"Must have the same aspect ratio as the image.\",","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/Comfy-Org/ComfyUI/blob/1c6d8d45b3693bfbb32385b410d813a7fd6be216/comfy_api_nodes/nodes_bria.py#L265-L301","documentation":"Bria's fill/erase endpoints require the mask to have the same aspect ratio as the image (within a 1% tolerance, checked as abs(iw*mh - ih*mw) > 0.01*ih*mw). A mismatched mask would be applied to the wrong pixel regions, so the node validates before upload.","triggerScenarios":"Feeding BriaGenFill/BriaErase a mask whose width/height ratio differs from the image by more than 1%: e.g. 512x512 image with a 256x512 mask, or a mask resized non-uniformly upstream.","commonSituations":"Mask painted on a different canvas size than the current image; image was resized/cropped between mask creation and the Bria node; batch image where mask matches only one frame's shape.","solutions":["Regenerate the mask at the same resolution (or same aspect ratio) as the input image.","Resize the mask to the image's exact dimensions before the node: torch.nn.functional.interpolate(mask, size=(ih, iw)).","If the image was cropped after masking, crop the mask with identical parameters."],"exampleFix":"# before\nmask = F.interpolate(mask, size=(256, 512))  # image is 512x512\n# after\n_, _, ih, iw = image.shape[-4:], image.shape[-1]\nmask = torch.nn.functional.interpolate(mask, size=(image.shape[-2], image.shape[-1]), mode='nearest')","handlingStrategy":"validation","validationCode":"ih, iw = image.shape[-2], image.shape[-1]\nmh, mw = mask.shape[-2], mask.shape[-1]\nassert abs(iw * mh - ih * mw) <= 0.01 * ih * mw, 'mask aspect ratio differs from image'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate the mask from the image itself (same canvas) rather than a separate source.","Resize masks with the same interpolation parameters as the image in any preprocessing chain."],"tags":["comfyui","bria","mask","aspect-ratio","validation"],"backgroundTag":null,"analyzedSha":"1c6d8d45b3693bfbb32385b410d813a7fd6be216","analyzedAt":"2026-08-14T19:37:18.893Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}