-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d09eeb3
commit 690ea3d
Showing
7 changed files
with
120 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
from .imagefunc import * | ||
|
||
NODE_NAME = 'MaskByColor' | ||
|
||
|
||
class MaskByColor: | ||
@classmethod | ||
def INPUT_TYPES(s): | ||
return { | ||
"required": { | ||
"image": ("IMAGE", ), | ||
"color": ("COLOR", {"default": "#FFFFFF"},), | ||
"color_in_HEX": ("STRING", {"default": ""}), | ||
"threshold": ("INT", { "default": 0, "min": 0, "max": 100, "step": 1, }), | ||
"fix_gap": ("INT", {"default": 2, "min": 0, "max": 32, "step": 1}), | ||
"fix_threshold": ("FLOAT", {"default": 0.75, "min": 0.01, "max": 0.99, "step": 0.01}), | ||
"invert_mask": ("BOOLEAN", {"default": False}), # 反转mask | ||
} | ||
} | ||
|
||
RETURN_TYPES = ("MASK",) | ||
RETURN_NAMES = ("mask",) | ||
FUNCTION = "mask_by_color" | ||
CATEGORY = '😺dzNodes/LayerMask' | ||
|
||
def mask_by_color(self, image, color, color_in_HEX, threshold, | ||
fix_gap, fix_threshold, invert_mask): | ||
|
||
if color_in_HEX != "" and color_in_HEX.startswith('#') and len(color_in_HEX) == 7: | ||
color = color_in_HEX | ||
|
||
ret_masks = [] | ||
|
||
for i in image: | ||
img = tensor2pil(i.unsqueeze(0)) | ||
mask = create_mask_from_color_tensor(img, color, threshold) | ||
mask = image2mask(mask) | ||
if invert_mask: | ||
mask = 1 - mask | ||
|
||
if fix_gap: | ||
mask = mask_fix(mask, 1, fix_gap, fix_threshold, fix_threshold) | ||
ret_masks.append(mask) | ||
|
||
return (torch.cat(ret_masks, dim=0), ) | ||
|
||
|
||
NODE_CLASS_MAPPINGS = { | ||
"LayerMask: MaskByColor": MaskByColor | ||
} | ||
|
||
NODE_DISPLAY_NAME_MAPPINGS = { | ||
"LayerMask: MaskByColor": "LayerMask: Mask by Color" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters