Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add "Show original image" option #100

Merged
merged 1 commit into from
Jun 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,13 @@ To remove the borders generated when pasting the image, mask all but the face an
When pasting the generated image to its original location, the rectangle of the detected face area is used. If this option is not enabled, the generated image itself is pasted. In other words, enabling this option applies a smaller face image, while disabling it applies a larger face image.

##### Save original image
Specify whether to save the image before modification.
This option allows you to save the original, unmodified image.

##### Show intermediate steps
Specifies whether to display images of detected faces and masks.
##### Show original image
This option allows you to display the original, unmodified image.

##### Show intermediate steps
This option enables the display of images that depict detected faces and masks.
If the generated image is unnatural, enabling it may reveal the cause.

##### Prompt for face
Expand Down
4 changes: 4 additions & 0 deletions scripts/entities/option.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Option:
DEFAULT_PROMPT_FOR_FACE = ""
DEFAULT_APPLY_INSIDE_MASK_ONLY = True
DEFAULT_SAVE_ORIGINAL_IMAGE = False
DEFAULT_SHOW_ORIGINAL_IMAGE = False
DEFAULT_SHOW_INTERMEDIATE_STEPS = False
DEFAULT_APPLY_SCRIPTS_TO_FACES = False
DEFAULT_FACE_SIZE = 512
Expand All @@ -33,6 +34,7 @@ def __init__(self, *args) -> None:
self.use_minimal_area = Option.DEFAULT_USE_MINIMAL_AREA
self.ignore_larger_faces = Option.DEFAULT_IGNORE_LARGER_FACES
self.affected_areas = Option.DEFAULT_AFFECTED_AREAS
self.show_original_image = Option.DEFAULT_SHOW_ORIGINAL_IMAGE

if len(args) > 0 and isinstance(args[0], dict):
self.update_by_dict(args[0])
Expand Down Expand Up @@ -65,6 +67,7 @@ def update_by_list(self, args: tuple) -> None:
self.use_minimal_area = args[13] if arg_len > 13 and isinstance(args[13], bool) else self.use_minimal_area
self.ignore_larger_faces = args[14] if arg_len > 14 and isinstance(args[14], bool) else self.ignore_larger_faces
self.affected_areas = args[15] if arg_len > 15 and isinstance(args[15], list) else self.affected_areas
self.show_original_image = args[16] if arg_len > 16 and isinstance(args[16], bool) else self.show_original_image

def update_by_dict(self, params: dict) -> None:
self.face_margin = params.get("face_margin", self.face_margin)
Expand All @@ -83,6 +86,7 @@ def update_by_dict(self, params: dict) -> None:
self.use_minimal_area = params.get("use_minimal_area", self.use_minimal_area)
self.ignore_larger_faces = params.get("ignore_larger_faces", self.ignore_larger_faces)
self.affected_areas = params.get("affected_areas", self.affected_areas)
self.show_original_image = params.get("show_original_image", self.show_original_image)

def to_dict(self) -> dict:
return {
Expand Down
17 changes: 11 additions & 6 deletions scripts/ui/ui_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,17 @@ def __build(self, is_img2img: bool):
)
self.infotext_fields.append((use_minimal_area, Option.add_prefix("use_minimal_area")))

save_original_image = gr.Checkbox(label="Save original image", value=Option.DEFAULT_SAVE_ORIGINAL_IMAGE)
self.infotext_fields.append((save_original_image, Option.add_prefix("save_original_image")))
with gr.Row():
save_original_image = gr.Checkbox(label="Save original image", value=Option.DEFAULT_SAVE_ORIGINAL_IMAGE)
self.infotext_fields.append((save_original_image, Option.add_prefix("save_original_image")))

show_intermediate_steps = gr.Checkbox(
label="Show intermediate steps", value=Option.DEFAULT_SHOW_INTERMEDIATE_STEPS
)
self.infotext_fields.append((show_intermediate_steps, Option.add_prefix("show_intermediate_steps")))
show_original_image = gr.Checkbox(label="Show original image", value=Option.DEFAULT_SHOW_ORIGINAL_IMAGE)
self.infotext_fields.append((show_original_image, Option.add_prefix("show_original_image")))

show_intermediate_steps = gr.Checkbox(
label="Show intermediate steps", value=Option.DEFAULT_SHOW_INTERMEDIATE_STEPS
)
self.infotext_fields.append((show_intermediate_steps, Option.add_prefix("show_intermediate_steps")))

prompt_for_face = gr.Textbox(
show_label=False,
Expand Down Expand Up @@ -142,4 +146,5 @@ def __build(self, is_img2img: bool):
use_minimal_area,
ignore_larger_faces,
affected_areas,
show_original_image,
]
5 changes: 4 additions & 1 deletion scripts/use_cases/image_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,10 @@ def proc_images(self, o: StableDiffusionProcessing, res: Processed, option: Opti
all_prompts.extend(proc.all_prompts)
infotexts.extend(proc.infotexts)

res.images.extend(edited_images)
if option.show_original_image:
res.images.extend(edited_images)
else:
res.images = edited_images
res.all_seeds.extend(all_seeds)
res.all_prompts.extend(all_prompts)
res.infotexts.extend(infotexts)
Expand Down