Skip to content

Commit

Permalink
fix: ✨ expose invert of bboxfrommask
Browse files Browse the repository at this point in the history
changes the default to false
related to #124
  • Loading branch information
melMass committed Nov 14, 2023
1 parent d5c4c5f commit 53cb503
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions nodes/crop.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ def INPUT_TYPES(cls):
return {
"required": {
"mask": ("MASK",),
"invert": ("BOOLEAN", {"default": False}),
},
"optional": {
"image": ("IMAGE",),
Expand All @@ -61,7 +62,7 @@ def INPUT_TYPES(cls):
FUNCTION = "extract_bounding_box"
CATEGORY = "mtb/crop"

def extract_bounding_box(self, mask: torch.Tensor, image=None):
def extract_bounding_box(self, mask: torch.Tensor, invert: bool, image=None):
# if image != None:
# if mask.size(0) != image.size(0):
# if mask.size(0) != 1:
Expand All @@ -73,9 +74,8 @@ def extract_bounding_box(self, mask: torch.Tensor, image=None):
# f"Batch count mismatch for mask and image, it can either be 1 mask for X images, or X masks for X images (mask: {mask.shape} | image: {image.shape})"
# )

_mask = tensor2pil(1.0 - mask)[0]

# we invert it
_mask = tensor2pil(1.0 - mask)[0] if invert else tensor2pil(mask)[0]
alpha_channel = np.array(_mask)

non_zero_indices = np.nonzero(alpha_channel)
Expand Down

0 comments on commit 53cb503

Please sign in to comment.