代码拉取完成,页面将自动刷新
import torch
import numpy as np
import scipy
import os
#import re
from pathlib import Path
import folder_paths
FONTS_DIR = os.path.join(os.path.dirname(os.path.realpath(__file__)), "fonts")
SCRIPT_DIR = Path(__file__).parent
folder_paths.add_model_folder_path("luts", (SCRIPT_DIR / "luts").as_posix())
folder_paths.add_model_folder_path(
"luts", (Path(folder_paths.models_dir) / "luts").as_posix()
)
# from https://github.com/pythongosssss/ComfyUI-Custom-Scripts
class AnyType(str):
def __ne__(self, __value: object) -> bool:
return False
def min_(tensor_list):
# return the element-wise min of the tensor list.
x = torch.stack(tensor_list)
mn = x.min(axis=0)[0]
return torch.clamp(mn, min=0)
def max_(tensor_list):
# return the element-wise max of the tensor list.
x = torch.stack(tensor_list)
mx = x.max(axis=0)[0]
return torch.clamp(mx, max=1)
def expand_mask(mask, expand, tapered_corners):
c = 0 if tapered_corners else 1
kernel = np.array([[c, 1, c],
[1, 1, 1],
[c, 1, c]])
mask = mask.reshape((-1, mask.shape[-2], mask.shape[-1]))
out = []
for m in mask:
output = m.numpy()
for _ in range(abs(expand)):
if expand < 0:
output = scipy.ndimage.grey_erosion(output, footprint=kernel)
else:
output = scipy.ndimage.grey_dilation(output, footprint=kernel)
output = torch.from_numpy(output)
out.append(output)
return torch.stack(out, dim=0)
def parse_string_to_list(s):
elements = s.split(',')
result = []
def parse_number(s):
try:
if '.' in s:
return float(s)
else:
return int(s)
except ValueError:
return 0
def decimal_places(s):
if '.' in s:
return len(s.split('.')[1])
return 0
for element in elements:
element = element.strip()
if '...' in element:
start, rest = element.split('...')
end, step = rest.split('+')
decimals = decimal_places(step)
start = parse_number(start)
end = parse_number(end)
step = parse_number(step)
current = start
if (start > end and step > 0) or (start < end and step < 0):
step = -step
while current <= end:
result.append(round(current, decimals))
current += step
else:
result.append(round(parse_number(element), decimal_places(element)))
return result
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。