Add SigmasToFloat

This commit is contained in:
kijai 2024-11-03 20:00:49 +02:00
parent d9191b4c1d
commit 3e11fff5f5
3 changed files with 35 additions and 7 deletions

View File

@ -132,6 +132,7 @@ NODE_CONFIG = {
"WeightScheduleConvert": {"class": WeightScheduleConvert, "name": "Weight Schedule Convert"},
"FloatToMask": {"class": FloatToMask, "name": "Float To Mask"},
"FloatToSigmas": {"class": FloatToSigmas, "name": "Float To Sigmas"},
"SigmasToFloat": {"class": SigmasToFloat, "name": "Sigmas To Float"},
"PlotCoordinates": {"class": PlotCoordinates, "name": "Plot Coordinates"},
"InterpolateCoords": {"class": InterpolateCoords, "name": "Interpolate Coords"},
"PointsEditor": {"class": PointsEditor, "name": "Points Editor"},

View File

@ -934,6 +934,25 @@ Creates a sigmas tensor from list of float values.
def customsigmas(self, float_list):
return torch.tensor(float_list, dtype=torch.float32),
class SigmasToFloat:
@classmethod
def INPUT_TYPES(s):
return {"required":
{
"sigmas": ("SIGMAS",),
}
}
RETURN_TYPES = ("FLOAT",)
RETURN_NAMES = ("float",)
CATEGORY = "KJNodes/noise"
FUNCTION = "customsigmas"
DESCRIPTION = """
Creates a float list from sigmas tensors.
"""
def customsigmas(self, sigmas):
return sigmas.tolist(),
class GLIGENTextBoxApplyBatchCoords:
@classmethod
def INPUT_TYPES(s):

View File

@ -2410,6 +2410,9 @@ class ImageCropByMaskAndResize:
"mask": ("MASK", ),
"base_resolution": ("INT", { "default": 512, "min": 0, "max": MAX_RESOLUTION, "step": 8, }),
"padding": ("INT", { "default": 0, "min": 0, "max": MAX_RESOLUTION, "step": 1, }),
"min_crop_resolution": ("INT", { "default": 128, "min": 0, "max": MAX_RESOLUTION, "step": 8, }),
"max_crop_resolution": ("INT", { "default": 512, "min": 0, "max": MAX_RESOLUTION, "step": 8, }),
},
}
@ -2418,7 +2421,7 @@ class ImageCropByMaskAndResize:
FUNCTION = "crop"
CATEGORY = "KJNodes/image"
def crop_by_mask(self, mask, padding=0):
def crop_by_mask(self, mask, padding=0, min_crop_resolution=None, max_crop_resolution=None):
iy, ix = (mask == 1).nonzero(as_tuple=True)
h0, w0 = mask.shape
@ -2442,14 +2445,19 @@ class ImageCropByMaskAndResize:
x_c = (x_min + x_max) / 2.0
y_c = (y_min + y_max) / 2.0
width_half = width / 2.0
height_half = height / 2.0
if min_crop_resolution:
width = max(width, min_crop_resolution)
height = max(height, min_crop_resolution)
if max_crop_resolution:
width = min(width, max_crop_resolution)
height = min(height, max_crop_resolution)
if w0 <= width:
x0 = 0
w = w0
else:
x0 = max(0, x_c - width_half - padding)
x0 = max(0, x_c - width / 2 - padding)
w = width + 2 * padding
if x0 + w > w0:
x0 = w0 - w
@ -2458,19 +2466,19 @@ class ImageCropByMaskAndResize:
y0 = 0
h = h0
else:
y0 = max(0, y_c - height_half - padding)
y0 = max(0, y_c - height / 2 - padding)
h = height + 2 * padding
if y0 + h > h0:
y0 = h0 - h
return (int(x0), int(y0), int(w), int(h))
def crop(self, image, mask, base_resolution, padding=0):
def crop(self, image, mask, base_resolution, padding=0, min_crop_resolution=128, max_crop_resolution=512):
image_list = []
mask_list = []
bbox_list = []
for i in range(image.shape[0]):
x0, y0, w, h = self.crop_by_mask(mask[i], padding)
x0, y0, w, h = self.crop_by_mask(mask[i], padding, min_crop_resolution, max_crop_resolution)
cropped_image = image[i][y0:y0+h, x0:x0+w, :]
cropped_mask = mask[i][y0:y0+h, x0:x0+w]