Update
This commit is contained in:
@@ -1,26 +1,6 @@
|
||||
<<<<<<< HEAD
|
||||
import os, re,io, base64, csv, torch
|
||||
import shutil, requests, chardet, pathlib
|
||||
import openpyxl, folder_paths, node_helpers
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
import os, re,io, base64, csv, torch
|
||||
import shutil, requests, chardet, pathlib
|
||||
import openpyxl, folder_paths, node_helpers
|
||||
=======
|
||||
import os
|
||||
import re
|
||||
import csv
|
||||
import torch
|
||||
import shutil
|
||||
import requests
|
||||
import chardet
|
||||
import pathlib
|
||||
import openpyxl
|
||||
import folder_paths
|
||||
import node_helpers
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
import numpy as np
|
||||
from PIL import Image, ImageOps, ImageSequence
|
||||
from pathlib import Path
|
||||
@@ -29,10 +9,6 @@ from PIL import Image as PILImage
|
||||
from io import BytesIO
|
||||
from . import AnyType, any_typ
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
|
||||
|
||||
|
||||
@@ -42,11 +18,7 @@ class GenericImageLoader:
|
||||
def INPUT_TYPES(cls):
|
||||
return {
|
||||
"required": {
|
||||
<<<<<<< HEAD
|
||||
"image_input": ("STRING", {"default": ""}),
|
||||
=======
|
||||
"path_or_input": ("STRING", {"default": ""}),
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
}
|
||||
}
|
||||
RETURN_TYPES = ("IMAGE", "MASK")
|
||||
@@ -58,13 +30,8 @@ class GenericImageLoader:
|
||||
def IS_CHANGED():
|
||||
return float("NaN")
|
||||
|
||||
<<<<<<< HEAD
|
||||
def load_image(self, image_input):
|
||||
path = image_input.strip()
|
||||
=======
|
||||
def load_image(self, path_or_input):
|
||||
path = path_or_input.strip()
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
for ctrl in ['\u202a', '\u202b', '\u202c', '\u202d', '\u202e']:
|
||||
while path.startswith(ctrl):
|
||||
path = path.lstrip(ctrl)
|
||||
@@ -104,11 +71,6 @@ class GenericImageLoader:
|
||||
|
||||
return img_tensor, mask_tensor
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
=======
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
|
||||
#======加载重置图像
|
||||
class LoadAndAdjustImage:
|
||||
@@ -277,99 +239,35 @@ class ImageAdjuster:
|
||||
def IS_CHANGED(self):
|
||||
return float("NaN")
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
def process_image(self, image, mask, max_dimension=1024, size_option="Custom"):
|
||||
batch_size = image.shape[0]
|
||||
processed_images = []
|
||||
processed_masks = []
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
=======
|
||||
def process_image(self, image, max_dimension=1024, size_option="Custom"):
|
||||
batch_size = image.shape[0]
|
||||
processed_images = []
|
||||
>>>>>>> db71d026f74322a6e66276701198bfe8b5d44ad8
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
widths = []
|
||||
heights = []
|
||||
|
||||
for i in range(batch_size):
|
||||
current_image = image[i]
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
current_mask = mask[i]
|
||||
|
||||
input_pil_image = Image.fromarray((current_image.numpy() * 255).astype(np.uint8))
|
||||
input_pil_mask = Image.fromarray((current_mask.numpy() * 255).astype(np.uint8))
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
=======
|
||||
input_pil_image = Image.fromarray((current_image.numpy() * 255).astype(np.uint8))
|
||||
>>>>>>> db71d026f74322a6e66276701198bfe8b5d44ad8
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
W, H = input_pil_image.size
|
||||
|
||||
processed_image_pil = input_pil_image.copy()
|
||||
processed_image_pil = ImageOps.exif_transpose(processed_image_pil)
|
||||
|
||||
<<<<<<< HEAD
|
||||
processed_mask_pil = input_pil_mask.copy()
|
||||
processed_mask_pil = ImageOps.exif_transpose(processed_mask_pil)
|
||||
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
processed_mask_pil = input_pil_mask.copy()
|
||||
processed_mask_pil = ImageOps.exif_transpose(processed_mask_pil)
|
||||
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
processed_mask_pil = input_pil_mask.copy()
|
||||
processed_mask_pil = ImageOps.exif_transpose(processed_mask_pil)
|
||||
|
||||
=======
|
||||
>>>>>>> db71d026f74322a6e66276701198bfe8b5d44ad8
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
if processed_image_pil.mode == 'P':
|
||||
processed_image_pil = processed_image_pil.convert("RGBA")
|
||||
elif 'A' in processed_image_pil.getbands():
|
||||
processed_image_pil = processed_image_pil.convert("RGBA")
|
||||
<<<<<<< HEAD
|
||||
|
||||
if processed_mask_pil.mode != "L":
|
||||
processed_mask_pil = processed_mask_pil.convert("L")
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
|
||||
if processed_mask_pil.mode != "L":
|
||||
processed_mask_pil = processed_mask_pil.convert("L")
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
|
||||
if processed_mask_pil.mode != "L":
|
||||
processed_mask_pil = processed_mask_pil.convert("L")
|
||||
=======
|
||||
>>>>>>> db71d026f74322a6e66276701198bfe8b5d44ad8
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
|
||||
if size_option != "Custom":
|
||||
aspect_ratio = W / H
|
||||
@@ -402,21 +300,8 @@ class ImageAdjuster:
|
||||
target_width, target_height = size_options[size_option]
|
||||
processed_image_pil = processed_image_pil.convert("RGB")
|
||||
processed_image_pil = ImageOps.fit(processed_image_pil, (target_width, target_height), method=Image.Resampling.BILINEAR, centering=(0.5, 0.5))
|
||||
<<<<<<< HEAD
|
||||
|
||||
processed_mask_pil = ImageOps.fit(processed_mask_pil, (target_width, target_height), method=Image.Resampling.BILINEAR, centering=(0.5, 0.5))
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
|
||||
processed_mask_pil = ImageOps.fit(processed_mask_pil, (target_width, target_height), method=Image.Resampling.BILINEAR, centering=(0.5, 0.5))
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
|
||||
processed_mask_pil = ImageOps.fit(processed_mask_pil, (target_width, target_height), method=Image.Resampling.BILINEAR, centering=(0.5, 0.5))
|
||||
=======
|
||||
>>>>>>> db71d026f74322a6e66276701198bfe8b5d44ad8
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
else:
|
||||
ratio = min(max_dimension / W, max_dimension / H)
|
||||
adjusted_width = round(W * ratio)
|
||||
@@ -424,45 +309,17 @@ class ImageAdjuster:
|
||||
|
||||
processed_image_pil = processed_image_pil.convert("RGB")
|
||||
processed_image_pil = processed_image_pil.resize((adjusted_width, adjusted_height), Image.Resampling.BILINEAR)
|
||||
<<<<<<< HEAD
|
||||
|
||||
processed_mask_pil = processed_mask_pil.resize((adjusted_width, adjusted_height), Image.Resampling.BILINEAR)
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
|
||||
processed_mask_pil = processed_mask_pil.resize((adjusted_width, adjusted_height), Image.Resampling.BILINEAR)
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
|
||||
processed_mask_pil = processed_mask_pil.resize((adjusted_width, adjusted_height), Image.Resampling.BILINEAR)
|
||||
=======
|
||||
>>>>>>> db71d026f74322a6e66276701198bfe8b5d44ad8
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
|
||||
processed_image = np.array(processed_image_pil).astype(np.float32) / 255.0
|
||||
processed_image = torch.from_numpy(processed_image)
|
||||
processed_images.append(processed_image)
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
processed_mask = np.array(processed_mask_pil).astype(np.float32) / 255.0
|
||||
processed_mask = torch.from_numpy(processed_mask)
|
||||
processed_masks.append(processed_mask)
|
||||
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
=======
|
||||
>>>>>>> db71d026f74322a6e66276701198bfe8b5d44ad8
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
if size_option != "Custom":
|
||||
widths.append(target_width)
|
||||
heights.append(target_height)
|
||||
@@ -471,32 +328,12 @@ class ImageAdjuster:
|
||||
heights.append(adjusted_height)
|
||||
|
||||
output_image = torch.stack(processed_images)
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
output_mask = torch.stack(processed_masks)
|
||||
|
||||
if all(w == widths[0] for w in widths) and all(h == heights[0] for h in heights):
|
||||
return (output_image, output_mask, widths[0], heights[0])
|
||||
else:
|
||||
return (output_image, output_mask, widths[0], heights[0])
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
<<<<<<< HEAD
|
||||
=======
|
||||
=======
|
||||
|
||||
if all(w == widths[0] for w in widths) and all(h == heights[0] for h in heights):
|
||||
return (output_image, widths[0], heights[0])
|
||||
else:
|
||||
return (output_image, widths[0], heights[0])
|
||||
>>>>>>> db71d026f74322a6e66276701198bfe8b5d44ad8
|
||||
>>>>>>> 79ed250c5d0d1f11fccbec9087431ff25fc1e810
|
||||
>>>>>>> f14d0c29f81a549b32997f82e610ad71cdb4404c
|
||||
|
||||
def _resize_to_million_pixels(self, W, H):
|
||||
aspect_ratio = W / H
|
||||
|
||||
Reference in New Issue
Block a user