Skip to content

Commit

Permalink
feat: add noise source with solid color
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Jan 15, 2023
1 parent 16108ae commit 5bb3f6c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
13 changes: 12 additions & 1 deletion api/onnx_web/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
'''
Expand All @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions api/onnx_web/serve.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@
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,
)

Expand Down Expand Up @@ -86,7 +87,8 @@
'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,
Expand Down
11 changes: 6 additions & 5 deletions gui/src/strings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ export const SCHEDULER_LABELS: Record<string, string> = {
};

export const NOISE_LABELS: Record<string, string> = {
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<string, string> = {
Expand Down

0 comments on commit 5bb3f6c

Please sign in to comment.