Compare commits

...

5 Commits

Author SHA1 Message Date
sovahc
24e9e000de
Merge cb820f02492a8ecb866bb41eecacafc5c9ca7611 into 712851c53e167da748783a6fbc914932032c8fd6 2025-12-04 17:33:23 +08:00
Jukka Seppänen
712851c53e
Merge pull request #451 from stuttlepress/handle-base-directory-paths
Add relative path handling for --base-directory
2025-12-04 09:52:42 +02:00
stuttlepress
496d3bd07e Add relative path handling for --base-directory
- LoadImagesFromFolderKJ: Resolve relative paths against base_directory
- LoadVideosFromFolder: Resolve relative video folder paths
- SaveStringKJ: Resolve relative output folder paths
2025-12-04 00:37:15 -06:00
sovahc
cb820f0249
Description is fixed 2025-11-21 03:14:59 +02:00
sovahc
95bc77f855
Added step to ReplaceImagesInBatch
This is useful for VACE for interleaving frames
2025-11-21 02:17:20 +02:00

View File

@ -2156,8 +2156,8 @@ class ReplaceImagesInBatch:
FUNCTION = "replace"
CATEGORY = "KJNodes/image"
DESCRIPTION = """
Replaces the images in a batch, starting from the specified start index,
with the replacement images.
Replaces the images in a batch, starting from the specified start index with step stride,
using the replacement images.
"""
@classmethod
@ -2165,6 +2165,7 @@ with the replacement images.
return {
"required": {
"start_index": ("INT", {"default": 1,"min": 0, "max": 4096, "step": 1}),
"step": ("INT", {"default": 1,"min": 1, "max": 4096, "step": 1}),
},
"optional": {
"original_images": ("IMAGE",),
@ -2174,14 +2175,14 @@ with the replacement images.
}
}
def replace(self, original_images=None, replacement_images=None, start_index=1, original_masks=None, replacement_masks=None):
def replace(self, original_images=None, replacement_images=None, start_index=1, step=1, original_masks=None, replacement_masks=None):
images = None
masks = None
if original_images is not None and replacement_images is not None:
if start_index >= len(original_images):
raise ValueError("ReplaceImagesInBatch: Start index is out of range")
end_index = start_index + len(replacement_images)
end_index = start_index + len(replacement_images) * step
if end_index > len(original_images):
raise ValueError("ReplaceImagesInBatch: End index is out of range")
@ -2189,7 +2190,7 @@ with the replacement images.
if original_images_copy.shape[2] != replacement_images.shape[2] or original_images_copy.shape[3] != replacement_images.shape[3]:
replacement_images = common_upscale(replacement_images.movedim(-1, 1), original_images_copy.shape[1], original_images_copy.shape[2], "lanczos", "center").movedim(1, -1)
original_images_copy[start_index:end_index] = replacement_images
original_images_copy[start_index:end_index:step] = replacement_images
images = original_images_copy
else:
images = torch.zeros((1, 64, 64, 3))
@ -2197,7 +2198,7 @@ with the replacement images.
if original_masks is not None and replacement_masks is not None:
if start_index >= len(original_masks):
raise ValueError("ReplaceImagesInBatch: Start index is out of range")
end_index = start_index + len(replacement_masks)
end_index = start_index + len(replacement_masks) * step
if end_index > len(original_masks):
raise ValueError("ReplaceImagesInBatch: End index is out of range")
@ -2205,7 +2206,7 @@ with the replacement images.
if original_masks_copy.shape[1] != replacement_masks.shape[1] or original_masks_copy.shape[2] != replacement_masks.shape[2]:
replacement_masks = common_upscale(replacement_masks.unsqueeze(1), original_masks_copy.shape[1], original_masks_copy.shape[2], "nearest-exact", "center").squeeze(0)
original_masks_copy[start_index:end_index] = replacement_masks
original_masks_copy[start_index:end_index:step] = replacement_masks
masks = original_masks_copy
else:
masks = torch.zeros((1, 64, 64))
@ -2963,6 +2964,8 @@ class LoadImagesFromFolderKJ:
@classmethod
def IS_CHANGED(cls, folder, **kwargs):
if not os.path.isabs(folder) and args.base_directory:
folder = os.path.join(args.base_directory, folder)
if not os.path.isdir(folder):
return float("NaN")
@ -3032,6 +3035,8 @@ class LoadImagesFromFolderKJ:
DESCRIPTION = """Loads images from a folder into a batch, images are resized and loaded into a batch."""
def load_images(self, folder, width, height, image_load_cap, start_index, keep_aspect_ratio, include_subfolders=False):
if not os.path.isabs(folder) and args.base_directory:
folder = os.path.join(args.base_directory, folder)
if not os.path.isdir(folder):
raise FileNotFoundError(f"Folder '{folder} cannot be found.'")
@ -3335,6 +3340,8 @@ class SaveStringKJ:
filename_prefix += self.prefix_append
full_output_folder, filename, counter, subfolder, filename_prefix = folder_paths.get_save_image_path(filename_prefix, self.output_dir)
if not os.path.isabs(output_folder) and args.base_directory:
output_folder = os.path.join(args.base_directory, output_folder)
if output_folder != "output":
if not os.path.exists(output_folder):
os.makedirs(output_folder, exist_ok=True)
@ -3960,6 +3967,9 @@ class LoadVideosFromFolder:
FUNCTION = "load_video"
def load_video(self, output_type, grid_max_columns, add_label=False, **kwargs):
if not os.path.isabs(kwargs['video']) and args.base_directory:
kwargs['video'] = os.path.join(args.base_directory, kwargs['video'])
if self.vhs_nodes is None:
raise ImportError("This node requires ComfyUI-VideoHelperSuite to be installed.")
videos_list = []