Skip to content

Commit

Permalink
update aci
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Mandic <[email protected]>
  • Loading branch information
vladmandic committed Feb 14, 2025
1 parent c430d32 commit 896fab1
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 22 deletions.
14 changes: 7 additions & 7 deletions html/locale_en.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,12 @@
{"id":"","label":"Loops","localized":"","hint":"How many times to process an image. Each output is used as the input of the next loop. If set to 1, behavior will be as if this script were not used"},
{"id":"","label":"Final denoising strength","localized":"","hint":"The denoising strength for the final loop of each image in the batch"},
{"id":"","label":"Denoising strength curve","localized":"","hint":"The denoising curve controls the rate of denoising strength change each loop. Aggressive: Most of the change will happen towards the start of the loops. Linear: Change will be constant through all loops. Lazy: Most of the change will happen towards the end of the loops"},
{"id":"","label":"Tile overlap","localized":"","hint":"For SD upscale, how much overlap in pixels should there be between tiles. Tiles overlap so that when they are merged back into one picture, there is no clearly visible seam"}
{"id":"","label":"Tile overlap","localized":"","hint":"For SD upscale, how much overlap in pixels should there be between tiles. Tiles overlap so that when they are merged back into one picture, there is no clearly visible seam"},
{"id":"","label":"ACI: Color to Mask","localized":"","hint":"Pick the color you want to mask and inpaint. Click on the color in the image to automatically select it.\n Advised to use images like green screens to get precise results."},
{"id":"","label":"ACI: Color Tolerance","localized":"","hint":"Adjust the tolerance to include similar colors in the mask. Lower values = mask only very similar colors. Higher = values mask a wider range of similar colors."},
{"id":"","label":"ACI: Mask Padding","localized":"","hint":"Adjust padding to apply a inside offset to the mask. (Recommended value = 2 to remove leftovers at edges)"},
{"id":"","label":"ACI: Mask Blur","localized":"","hint":"Adjust blur to apply a smooth transition between image and inpainted area. (Recommended value = 0 for sharpness)"},
{"id":"","label":"ACI: Denoising Strength","localized":"","hint":"Change Denoising Strength to achieve desired inpaint amount."}
],
"settings": [
{"id":"settings_submit","label":"Apply settings","localized":"","hint":"Save current settings, server restart is recommended"},
Expand Down Expand Up @@ -1248,11 +1253,6 @@
{"id":"","label":"zero","localized":"","hint":"zero"},
{"id":"","label":"zoe depth","localized":"","hint":"zoe depth"},
{"id":"","label":"➠ control","localized":"","hint":"➠ control"},
{"id":"","label":"💾","localized":"","hint":"💾"},
{"id":"","label":"ACI: Color to Mask","localized":"","hint":"Pick the color you want to mask and inpaint. Click on the color in the image to automatically select it.\n Advised to use images like green screens to get precise results."},
{"id":"","label":"ACI: Color Tolerance","localized":"","hint":"Adjust the tolerance to include similar colors in the mask. Lower values = mask only very similar colors. Higher = values mask a wider range of similar colors."},
{"id":"","label":"ACI: Mask Padding","localized":"","hint":"Adjust padding to apply a inside offset to the mask. (Recommended value = 2 to remove leftovers at edges)"},
{"id":"","label":"ACI: Mask Blur","localized":"","hint":"Adjust blur to apply a smooth transition between image and inpainted area. (Recommended value = 0 for sharpness)"},
{"id":"","label":"ACI: Denoising Strength","localized":"","hint":"Change Denoising Strength to achieve desired inpaint amount."}
{"id":"","label":"💾","localized":"","hint":"💾"}
]
}
31 changes: 16 additions & 15 deletions scripts/automatic_color_inpaint.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import gradio as gr
from diffusers.pipelines import StableDiffusionPipeline, StableDiffusionXLPipeline # pylint: disable=unused-import
from PIL import Image
import numpy as np
from modules import shared, scripts, processing
Expand Down Expand Up @@ -46,7 +45,7 @@ def ui(self, _is_img2img):
color_picker = gr.ColorPicker(
label="ACI: Color to Mask",
value="#04F404", # Default to green screen green
info="Pick the color you want to mask and inpaint."
# info="Pick the color you want to mask and inpaint."
)
tolerance_slider = gr.Slider(
minimum=0,
Expand All @@ -55,28 +54,29 @@ def ui(self, _is_img2img):
value=25,
label="ACI: Color Tolerance",
)
denoising_slider = gr.Slider(
minimum=0.01,
maximum=1,
step=0.01,
value=1,
label="ACI: Denoising Strength",
)
with gr.Row():
padding_slider = gr.Slider(
minimum=0,
maximum=256,
step=1,
value=2,
label="ACI: Mask Padding",
info="(Recommended value = 2 to remove leftovers at edges)"
# info="(Recommended value = 2 to remove leftovers at edges)"
)
blur_slider = gr.Slider(
minimum=0,
maximum=64,
step=1,
value=0,
label="ACI: Mask Blur",
info="(Recommended value = 0 for sharpness)"
)
denoising_slider = gr.Slider(
minimum=0.01,
maximum=1,
step=0.01,
value=1,
label="ACI: Denoising Strength",
# info="(Recommended value = 0 for sharpness)"
)
return [color_picker, tolerance_slider, padding_slider, blur_slider, denoising_slider]

Expand All @@ -90,15 +90,16 @@ def run(self, p: processing.StableDiffusionProcessing, *args): # pylint: disabl
# Convert hex color to RGB tuple (0-255)
color_to_mask_rgb = tuple(int(color_to_mask_hex[i:i+2], 16) for i in (1, 3, 5))

shared.log.debug(f'{title}: rgb={color_to_mask_rgb} tolerance={mask_tolerance} padding={mask_padding} blur={mask_blur} denoise={inpaint_denoising_strength}')
shared.log.debug(f'ACI: rgb={color_to_mask_rgb} tolerance={mask_tolerance} padding={mask_padding} blur={mask_blur} denoise={inpaint_denoising_strength}')

# Create Color Mask using vectorized operations
init_image = p.init_images[0].convert("RGB")
image_np = np.array(init_image)

# Calculate Euclidean distance for all pixels at once
diff = np.linalg.norm(image_np.astype(np.int16) - np.array(color_to_mask_rgb, dtype=np.int16), axis=2)
mask_np = (diff <= mask_tolerance).astype(np.uint8) * 255
calc_tolerance = (diff.max() - diff.min()) * mask_tolerance/100
mask_np = (diff <= calc_tolerance).astype(np.uint8) * 255

mask_image = Image.fromarray(mask_np).convert("L")

Expand All @@ -118,5 +119,5 @@ def run(self, p: processing.StableDiffusionProcessing, *args): # pylint: disabl
p.inpaint_full_res_padding = mask_padding
p.mask_blur = mask_blur
p.denoising_strength = inpaint_denoising_strength
return None

return None

0 comments on commit 896fab1

Please sign in to comment.