diff --git a/assets/females/1.png b/assets/females/1.png index 2fd7549..a7189bd 100644 Binary files a/assets/females/1.png and b/assets/females/1.png differ diff --git a/assets/females/10.png b/assets/females/10.png index efc7ff1..1ef8402 100644 Binary files a/assets/females/10.png and b/assets/females/10.png differ diff --git a/assets/females/11.png b/assets/females/11.png index fa6b40e..ee5ff64 100644 Binary files a/assets/females/11.png and b/assets/females/11.png differ diff --git a/assets/females/12.png b/assets/females/12.png index e08cb6f..c04946b 100644 Binary files a/assets/females/12.png and b/assets/females/12.png differ diff --git a/assets/females/13.png b/assets/females/13.png index 0cbdc5d..f80ab9b 100644 Binary files a/assets/females/13.png and b/assets/females/13.png differ diff --git a/assets/females/14.png b/assets/females/14.png index 67710b6..412e48e 100644 Binary files a/assets/females/14.png and b/assets/females/14.png differ diff --git a/assets/females/15.png b/assets/females/15.png index 7b9466b..135d44b 100644 Binary files a/assets/females/15.png and b/assets/females/15.png differ diff --git a/assets/females/16.png b/assets/females/16.png deleted file mode 100644 index aae3480..0000000 Binary files a/assets/females/16.png and /dev/null differ diff --git a/assets/females/2.png b/assets/females/2.png index 5bb1220..d046ee3 100644 Binary files a/assets/females/2.png and b/assets/females/2.png differ diff --git a/assets/females/3.png b/assets/females/3.png index 38593c8..2a064a1 100644 Binary files a/assets/females/3.png and b/assets/females/3.png differ diff --git a/assets/females/4.png b/assets/females/4.png index 34c5543..f66a69d 100644 Binary files a/assets/females/4.png and b/assets/females/4.png differ diff --git a/assets/females/5.png b/assets/females/5.png index 88bf1e3..c00d49b 100644 Binary files a/assets/females/5.png and b/assets/females/5.png differ diff --git a/assets/females/6.png b/assets/females/6.png index 95525d4..f856ee0 100644 Binary files a/assets/females/6.png and b/assets/females/6.png differ diff --git a/assets/females/7.png b/assets/females/7.png index 80f543d..83b835b 100644 Binary files a/assets/females/7.png and b/assets/females/7.png differ diff --git a/assets/females/8.png b/assets/females/8.png index 65c4c1e..b36facc 100644 Binary files a/assets/females/8.png and b/assets/females/8.png differ diff --git a/assets/females/9.png b/assets/females/9.png index 0d8c783..2a6d5ef 100644 Binary files a/assets/females/9.png and b/assets/females/9.png differ diff --git a/assets/males/1.png b/assets/males/1.png index 4d46e24..0981a38 100644 Binary files a/assets/males/1.png and b/assets/males/1.png differ diff --git a/assets/males/10.png b/assets/males/10.png index 65ae243..1ba1ced 100644 Binary files a/assets/males/10.png and b/assets/males/10.png differ diff --git a/assets/males/11.png b/assets/males/11.png index cc7771b..2b20ed9 100644 Binary files a/assets/males/11.png and b/assets/males/11.png differ diff --git a/assets/males/12.png b/assets/males/12.png index ce9d6bf..7b2689f 100644 Binary files a/assets/males/12.png and b/assets/males/12.png differ diff --git a/assets/males/13.png b/assets/males/13.png index b6f9a63..e1d53cf 100644 Binary files a/assets/males/13.png and b/assets/males/13.png differ diff --git a/assets/males/14.png b/assets/males/14.png index bfb5ff0..88dc323 100644 Binary files a/assets/males/14.png and b/assets/males/14.png differ diff --git a/assets/males/15.png b/assets/males/15.png index 2e0fa74..616e1ce 100644 Binary files a/assets/males/15.png and b/assets/males/15.png differ diff --git a/assets/males/2.png b/assets/males/2.png index 73eb453..2d6f2a3 100644 Binary files a/assets/males/2.png and b/assets/males/2.png differ diff --git a/assets/males/3.png b/assets/males/3.png index 546bef6..6da0131 100644 Binary files a/assets/males/3.png and b/assets/males/3.png differ diff --git a/assets/males/4.png b/assets/males/4.png index fc36c21..4ca343c 100644 Binary files a/assets/males/4.png and b/assets/males/4.png differ diff --git a/assets/males/5.png b/assets/males/5.png index 9e0e7fd..403d873 100644 Binary files a/assets/males/5.png and b/assets/males/5.png differ diff --git a/assets/males/6.png b/assets/males/6.png index a8c4208..8b43788 100644 Binary files a/assets/males/6.png and b/assets/males/6.png differ diff --git a/assets/males/7.png b/assets/males/7.png index 17ef0c8..5d8f39a 100644 Binary files a/assets/males/7.png and b/assets/males/7.png differ diff --git a/assets/males/8.png b/assets/males/8.png index 9a4e9d0..0600a5b 100644 Binary files a/assets/males/8.png and b/assets/males/8.png differ diff --git a/assets/males/9.png b/assets/males/9.png index c12caf2..7f4066d 100644 Binary files a/assets/males/9.png and b/assets/males/9.png differ diff --git a/tools/img_gen/gen_img.py b/tools/img_gen/gen_img.py index 8d5d38d..8962951 100644 --- a/tools/img_gen/gen_img.py +++ b/tools/img_gen/gen_img.py @@ -89,7 +89,7 @@ def generate_qwen_image(prompt: str, *, size: str = "1328*1328") -> str: raise RuntimeError("未获得图片结果") -def save_generated_image(query: str) -> str: +def save_generated_image(query: str, folder: str = "tools/img_gen/tmp/raw") -> str: """根据查询生成图片并保存到 result 目录。 入参: @@ -101,7 +101,7 @@ def save_generated_image(query: str) -> str: b64 = generate_qwen_image(query) img_bytes = base64.b64decode(b64) - result_dir = "tools/img_gen/tmp/raw" + result_dir = folder os.makedirs(result_dir, exist_ok=True) filename = datetime.now().strftime("%Y%m%d_%H%M%S") + ".png" @@ -156,7 +156,7 @@ if __name__ == "__main__": for affix in male_affixes: prompt_text = male_prompt_base + affix - save_generated_image(prompt_text) + save_generated_image(prompt_text, folder="tools/img_gen/tmp/males") for affix in female_affixes: prompt_text = female_prompt_base + affix - save_generated_image(prompt_text) \ No newline at end of file + save_generated_image(prompt_text, folder="tools/img_gen/tmp/females") \ No newline at end of file diff --git a/tools/img_gen/remove_bg.py b/tools/img_gen/remove_bg.py index 5a0939b..92472d1 100644 --- a/tools/img_gen/remove_bg.py +++ b/tools/img_gen/remove_bg.py @@ -169,6 +169,7 @@ def process( white_threshold: int = 240, output: Optional[PathLike] = None, show_progress: bool = False, + resize_to: Optional[tuple[int, int]] = (512, 512), ) -> Image.Image: """先裁边后去白底的组合处理函数。""" @@ -178,6 +179,10 @@ def process( white_threshold=white_threshold, show_progress=show_progress ) + + # 压缩图片到指定尺寸 + if resize_to is not None: + cleaned = cleaned.resize(resize_to, Image.Resampling.LANCZOS) if output is not None: cleaned.save(output) @@ -193,6 +198,8 @@ def process_all( white_threshold: int = 240, show_progress: bool = True, show_detail_progress: bool = False, + resize_to: Optional[tuple[int, int]] = (512, 512), + rename_by_index: bool = True, ) -> list[Path]: """ 遍历目录内的图像文件,批量处理并保存到目标目录。 @@ -204,6 +211,8 @@ def process_all( white_threshold: 白色阈值 show_progress: 是否显示批处理进度条 show_detail_progress: 是否显示每张图片的详细处理进度(洪水填充进度) + resize_to: 调整图片尺寸,None表示不调整 + rename_by_index: 是否按索引重命名为 1.png, 2.png... """ input_path = Path(input_dir) @@ -228,14 +237,30 @@ def process_all( white_threshold=white_threshold, output=target, show_progress=show_detail_progress, + resize_to=resize_to, ) saved_files.append(target) + + # 根据索引重命名文件 + if rename_by_index and saved_files: + renamed_files: list[Path] = [] + for index, old_path in enumerate(saved_files, start=1): + new_name = f"{index}.png" + new_path = output_path / new_name + old_path.rename(new_path) + renamed_files.append(new_path) + return renamed_files return saved_files if __name__ == "__main__": process_all( - input_dir="tools/img_gen/tmp/raw", - output_dir="tools/img_gen/tmp/processed", + input_dir="tools/img_gen/tmp/males", + output_dir="tools/img_gen/tmp/processed_males", + crop_fraction=1 / 16, + ) + process_all( + input_dir="tools/img_gen/tmp/females", + output_dir="tools/img_gen/tmp/processed_females", crop_fraction=1 / 16, ) \ No newline at end of file