Skip to content

wasidy/auto_retoucher

Repository files navigation

AutoRetoucher - SDXL-based application for fast and quality retouching high-resolution photos

Requirements:

  • Python 3.10
  • Videocard with CUDA and minimum 12Gb VRAM

Installation:

  • copy files to folder and run install.bat
  • copy SDXL checkpoints to 'models' folder
  • launch run.bat and open 127.0.0.1:7860 in your browser

Usage

This application is mainly used for retouching portraits with a lot of exposed body areas that require careful retouching, such as shootings in lingerie, swimsuits or explicit erotic. Manual retouching with frequency separation requires considerable time and high qualification of a retoucher. Base SDXL Img2Img pipeline allows you to get quality results, but it limited to optimal size of image, 1024х1024 for example. AutoRetoucher creates a perfect result with the following steps:

  • creating mask for human figure on image (using Mask2Former with fusing masks if more than one person)
  • splitting source image with mask to tiles size of 1024x1024 px (or you can select another value, but SDXL trained on this size)
  • generating new tiles with specified parameters of generation (denoise steps, and generation steps) and common prompt
  • compiling result tiles with blending and paste new image to original background with generated mask
  • after generation you can regenerate any part of image with custom prompt and paste it again
  • also batching is supported
  • the application is also suitable for retouching close-up portraits, but I recommend to resize it smaller for best result
  • for the final you can load PNG file into Photoshop, as a new layer over original image, and apply mask for some areas

Interface

image

  1. Input image. Click for load source file. If file too small, it will be upscaled.
  2. Main control buttons. GENERATE start generation of all tiles, STOP stops generation without errors, Reset all parameters resets all sliders to default values.
  3. Positive and negative prompt for whole image. Be carefully with specified prompt. Some tiles do not correspondent prompt, especially at large denoising values.
  4. Image processing. You can ROTATE your image, RESIZE for short side value. COPY INPUT TO OUTPUT allows you to generate and paste custom tiles without whole generation. RESIZE BATCH checkbox means resizing all batch images to specified size. MASK BLUR determines value for blurring mask before final paste with alpha on background. MASK EXPAND is size of expansion mask before blurring. FILL MASK fills whole image with mask. For examle, you want to proceed background, or humag figure was not recognized. REMAKE FIGURE MASK regenerates mask with new blur and expand parameters.
  5. Grid processing. Minimum overlap is minimum overlap between tiles. Too small value decreases amount of tiles, but can worse quality of mixing tiles. Tile size is size of grid's tile. 1024x1024 optiman for SDXL, but another values is allowed. Minimum density is value for grid computation. If too smal part of masked image in tile, there is no necessary to gerenate it. Value in percent. REMESH GRID recalculates grid with new values.
  6. Generation settings. Denoise strength is denoising strength for Img2Img pipeline. For skin retouching is fine value between 5-10. Higher values can do more affect for regenerating, but it may couse mismatch lines, countoures and texture in different tiles. Batch size is number of simultaneously generated tiles. It depends of your videocard memory and tile size. Steps is amount of generation steps. More steps - better quality. 50 is enough.
  7. Output image. After generation you can save PNG file with clicking RMB.
  8. Regenerate custom tile. As source for regenerating you can click LMB on any area input OR output image. Tile will be loaded in window.
  9. Tile masking is value for box alpha. Apply generated mask means that the generation result will be applied only to the area on which the base mask was generated. APPLY TO IMAGE will paste generated tile to original coordinates onto output image, with blur settings. Prompt and Negative prompt is custom prompt for single tile generation.
  10. Added ability to automatic saving generated result, and saving outputs by button pressing.

Sample images are copyrighted by Vasiliy Stepanov.