feat(api): add edge options to region feathering
This commit is contained in:
parent
5fb2de85c5
commit
1fae41ddcf
|
@ -95,6 +95,7 @@ def make_tile_mask(
|
|||
shape: Any,
|
||||
tile: Tuple[int, int],
|
||||
overlap: float,
|
||||
edges: Tuple[bool, bool, bool, bool],
|
||||
) -> np.ndarray:
|
||||
mask = np.ones(shape)
|
||||
|
||||
|
@ -113,7 +114,7 @@ def make_tile_mask(
|
|||
points_w = [0, min(p1_w, p2_w), max(p1_w, p2_w), tile_w]
|
||||
|
||||
# build gradients
|
||||
grad_x, grad_y = [0, 1, 1, 0], [0, 1, 1, 0]
|
||||
grad_x, grad_y = [int(edges[0]), 1, 1, int(edges[2])], [int(edges[1]), 1, 1, int(edges[3])]
|
||||
logger.debug("tile gradients: %s, %s, %s, %s", points_w, points_h, grad_x, grad_y)
|
||||
|
||||
mult_x = [np.interp(i, points_w, grad_x) for i in range(tile_w)]
|
||||
|
|
|
@ -671,11 +671,12 @@ class OnnxStableDiffusionPanoramaPipeline(DiffusionPipeline):
|
|||
)
|
||||
latents_region_denoised = scheduler_output.prev_sample.numpy()
|
||||
|
||||
if feather > 0.0:
|
||||
if feather[0] > 0.0:
|
||||
mask = make_tile_mask(
|
||||
(h_end - h_start, w_end - w_start),
|
||||
(h_end - h_start, w_end - w_start),
|
||||
feather,
|
||||
feather[0],
|
||||
feather[1],
|
||||
)
|
||||
mask = np.expand_dims(mask, axis=0)
|
||||
mask = np.repeat(mask, 4, axis=0)
|
||||
|
|
|
@ -520,11 +520,12 @@ class StableDiffusionXLPanoramaPipelineMixin(StableDiffusionXLImg2ImgPipelineMix
|
|||
)
|
||||
latents_region_denoised = scheduler_output.prev_sample.numpy()
|
||||
|
||||
if feather > 0.0:
|
||||
if feather[0] > 0.0:
|
||||
mask = make_tile_mask(
|
||||
(h_end - h_start, w_end - w_start),
|
||||
(h_end - h_start, w_end - w_start),
|
||||
feather,
|
||||
feather[0],
|
||||
feather[1],
|
||||
)
|
||||
mask = np.expand_dims(mask, axis=0)
|
||||
mask = np.repeat(mask, 4, axis=0)
|
||||
|
|
|
@ -22,7 +22,7 @@ INVERSION_TOKEN = compile(r"\<inversion:([^:\>]+):(-?[\.|\d]+)\>")
|
|||
LORA_TOKEN = compile(r"\<lora:([^:\>]+):(-?[\.|\d]+)\>")
|
||||
WILDCARD_TOKEN = compile(r"__([-/\\\w]+)__")
|
||||
REGION_TOKEN = compile(
|
||||
r"\<region:(\d+):(\d+):(\d+):(\d+):(-?[\.|\d]+):(-?[\.|\d]+):([^\>]+)\>"
|
||||
r"\<region:(\d+):(\d+):(\d+):(\d+):(-?[\.|\d]+):(-?[\.|\d]+_?[TLBR]*):([^\>]+)\>"
|
||||
)
|
||||
RESEED_TOKEN = compile(r"\<reseed:(\d+):(\d+):(\d+):(\d+):(-?\d+)\>")
|
||||
|
||||
|
@ -455,18 +455,28 @@ def slice_prompt(prompt: str, slice: int) -> str:
|
|||
return prompt
|
||||
|
||||
|
||||
Region = Tuple[int, int, int, int, float, str]
|
||||
Region = Tuple[int, int, int, int, float, Tuple[float, Tuple[bool, bool, bool, bool]], str]
|
||||
|
||||
|
||||
def parse_region_group(group) -> Region:
|
||||
def parse_region_group(group: Tuple[str, ...]) -> Region:
|
||||
top, left, bottom, right, weight, feather, prompt = group
|
||||
|
||||
# break down the feather section
|
||||
feather_radius, *feather_edges = feather.split("_")
|
||||
feather_edges = "".join(feather_edges)
|
||||
|
||||
return (
|
||||
int(top),
|
||||
int(left),
|
||||
int(bottom),
|
||||
int(right),
|
||||
float(weight),
|
||||
float(feather),
|
||||
(float(feather_radius), (
|
||||
"T" in feather_edges,
|
||||
"L" in feather_edges,
|
||||
"B" in feather_edges,
|
||||
"R" in feather_edges,
|
||||
)),
|
||||
prompt,
|
||||
)
|
||||
|
||||
|
|
Loading…
Reference in New Issue