Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmandic committed Oct 24, 2023
1 parent 636560c commit e7dc410
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 17 deletions.
2 changes: 1 addition & 1 deletion scripts/outpainting_mk_2.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def expand(init, count, expand_pixels, is_left=False, is_right=False, is_top=Fal
np_image = (np.asarray(img) / 255.0).astype(np.float64)
np_mask = (np.asarray(mask) / 255.0).astype(np.float64)
noised = get_matched_noise(np_image, np_mask, noise_q, color_variation)
output_images.append(Image.fromarray(np.clip(noised * 255., 0., 255.).astype(np.uint8), mode="RGB"))
output_images.append(Image.fromarray(np.clip(255.0 * noised, 0.0, 255.0).astype(np.uint8), mode="RGB"))

target_width = min(process_width, init[n].width + pixels_horiz) if is_horiz else img.width
target_height = min(process_height, init[n].height + pixels_vert) if is_vert else img.height
Expand Down
9 changes: 1 addition & 8 deletions scripts/postprocessing_codeformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,15 @@ def ui(self):
with FormRow():
codeformer_visibility = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label="Strength", value=0.0, elem_id="extras_codeformer_visibility")
codeformer_weight = gr.Slider(minimum=0.0, maximum=1.0, step=0.01, label="Weight", value=0.2, elem_id="extras_codeformer_weight")

return {
"codeformer_visibility": codeformer_visibility,
"codeformer_weight": codeformer_weight,
}
return { "codeformer_visibility": codeformer_visibility, "codeformer_weight": codeformer_weight }

def process(self, pp: scripts_postprocessing.PostprocessedImage, codeformer_visibility, codeformer_weight): # pylint: disable=arguments-differ
if codeformer_visibility == 0:
return

restored_img = codeformer_model.codeformer.restore(np.array(pp.image, dtype=np.uint8), w=codeformer_weight)
res = Image.fromarray(restored_img)

if codeformer_visibility < 1.0:
res = Image.blend(pp.image, res, codeformer_visibility)

pp.image = res
pp.info["CodeFormer visibility"] = round(codeformer_visibility, 3)
pp.info["CodeFormer weight"] = round(codeformer_weight, 3)
10 changes: 2 additions & 8 deletions scripts/postprocessing_gfpgan.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,14 @@ class ScriptPostprocessingGfpGan(scripts_postprocessing.ScriptPostprocessing):
def ui(self):
with FormRow():
gfpgan_visibility = gr.Slider(minimum=0.0, maximum=1.0, step=0.001, label="Strength", value=0, elem_id="extras_gfpgan_visibility")
return { "gfpgan_visibility": gfpgan_visibility }

return {
"gfpgan_visibility": gfpgan_visibility,
}

def process(self, pp: scripts_postprocessing.PostprocessedImage, gfpgan_visibility):
def process(self, pp: scripts_postprocessing.PostprocessedImage, gfpgan_visibility): # pylint: disable=arguments-differ
if gfpgan_visibility == 0:
return

restored_img = gfpgan_model.gfpgan_fix_faces(np.array(pp.image, dtype=np.uint8))
res = Image.fromarray(restored_img)

if gfpgan_visibility < 1.0:
res = Image.blend(pp.image, res, gfpgan_visibility)

pp.image = res
pp.info["GFPGAN visibility"] = round(gfpgan_visibility, 3)

0 comments on commit e7dc410

Please sign in to comment.