sort images node

This commit is contained in:
SayanoAI
2024-08-08 14:56:21 -04:00
parent 5b12b19bc4
commit 0f3303f439
2 changed files with 40 additions and 3 deletions
+4 -2
View File
@@ -3,7 +3,7 @@ from .custom_nodes.uvr import UVR5Node
from .custom_nodes.rvc import RVCNode
from .custom_nodes.loaders import DownloadAudio, LoadAudio, LoadWhisperModelNode, LoadRVCModelNode, LoadHubertModel, LoadPitchExtractionParams
from .custom_nodes.output import PreviewAudio
from .custom_nodes.utils import Any2ListNode, AudioBatchValueNode, List2AnyNode, MergeImageBatches, MergeLatentBatches, ImageRepeatInterleavedNode, LatentRepeatInterleavedNode, MergeAudioNode, SimpleMathNode, SliceNode, ZipImagesNode
from .custom_nodes.utils import Any2ListNode, AudioBatchValueNode, List2AnyNode, MergeImageBatches, MergeLatentBatches, ImageRepeatInterleavedNode, LatentRepeatInterleavedNode, MergeAudioNode, SimpleMathNode, SliceNode, SortImagesNode, ZipImagesNode
# Set the web directory, any .js file in that directory will be loaded by the frontend as a frontend extension
WEB_DIRECTORY = "./web"
@@ -32,7 +32,8 @@ NODE_CLASS_MAPPINGS = {
"SliceNode": SliceNode,
"ZipNode": ZipImagesNode,
"Any2ListNode": Any2ListNode,
"List2AnyNode": List2AnyNode
"List2AnyNode": List2AnyNode,
"SortImagesNode": SortImagesNode
}
# A dictionary that contains the friendly/humanly readable titles for the nodes
@@ -59,4 +60,5 @@ NODE_DISPLAY_NAME_MAPPINGS = {
"ZipNode": "🌺Zip Images",
"Any2ListNode": "🌺Any to List",
"List2AnyNode": "🌺List to Any",
"SortImagesNode": "🌺Sort Images",
}
+36 -1
View File
@@ -548,4 +548,39 @@ class List2AnyNode:
CATEGORY = CATEGORY
def to(self, any):
return (any,)
return (any,)
class SortImagesNode:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"images": ("IMAGE",),
},
"optional": {
"indices": ("INT", {"forceInput": True}),
"reverse": ("BOOLEAN", {"default": False}),
"sort_by": (["sum","mean","median","min","max"],{"default": "sum"})
}
}
RETURN_TYPES = ("IMAGE", "INT")
RETURN_NAMES = ("images", "indices")
FUNCTION = "execute"
CATEGORY = CATEGORY
def execute(self, images, indices=None, reverse=False, sort_by="sum"):
if sort_by=="mean": func=np.mean
elif sort_by=="median": func=np.median
elif sort_by=="min": func=np.amin
elif sort_by=="max": func=np.amax
else: func=np.sum
values = list(map(lambda x: func(x.numpy()),images))
if indices is None:
indices = np.argsort(values)
if reverse: indices=indices[::-1]
indices = list(indices)
return (images[indices],indices)