forked from pixaroma/ComfyUI-Pixaroma
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnodes_compare.py
More file actions
65 lines (55 loc) · 1.72 KB
/
nodes_compare.py
File metadata and controls
65 lines (55 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import random
import numpy as np
from PIL import Image
import folder_paths
class PixaromaCompare:
def __init__(self):
self.output_dir = folder_paths.get_temp_directory()
self.type = "temp"
self.prefix_append = "_pixcmp_" + ''.join(
random.choice("abcdefghijklmnopqrstuvwxyz") for _ in range(5)
)
self.compress_level = 4
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"image1": ("IMAGE",),
"image2": ("IMAGE",),
}
}
RETURN_TYPES = ()
FUNCTION = "compare_images"
OUTPUT_NODE = True
CATEGORY = "Pixaroma"
def compare_images(self, image1, image2):
results = []
prefix = "pixaroma_compare" + self.prefix_append
full_output_folder, filename, counter, subfolder, _ = (
folder_paths.get_save_image_path(
prefix, self.output_dir,
image1[0].shape[1], image1[0].shape[0],
)
)
for tensor in [image1, image2]:
i = 255.0 * tensor[0].cpu().numpy()
img = Image.fromarray(np.clip(i, 0, 255).astype(np.uint8))
file = f"{filename}_{counter:05}_.png"
img.save(
os.path.join(full_output_folder, file),
compress_level=self.compress_level,
)
results.append({
"filename": file,
"subfolder": subfolder,
"type": self.type,
})
counter += 1
return {"ui": {"images": results}}
NODE_CLASS_MAPPINGS = {
"PixaromaCompare": PixaromaCompare,
}
NODE_DISPLAY_NAME_MAPPINGS = {
"PixaromaCompare": "Image Compare Pixaroma",
}