Files
Bjornulf_custom_nodes/select_image_from_list.py
justumen 5f47d20f75 0.34
2024-09-16 10:36:11 +02:00

32 lines
910 B
Python

import torch
class Everything(str):
def __ne__(self, __value: object) -> bool:
return False
class SelectImageFromList:
@classmethod
def INPUT_TYPES(cls):
return {
"required": {
"all_images": ("IMAGE", {}),
"selection": ("INT", {"default": 1, "min": 1, "max": 999, "step": 1}),
}
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("selected_image",)
FUNCTION = "select_an_image"
CATEGORY = "Bjornulf"
def select_an_image(self, all_images, selection):
# Ensure the selection is within bounds
selection = max(1, min(selection, all_images.shape[0]))
# Adjust selection to 0-based index
index = selection - 1
# Select the image at the specified index
selected_image = all_images[index].unsqueeze(0)
return (selected_image,)