Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
chenpangpang
ComfyUI
Commits
81d9200e
"vscode:/vscode.git/clone" did not exist on "3376f3a7d931555ed1e89d4e51e102e91bcf2e68"
Commit
81d9200e
authored
Aug 29, 2023
by
comfyanonymous
Browse files
Add node to convert a specific colour in an image to a mask.
parent
f2f5e5dc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
0 deletions
+22
-0
comfy_extras/nodes_mask.py
comfy_extras/nodes_mask.py
+22
-0
No files found.
comfy_extras/nodes_mask.py
View file @
81d9200e
...
@@ -125,6 +125,27 @@ class ImageToMask:
...
@@ -125,6 +125,27 @@ class ImageToMask:
mask
=
image
[
0
,
:,
:,
channels
.
index
(
channel
)]
mask
=
image
[
0
,
:,
:,
channels
.
index
(
channel
)]
return
(
mask
,)
return
(
mask
,)
class
ImageColorToMask
:
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"image"
:
(
"IMAGE"
,),
"color"
:
(
"INT"
,
{
"default"
:
0
,
"min"
:
0
,
"max"
:
0xFFFFFF
,
"step"
:
1
,
"display"
:
"color"
}),
}
}
CATEGORY
=
"mask"
RETURN_TYPES
=
(
"MASK"
,)
FUNCTION
=
"image_to_mask"
def
image_to_mask
(
self
,
image
,
color
):
temp
=
(
torch
.
clamp
(
image
[
0
],
0
,
1.0
)
*
255.0
).
round
().
to
(
torch
.
int
)
temp
=
torch
.
bitwise_left_shift
(
temp
[:,:,
0
],
16
)
+
torch
.
bitwise_left_shift
(
temp
[:,:,
1
],
8
)
+
temp
[:,:,
2
]
mask
=
torch
.
where
(
temp
==
color
,
255
,
0
).
float
()
return
(
mask
,)
class
SolidMask
:
class
SolidMask
:
@
classmethod
@
classmethod
def
INPUT_TYPES
(
cls
):
def
INPUT_TYPES
(
cls
):
...
@@ -315,6 +336,7 @@ NODE_CLASS_MAPPINGS = {
...
@@ -315,6 +336,7 @@ NODE_CLASS_MAPPINGS = {
"ImageCompositeMasked"
:
ImageCompositeMasked
,
"ImageCompositeMasked"
:
ImageCompositeMasked
,
"MaskToImage"
:
MaskToImage
,
"MaskToImage"
:
MaskToImage
,
"ImageToMask"
:
ImageToMask
,
"ImageToMask"
:
ImageToMask
,
"ImageColorToMask"
:
ImageColorToMask
,
"SolidMask"
:
SolidMask
,
"SolidMask"
:
SolidMask
,
"InvertMask"
:
InvertMask
,
"InvertMask"
:
InvertMask
,
"CropMask"
:
CropMask
,
"CropMask"
:
CropMask
,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment