feat(*): add latent scale options

This commit is contained in:
Карпич Дмитрий Александрович
2026-04-26 02:50:54 +03:00
parent 7402ccc0e5
commit 02cb40b55c
2 changed files with 29 additions and 16 deletions
+20 -5
View File
@@ -1,7 +1,15 @@
from numpy import ndarray
from typing import Union
from .util import get_sizes
from .util import get_latent_size, get_image_size
SCALE_8X = "SD, Qwen (8x)"
SCALE_16X = "Flux2 (16x)"
SCALE_OPTIONS = [SCALE_8X, SCALE_16X]
SCALE_FACTOR_MAP = {
SCALE_8X: 8,
SCALE_16X: 16,
}
class OFOImageFit:
@@ -11,7 +19,11 @@ class OFOImageFit:
@classmethod
def INPUT_TYPES(s):
return {
"required": {"latent": ("LATENT",), "image": ("IMAGE",)},
"required": {
"latent": ("LATENT",),
"image": ("IMAGE",),
"latent_scale": (SCALE_OPTIONS,),
},
"optional": {
"width_position": (
"FLOAT",
@@ -76,6 +88,7 @@ class OFOImageFit:
self,
latent: Union[dict, ndarray],
image: ndarray,
latent_scale: str,
width_position: float = 0.5,
height_position: float = 0.5,
scale: float = 1.0,
@@ -86,6 +99,7 @@ class OFOImageFit:
Args:
latent (np.ndarray or dict): Latent representation or dictionary containing latent samples.
image (np.ndarray): Input image to be resized and padded.
latent_scale (str): Latent scale factor option. "SD, Qwen (8x)" or "Flux2 (16x)".
width_position (float, optional): Horizontal position where the image will be placed within the latent space. Defaults to 0.5.
height_position (float, optional): Vertical position where the image will be placed within the latent space. Defaults to 0.5.
scale (float, optional): Scaling factor applied to the image before resizing. Defaults to 1.0.
@@ -93,9 +107,10 @@ class OFOImageFit:
Returns:
tuple: A tuple containing six integers representing the new width, height, top, right, bottom, and left padding values.
"""
# get sizes
latent_height, latent_width = get_sizes(latent)
image_height, image_width = get_sizes(image)
scale_factor = SCALE_FACTOR_MAP[latent_scale]
latent_height, latent_width = get_latent_size(latent, scale_factor)
image_height, image_width = get_image_size(image)
# get minimum scale
scale_w = latent_width / image_width
+9 -11
View File
@@ -1,14 +1,12 @@
from numpy import ndarray
from typing import Union, Tuple
# latent to pixel scale factor
SCALE = 8
from typing import Tuple
def get_sizes(target: Union[dict, ndarray]) -> Tuple[int, int]:
if isinstance(target, dict) and "samples" in target:
# Latent height, width
return (target["samples"].shape[2] * SCALE, target["samples"].shape[3] * SCALE)
else:
# Image height, width
return (target.shape[1], target.shape[2])
def get_latent_size(latent: dict, scale_factor: int = 8) -> Tuple[int, int]:
"""Convert latent dimensions to pixel dimensions using scale factor."""
return (latent["samples"].shape[2] * scale_factor, latent["samples"].shape[3] * scale_factor)
def get_image_size(image: ndarray) -> Tuple[int, int]:
"""Get image height and width from numpy array."""
return (image.shape[1], image.shape[2])