Skip to content

Commit 217dbb3

Browse files
committed
Always add padding on top of selection bounds computed from grow/feather
* previously was not the case if feather was the minimum amount in absolute pixels * should now be added independent on how feather was computed
1 parent 469c19b commit 217dbb3

2 files changed

Lines changed: 13 additions & 9 deletions

File tree

ai_diffusion/document.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515

1616

1717
class SelectionModifiers(NamedTuple):
18+
feather_rel: float = 0.0
19+
feather_min_px: int = 0
1820
pad_rel: float = 0.0
19-
pad_min_px: int = 0
21+
pad_offset_px: int = 0
2022
size_min_px: int = 0
2123
multiple: int = 8
2224
square: bool = False
@@ -206,7 +208,9 @@ def create_mask_from_selection(self, mod: SelectionModifiers):
206208
)
207209
original_bounds = Bounds.clamp(original_bounds, self.extent)
208210
size_factor = original_bounds.extent.diagonal
209-
pad_px = max(int(mod.pad_rel * size_factor), mod.pad_min_px)
211+
pad_px = max(int(mod.feather_rel * size_factor), mod.feather_min_px)
212+
pad_px += mod.pad_offset_px
213+
pad_px += int(mod.pad_rel * size_factor)
210214

211215
if mod.invert:
212216
selection.invert()

ai_diffusion/model.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,6 @@ def _update_target_image(self):
14591459

14601460
def get_selection_modifiers(arch: Arch, inpaint_mode: InpaintMode, strength: float, min_size=256):
14611461
feather = settings.selection_feather / 100
1462-
padding = settings.selection_padding / 100
14631462
invert = False
14641463

14651464
if inpaint_mode is InpaintMode.replace_background and strength == 1.0:
@@ -1469,8 +1468,10 @@ def get_selection_modifiers(arch: Arch, inpaint_mode: InpaintMode, strength: flo
14691468
invert = True
14701469

14711470
return SelectionModifiers(
1472-
pad_rel=padding + feather,
1473-
pad_min_px=settings.selection_min_transition + settings.selection_grow_offset + 8,
1471+
feather_rel=feather,
1472+
feather_min_px=settings.selection_min_transition,
1473+
pad_rel=settings.selection_padding / 100,
1474+
pad_offset_px=settings.selection_grow_offset,
14741475
size_min_px=min_size,
14751476
multiple=arch.latent_compression_factor,
14761477
invert=invert,
@@ -1480,11 +1481,10 @@ def get_selection_modifiers(arch: Arch, inpaint_mode: InpaintMode, strength: flo
14801481
def get_selection_pre_process(bounds: Bounds | None, mods: SelectionModifiers):
14811482
if bounds is None or settings.selection_feather == 0:
14821483
return 0, 0
1483-
feather_rel = settings.selection_feather / 100
14841484
size_factor = bounds.extent.diagonal
1485-
feather = max(int(feather_rel * size_factor), settings.selection_min_transition)
1486-
if mods.invert:
1487-
feather = min(feather, 8)
1485+
feather = int(mods.feather_rel * size_factor)
1486+
if not mods.invert:
1487+
feather = max(feather, mods.feather_min_px)
14881488
grow = settings.selection_grow_offset + feather // 2
14891489
return grow, feather
14901490

0 commit comments

Comments
 (0)