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
f48f0872
Commit
f48f0872
authored
Apr 14, 2023
by
comfyanonymous
Browse files
Refactor: move nodes_mask_convertion nodes to nodes_mask.
parent
e1db7a20
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
31 additions
and
63 deletions
+31
-63
comfy_extras/nodes_mask.py
comfy_extras/nodes_mask.py
+31
-8
comfy_extras/nodes_mask_conversion.py
comfy_extras/nodes_mask_conversion.py
+0
-54
nodes.py
nodes.py
+0
-1
No files found.
comfy_extras/nodes_mask.py
View file @
f48f0872
...
@@ -59,7 +59,7 @@ class LatentCompositeMasked:
...
@@ -59,7 +59,7 @@ class LatentCompositeMasked:
class
MaskToImage
:
class
MaskToImage
:
@
classmethod
@
classmethod
def
INPUT_TYPES
(
cl
s
):
def
INPUT_TYPES
(
s
):
return
{
return
{
"required"
:
{
"required"
:
{
"mask"
:
(
"MASK"
,),
"mask"
:
(
"MASK"
,),
...
@@ -69,13 +69,31 @@ class MaskToImage:
...
@@ -69,13 +69,31 @@ class MaskToImage:
CATEGORY
=
"mask"
CATEGORY
=
"mask"
RETURN_TYPES
=
(
"IMAGE"
,)
RETURN_TYPES
=
(
"IMAGE"
,)
FUNCTION
=
"mask_to_image"
FUNCTION
=
"convert"
def
mask_to_image
(
self
,
mask
):
result
=
mask
[
None
,
:,
:,
None
].
expand
(
-
1
,
-
1
,
-
1
,
3
)
return
(
result
,)
def
convert
(
self
,
mask
):
class
ImageToMask
:
image
=
torch
.
cat
([
torch
.
reshape
(
mask
.
clone
(),
[
1
,
mask
.
shape
[
0
],
mask
.
shape
[
1
],
1
,])]
*
3
,
3
)
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"image"
:
(
"IMAGE"
,),
"channel"
:
([
"red"
,
"green"
,
"blue"
],),
}
}
CATEGORY
=
"mask"
return
(
image
,)
RETURN_TYPES
=
(
"MASK"
,)
FUNCTION
=
"image_to_mask"
def
image_to_mask
(
self
,
image
,
channel
):
channels
=
[
"red"
,
"green"
,
"blue"
]
mask
=
image
[
0
,
:,
:,
channels
.
index
(
channel
)]
return
(
mask
,)
class
SolidMask
:
class
SolidMask
:
@
classmethod
@
classmethod
...
@@ -231,6 +249,7 @@ class FeatherMask:
...
@@ -231,6 +249,7 @@ class FeatherMask:
NODE_CLASS_MAPPINGS
=
{
NODE_CLASS_MAPPINGS
=
{
"LatentCompositeMasked"
:
LatentCompositeMasked
,
"LatentCompositeMasked"
:
LatentCompositeMasked
,
"MaskToImage"
:
MaskToImage
,
"MaskToImage"
:
MaskToImage
,
"ImageToMask"
:
ImageToMask
,
"SolidMask"
:
SolidMask
,
"SolidMask"
:
SolidMask
,
"InvertMask"
:
InvertMask
,
"InvertMask"
:
InvertMask
,
"CropMask"
:
CropMask
,
"CropMask"
:
CropMask
,
...
@@ -238,3 +257,7 @@ NODE_CLASS_MAPPINGS = {
...
@@ -238,3 +257,7 @@ NODE_CLASS_MAPPINGS = {
"FeatherMask"
:
FeatherMask
,
"FeatherMask"
:
FeatherMask
,
}
}
NODE_DISPLAY_NAME_MAPPINGS
=
{
"ImageToMask"
:
"Convert Image to Mask"
,
"MaskToImage"
:
"Convert Mask to Image"
,
}
comfy_extras/nodes_mask_conversion.py
deleted
100644 → 0
View file @
e1db7a20
import
numpy
as
np
import
torch
import
torch.nn.functional
as
F
from
PIL
import
Image
import
comfy.utils
class
ImageToMask
:
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"image"
:
(
"IMAGE"
,),
"channel"
:
([
"red"
,
"green"
,
"blue"
],),
}
}
CATEGORY
=
"image"
RETURN_TYPES
=
(
"MASK"
,)
FUNCTION
=
"image_to_mask"
def
image_to_mask
(
self
,
image
,
channel
):
channels
=
[
"red"
,
"green"
,
"blue"
]
mask
=
image
[
0
,
:,
:,
channels
.
index
(
channel
)]
return
(
mask
,)
class
MaskToImage
:
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"mask"
:
(
"MASK"
,),
}
}
CATEGORY
=
"image"
RETURN_TYPES
=
(
"IMAGE"
,)
FUNCTION
=
"mask_to_image"
def
mask_to_image
(
self
,
mask
):
result
=
mask
[
None
,
:,
:,
None
].
expand
(
-
1
,
-
1
,
-
1
,
3
)
return
(
result
,)
NODE_CLASS_MAPPINGS
=
{
"ImageToMask"
:
ImageToMask
,
"MaskToImage"
:
MaskToImage
,
}
NODE_DISPLAY_NAME_MAPPINGS
=
{
"ImageToMask"
:
"Convert Image to Mask"
,
"MaskToImage"
:
"Convert Mask to Image"
,
}
nodes.py
View file @
f48f0872
...
@@ -1193,4 +1193,3 @@ def init_custom_nodes():
...
@@ -1193,4 +1193,3 @@ def init_custom_nodes():
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_upscale_model.py"
))
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_upscale_model.py"
))
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_post_processing.py"
))
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_post_processing.py"
))
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_mask.py"
))
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_mask.py"
))
load_custom_node
(
os
.
path
.
join
(
os
.
path
.
join
(
os
.
path
.
dirname
(
os
.
path
.
realpath
(
__file__
)),
"comfy_extras"
),
"nodes_mask_conversion.py"
))
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