From f6d1f495c51d992d9f41729fb3dfffb43a090f0f Mon Sep 17 00:00:00 2001 From: Tasha Upchurch Date: Tue, 30 May 2023 15:04:02 -0400 Subject: [PATCH] update to latest comfy --- image.py | 30 ++++++++++++++++++++++++++++++ video.py | 15 ++++++++++----- 2 files changed, 40 insertions(+), 5 deletions(-) diff --git a/image.py b/image.py index b0dfb24..170a133 100644 --- a/image.py +++ b/image.py @@ -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""" diff --git a/video.py b/video.py index 1729a14..c9cddd8 100644 --- a/video.py +++ b/video.py @@ -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"""