update
This commit is contained in:
@@ -1,16 +1,13 @@
|
||||
from .nodes.load_dilight_controlnet_node import LoadDiLightControlNetNode
|
||||
from .nodes.prepare_dilight_cond_node import PrepareDiLightCondNode
|
||||
from .nodes.load_dilight_image_node import LoadDiLightImageNode
|
||||
|
||||
|
||||
NODE_CLASS_MAPPINGS = {
|
||||
"LoadDiLightControlNet": LoadDiLightControlNetNode,
|
||||
"PrepareDiLightCond": PrepareDiLightCondNode,
|
||||
"LoadDiLightImage": LoadDiLightImageNode,
|
||||
}
|
||||
|
||||
NODE_DISPLAY_NAME_MAPPINGS = {
|
||||
"LoadDiLightControlNet": "Load DiLight ControlNet",
|
||||
"PrepareDiLightCond": "Prepare DiLight CN Image",
|
||||
"LoadDiLightImage": "Load DiLight Image",
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,72 +0,0 @@
|
||||
import os
|
||||
|
||||
import torch
|
||||
import numpy as np
|
||||
from PIL import Image, ImageOps, ImageSequence
|
||||
|
||||
import folder_paths
|
||||
import node_helpers
|
||||
|
||||
|
||||
class LoadDiLightImageNode:
|
||||
@classmethod
|
||||
def INPUT_TYPES(s):
|
||||
input_dir = folder_paths.get_input_directory()
|
||||
files = [f for f in os.listdir(input_dir) if os.path.isfile(os.path.join(input_dir, f))]
|
||||
return {"required":
|
||||
{"image": (sorted(files), {"image_upload": True})},
|
||||
}
|
||||
|
||||
CATEGORY = "image"
|
||||
|
||||
RETURN_TYPES = ("IMAGE", "MASK")
|
||||
FUNCTION = "load_image"
|
||||
def load_image(self, image):
|
||||
image_path = folder_paths.get_annotated_filepath(image)
|
||||
|
||||
img = node_helpers.pillow(Image.open, image_path)
|
||||
|
||||
output_images = []
|
||||
output_masks = []
|
||||
w, h = None, None
|
||||
|
||||
excluded_formats = ['MPO']
|
||||
|
||||
for i in ImageSequence.Iterator(img):
|
||||
i = node_helpers.pillow(ImageOps.exif_transpose, i)
|
||||
|
||||
if i.mode == 'I':
|
||||
i = i.point(lambda i: i * (1 / 255))
|
||||
if 'A' in i.getbands():
|
||||
image = i.convert("RGBA")
|
||||
else:
|
||||
image = i.convert("RGB")
|
||||
|
||||
if len(output_images) == 0:
|
||||
w = image.size[0]
|
||||
h = image.size[1]
|
||||
|
||||
if image.size[0] != w or image.size[1] != h:
|
||||
continue
|
||||
|
||||
image = np.array(image).astype(np.float32) / 255.0
|
||||
image = torch.from_numpy(image)[None,]
|
||||
if 'A' in i.getbands():
|
||||
mask = np.array(i.getchannel('A')).astype(np.float32) / 255.0
|
||||
mask = 1. - torch.from_numpy(mask)
|
||||
else:
|
||||
mask = torch.zeros((64,64), dtype=torch.float32, device="cpu")
|
||||
output_images.append(image)
|
||||
output_masks.append(mask.unsqueeze(0))
|
||||
|
||||
if len(output_images) > 1 and img.format not in excluded_formats:
|
||||
output_image = torch.cat(output_images, dim=0)
|
||||
output_mask = torch.cat(output_masks, dim=0)
|
||||
else:
|
||||
output_image = output_images[0]
|
||||
output_mask = output_masks[0]
|
||||
|
||||
if output_image.shape[-1] == 4:
|
||||
output_image = output_image[..., :3] * output_image[..., 3:]
|
||||
|
||||
return (output_image, output_mask)
|
||||
Reference in New Issue
Block a user