From 5bb3f6c558583fc7a135c36efb851a64646d7a57 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Sun, 15 Jan 2023 14:26:04 -0600 Subject: [PATCH] feat: add noise source with solid color --- api/onnx_web/image.py | 13 ++++++++++++- api/onnx_web/serve.py | 6 ++++-- gui/src/strings.ts | 11 ++++++----- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/api/onnx_web/image.py b/api/onnx_web/image.py index 2d9cdb3b..cfac3ee0 100644 --- a/api/onnx_web/image.py +++ b/api/onnx_web/image.py @@ -40,7 +40,7 @@ def mask_filter_gaussian_screen(mask_image: Image, dims: Tuple[int, int], origin return noise -def noise_source_fill(source_image: Image, dims: Tuple[int, int], origin: Tuple[int, int], fill='white') -> Image: +def noise_source_fill_edge(source_image: Image, dims: Tuple[int, int], origin: Tuple[int, int], fill='white') -> Image: ''' Identity transform, source image centered on white canvas. ''' @@ -52,6 +52,17 @@ def noise_source_fill(source_image: Image, dims: Tuple[int, int], origin: Tuple[ return noise +def noise_source_fill_mask(source_image: Image, dims: Tuple[int, int], origin: Tuple[int, int], fill='white') -> Image: + ''' + Fill the whole canvas, no source or noise. + ''' + width, height = dims + + noise = Image.new('RGB', (width, height), fill) + + return noise + + def noise_source_gaussian(source_image: Image, dims: Tuple[int, int], origin: Tuple[int, int], rounds=3) -> Image: ''' Gaussian blur, source image centered on white canvas. diff --git a/api/onnx_web/serve.py b/api/onnx_web/serve.py index 7813b12a..de3c3b88 100644 --- a/api/onnx_web/serve.py +++ b/api/onnx_web/serve.py @@ -36,10 +36,11 @@ from .image import ( mask_filter_gaussian_screen, mask_filter_none, # noise sources + noise_source_fill_edge, + noise_source_fill_mask, noise_source_gaussian, noise_source_histogram, noise_source_normal, - noise_source_fill, noise_source_uniform, ) @@ -86,7 +87,8 @@ pipeline_schedulers = { 'pndm': PNDMScheduler, } noise_sources = { - 'fill': noise_source_fill, + 'fill-edge': noise_source_fill_edge, + 'fill-mask': noise_source_fill_mask, 'gaussian': noise_source_gaussian, 'histogram': noise_source_histogram, 'normal': noise_source_normal, diff --git a/gui/src/strings.ts b/gui/src/strings.ts index 7aec7de2..fa9c2852 100644 --- a/gui/src/strings.ts +++ b/gui/src/strings.ts @@ -28,11 +28,12 @@ export const SCHEDULER_LABELS: Record = { }; export const NOISE_LABELS: Record = { - fill: 'Fill Edges', - gaussian: 'Gaussian Blur', - histogram: 'Histogram Noise', - normal: 'Gaussian Noise', - uniform: 'Uniform Noise', + 'fill-edge': 'Fill Edges', + 'fill-mask': 'Fill Masked', + 'gaussian': 'Gaussian Blur', + 'histogram': 'Histogram Noise', + 'normal': 'Gaussian Noise', + 'uniform': 'Uniform Noise', }; export const MASK_LABELS: Record = {