update to latest comfy

This commit is contained in:
Tasha Upchurch
2023-05-30 15:04:02 -04:00
parent 1abb75a740
commit f6d1f495c5
2 changed files with 40 additions and 5 deletions
+30
View File
@@ -1187,6 +1187,36 @@ class rgba_merge:
FUNCTION = "merge"
def merge(self, r, g, b, a):
"""
r,g,b,a all may be 3, 1, or 4 channel images
>>> image = torch.rand((1, 512, 512,3))
>>> r, g, b, a = rgba_split.split(None,image)
>>> rgba_merge.merge(None,r,g,b,a).shape
torch.Size([1, 512, 512, 4])
:param r:
:param g:
:param b:
:param a:
:return:
"""
# use channel 0 of each channel in the resulting image
r = r[:, :, :, 0:1]
g = g[:, :, :, 0:1]
b = b[:, :, :, 0:1]
a = a[:, :, :, 0:1]
# there will always be an alpha channel so just put the channels together
return (torch.cat((r, g, b, a), dim=3),)
class rgba_split:
"""splits the channels of an RGBA image"""
+10 -5
View File
@@ -178,12 +178,20 @@ class VideoFramesToImageStack(VideoFolderToImage, metaclass=WidgetMetaclass):
Return slices of time from the video, sequences of images, defined by the start, stop and step
- torch tensors (T,H,W,C)
"""
import glob
folder_in_path = os.path.join(self.input_dir, folder_in)
image_list = []
# List and sort all PNG or JPG files in the folder
file_fps = sorted(glob.glob(os.path.join(folder_in_path, '*.png')) + glob.glob(os.path.join(folder_in_path, '*.jpg')))
# Ensure the slice doesn't go beyond the end of the file list
if idx_slice_stop+idx > len(file_fps):
idx_slice_stop = len(file_fps) - idx
for i in range(idx_slice_start+idx, idx_slice_stop+idx, slice_idx_step):
file_fps = [os.path.join(folder_in_path, f"frame{i+ii}.jpg") for ii in range(slice_idx_step)]
for fn in file_fps:
for fn in file_fps[i:i+slice_idx_step]:
image = cv2.imread(fn)
if image is not None:
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) # converting to RGB format
@@ -192,11 +200,8 @@ class VideoFramesToImageStack(VideoFolderToImage, metaclass=WidgetMetaclass):
# Convert list of images to tensor (T,H,W,C)
tensor = torch.stack([torch.tensor(img,dtype=torch.float32) for img in image_list])
tensor=tensor/255.0
return (tensor,)
class VideoFileToImageStack(VideoFileToImage, metaclass=WidgetMetaclass):
"""Use cv2 to open a video and save the videos individual frames"""