Skip to content

Commit b029422

Browse files
committed
Fix linear blur in Expand/ShrinkMask too large by factor 2
* size is now consistent with other blur modes (ie. it maps to kernel size rather than radius)
1 parent ab62c98 commit b029422

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[project]
22
name = "comfyui-inpaint-nodes"
33
description = "Nodes for better inpainting with ComfyUI. Adds various ways to pre-process inpaint areas. Supports the Fooocus inpaint model, a small and flexible patch which can be applied to any SDXL checkpoint and will improve consistency when generating masked areas."
4-
version = "1.3.0"
4+
version = "1.3.1"
55
license = { file = "LICENSE" }
66

77
[project.urls]

util.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,19 @@ class BlurKernel(Enum):
110110

111111

112112
def mask_blur(mask: Tensor, size: int, method=BlurKernel.gaussian):
113+
if size <= 2:
114+
return mask
113115
if method is BlurKernel.gaussian:
114116
return gaussian_blur(mask, size)
115117

116-
match method:
117-
case BlurKernel.box:
118+
match method, size:
119+
case BlurKernel.box, _:
118120
kernel = torch.ones(1, size, device=mask.device) / size
119-
case BlurKernel.linear:
120-
kernel = torch.linspace(1 / size, (size - 1) / size, size, device=mask.device)
121+
case BlurKernel.linear, 3:
122+
kernel = torch.ones(1, size, device=mask.device) / size
123+
case BlurKernel.linear, _:
124+
h = size // 2
125+
kernel = torch.linspace(1 / h, (h - 1) / h, h, device=mask.device)
121126
kernel = torch.cat([kernel, torch.ones(1, device=mask.device), kernel.flip(0)])
122127
kernel = kernel / kernel.sum()
123128
kernel = kernel.unsqueeze(0)

0 commit comments

Comments
 (0)