├── README.md └── scripts └── pixel_fix.py /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Pixel Fix Plugin for sd-webui 3 | 4 | Hello everyone, 5 | 6 | This plugin is designed for repairing corrupted pixel art in sd-webui. Due to alignment issues with pixel particles when running pixel images in SD, I have created this simple pixel repair plugin. 7 | 8 | ## Usage 9 | 1.Install PIL: 10 | 11 | 12 | pip install Pillow 13 | 14 | 15 | 2.Download the plugin and place it in the following path: 16 | your_path\sd-webui-aki-v4.2\extensions 17 | Launch sd-webui, and you will find "Pixel Fix" in the lower-left corner of the interface. 18 | Check the enable box, adjust the pixel particle size, and run the image normally. 19 | After running, you will have both the original and the repaired images: 20 | 21 | 22 | .Before Repair: 23 | ![前](https://github.com/sd47942452/sd-webui-pixel-fix/assets/8718711/7f0e07ff-c036-40ed-9df6-58d15aab55e5) 24 | .After Repair: 25 | ![后](https://github.com/sd47942452/sd-webui-pixel-fix/assets/8718711/92f819dc-7bf2-4607-9e89-6b301226dc96) 26 | 27 | 28 | 29 | # Pixel Fix Plugin for sd-webui 30 | 大家好, 31 | 32 | 这个插件是专为修复在sd-webui中的像素艺术而设计的。由于在SD中运行像素图像时像素颗粒的对齐问题,我创建了这个简单的像素修复插件。 33 | 34 | ## Usage 35 | 安装PIL: 36 | 37 | 38 | pip install Pillow 39 | 40 | 41 | 下载插件并将其放置在以下路径: 42 | 43 | 44 | 你的路径\sd-webui-aki-v4.2\extensions 45 | 启动sd-webui,你将在界面的左下角找到 "Pixel Fix"。 46 | 47 | 勾选启用框,调整像素颗粒的大小,然后正常运行图像。 48 | 49 | 运行后,你将拥有原始图像和修复后的图像: 50 | 51 | 修复前: 前 52 | ![前](https://github.com/sd47942452/sd-webui-pixel-fix/assets/8718711/7f0e07ff-c036-40ed-9df6-58d15aab55e5) 53 | 修复后: 后 54 | ![后](https://github.com/sd47942452/sd-webui-pixel-fix/assets/8718711/92f819dc-7bf2-4607-9e89-6b301226dc96) 55 | -------------------------------------------------------------------------------- /scripts/pixel_fix.py: -------------------------------------------------------------------------------- 1 | from PIL import Image 2 | import gradio as gr 3 | import modules.scripts as scripts 4 | from modules import images 5 | from modules.shared import opts 6 | 7 | 8 | class Script(scripts.Script): 9 | print('像素修复插件已加载...') 10 | 11 | def title(self): 12 | return "像素修复" 13 | 14 | # 显示插件界面 15 | def show(self, is_img2img): 16 | return scripts.AlwaysVisible 17 | 18 | # 加载UI 19 | def ui(self, is_img2img): 20 | with gr.Accordion("像素修复", open=False): 21 | with gr.Row(): 22 | enabled = gr.Checkbox(label="Enable(是否启用)", value=False) 23 | 24 | with gr.Column(): 25 | with gr.Row(): 26 | pixel_size = gr.Slider(label="Pixel Size recommend:8(像素颗粒大小,推荐值:8)", minimum=1, maximum=32, 27 | step=1, value=8) 28 | 29 | return [enabled, pixel_size] 30 | 31 | # 读取图片进程 32 | def postprocess(self, p, processed, enabled, pixel_size): 33 | 34 | # 是否启用 35 | if not enabled: 36 | return 37 | 38 | # 简单的像素对齐处理 39 | def process_image(original_image): 40 | small = original_image.resize((original_image.width // pixel_size, original_image.height // pixel_size), 41 | resample=Image.NEAREST) 42 | return small.resize((original_image.width, original_image.height), resample=Image.NEAREST) 43 | 44 | # 批量处理 45 | for i in range(len(processed.images)): 46 | pixel_image = process_image(processed.images[i]) 47 | processed.images.append(pixel_image) 48 | images.save_image(pixel_image, p.outpath_samples, "pixel", 49 | processed.seed + i, processed.prompt, opts.samples_format, info=processed.info, p=p) 50 | 51 | return processed 52 | --------------------------------------------------------------------------------