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
ece69bf2
Commit
ece69bf2
authored
Sep 23, 2023
by
MoonRide303
Browse files
Change channel type to MASK (reduced redundancy, increased usability)
parent
d06cd280
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
8 additions
and
50 deletions
+8
-50
comfy_extras/nodes_compositing.py
comfy_extras/nodes_compositing.py
+5
-47
comfy_extras/nodes_mask.py
comfy_extras/nodes_mask.py
+2
-2
nodes.py
nodes.py
+1
-1
No files found.
comfy_extras/nodes_compositing.py
View file @
ece69bf2
...
@@ -93,14 +93,14 @@ class PorterDuffImageComposite:
...
@@ -93,14 +93,14 @@ class PorterDuffImageComposite:
return
{
return
{
"required"
:
{
"required"
:
{
"source"
:
(
"IMAGE"
,),
"source"
:
(
"IMAGE"
,),
"source_alpha"
:
(
"
ALPHA
"
,),
"source_alpha"
:
(
"
MASK
"
,),
"destination"
:
(
"IMAGE"
,),
"destination"
:
(
"IMAGE"
,),
"destination_alpha"
:
(
"
ALPHA
"
,),
"destination_alpha"
:
(
"
MASK
"
,),
"mode"
:
([
mode
.
name
for
mode
in
PorterDuffMode
],
{
"default"
:
PorterDuffMode
.
DST
.
name
}),
"mode"
:
([
mode
.
name
for
mode
in
PorterDuffMode
],
{
"default"
:
PorterDuffMode
.
DST
.
name
}),
},
},
}
}
RETURN_TYPES
=
(
"IMAGE"
,
"
ALPHA
"
)
RETURN_TYPES
=
(
"IMAGE"
,
"
MASK
"
)
FUNCTION
=
"composite"
FUNCTION
=
"composite"
CATEGORY
=
"compositing"
CATEGORY
=
"compositing"
...
@@ -148,7 +148,7 @@ class SplitImageWithAlpha:
...
@@ -148,7 +148,7 @@ class SplitImageWithAlpha:
}
}
CATEGORY
=
"compositing"
CATEGORY
=
"compositing"
RETURN_TYPES
=
(
"IMAGE"
,
"
ALPHA
"
)
RETURN_TYPES
=
(
"IMAGE"
,
"
MASK
"
)
FUNCTION
=
"split_image_with_alpha"
FUNCTION
=
"split_image_with_alpha"
def
split_image_with_alpha
(
self
,
image
:
torch
.
Tensor
):
def
split_image_with_alpha
(
self
,
image
:
torch
.
Tensor
):
...
@@ -164,7 +164,7 @@ class JoinImageWithAlpha:
...
@@ -164,7 +164,7 @@ class JoinImageWithAlpha:
return
{
return
{
"required"
:
{
"required"
:
{
"image"
:
(
"IMAGE"
,),
"image"
:
(
"IMAGE"
,),
"alpha"
:
(
"
ALPHA
"
,),
"alpha"
:
(
"
MASK
"
,),
}
}
}
}
...
@@ -183,50 +183,10 @@ class JoinImageWithAlpha:
...
@@ -183,50 +183,10 @@ class JoinImageWithAlpha:
return
result
return
result
class
ConvertAlphaToImage
:
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"alpha"
:
(
"ALPHA"
,),
}
}
CATEGORY
=
"compositing"
RETURN_TYPES
=
(
"IMAGE"
,)
FUNCTION
=
"alpha_to_image"
def
alpha_to_image
(
self
,
alpha
):
result
=
alpha
.
reshape
((
-
1
,
1
,
alpha
.
shape
[
-
2
],
alpha
.
shape
[
-
1
])).
movedim
(
1
,
-
1
).
expand
(
-
1
,
-
1
,
-
1
,
3
)
return
(
result
,)
class
ConvertImageToAlpha
:
@
classmethod
def
INPUT_TYPES
(
s
):
return
{
"required"
:
{
"image"
:
(
"IMAGE"
,),
"channel"
:
([
"red"
,
"green"
,
"blue"
,
"alpha"
],),
}
}
CATEGORY
=
"compositing"
RETURN_TYPES
=
(
"ALPHA"
,)
FUNCTION
=
"image_to_alpha"
def
image_to_alpha
(
self
,
image
,
channel
):
channels
=
[
"red"
,
"green"
,
"blue"
,
"alpha"
]
alpha
=
image
[
0
,
:,
:,
channels
.
index
(
channel
)]
return
(
alpha
,)
NODE_CLASS_MAPPINGS
=
{
NODE_CLASS_MAPPINGS
=
{
"PorterDuffImageComposite"
:
PorterDuffImageComposite
,
"PorterDuffImageComposite"
:
PorterDuffImageComposite
,
"SplitImageWithAlpha"
:
SplitImageWithAlpha
,
"SplitImageWithAlpha"
:
SplitImageWithAlpha
,
"JoinImageWithAlpha"
:
JoinImageWithAlpha
,
"JoinImageWithAlpha"
:
JoinImageWithAlpha
,
"ConvertAlphaToImage"
:
ConvertAlphaToImage
,
"ConvertImageToAlpha"
:
ConvertImageToAlpha
,
}
}
...
@@ -234,6 +194,4 @@ NODE_DISPLAY_NAME_MAPPINGS = {
...
@@ -234,6 +194,4 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"PorterDuffImageComposite"
:
"Porter-Duff Image Composite"
,
"PorterDuffImageComposite"
:
"Porter-Duff Image Composite"
,
"SplitImageWithAlpha"
:
"Split Image with Alpha"
,
"SplitImageWithAlpha"
:
"Split Image with Alpha"
,
"JoinImageWithAlpha"
:
"Join Image with Alpha"
,
"JoinImageWithAlpha"
:
"Join Image with Alpha"
,
"ConvertAlphaToImage"
:
"Convert Alpha to Image"
,
"ConvertImageToAlpha"
:
"Convert Image to Alpha"
,
}
}
comfy_extras/nodes_mask.py
View file @
ece69bf2
...
@@ -114,7 +114,7 @@ class ImageToMask:
...
@@ -114,7 +114,7 @@ class ImageToMask:
return
{
return
{
"required"
:
{
"required"
:
{
"image"
:
(
"IMAGE"
,),
"image"
:
(
"IMAGE"
,),
"channel"
:
([
"red"
,
"green"
,
"blue"
],),
"channel"
:
([
"red"
,
"green"
,
"blue"
,
"alpha"
],),
}
}
}
}
...
@@ -124,7 +124,7 @@ class ImageToMask:
...
@@ -124,7 +124,7 @@ class ImageToMask:
FUNCTION
=
"image_to_mask"
FUNCTION
=
"image_to_mask"
def
image_to_mask
(
self
,
image
,
channel
):
def
image_to_mask
(
self
,
image
,
channel
):
channels
=
[
"red"
,
"green"
,
"blue"
]
channels
=
[
"red"
,
"green"
,
"blue"
,
"alpha"
]
mask
=
image
[:,
:,
:,
channels
.
index
(
channel
)]
mask
=
image
[:,
:,
:,
channels
.
index
(
channel
)]
return
(
mask
,)
return
(
mask
,)
...
...
nodes.py
View file @
ece69bf2
...
@@ -1383,7 +1383,7 @@ class LoadImageWithAlpha(LoadImage):
...
@@ -1383,7 +1383,7 @@ class LoadImageWithAlpha(LoadImage):
CATEGORY
=
"compositing"
CATEGORY
=
"compositing"
RETURN_TYPES
=
(
"IMAGE"
,
"
ALPHA
"
)
RETURN_TYPES
=
(
"IMAGE"
,
"
MASK
"
)
FUNCTION
=
"load_image"
FUNCTION
=
"load_image"
def
load_image
(
self
,
image
):
def
load_image
(
self
,
image
):
...
...
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