AI Painting Stable Diffusion Research (9) Detailed Explanation of sd Image Generation Function-Old Photos HD Restoration and Enlargement


Hello everyone, I am rain or shine.


Through the introduction of the previous articles, I believe that everyone has a new understanding of Stable Diffusion, a powerful AI drawing system. We have seen that with the help of Stable Diffusion's Vincent diagram function, a perfect picture can be generated with a few simple words. In this issue, let's study the treasure of the Stable Diffusion map generation function.


For new friends, if you want to learn more about Stable Diffusion, please check out previous articles:

AI Painting Stable Diffusion Research (1) sd Integration Package v4.2 Version Installation Instructions
AI Painting Stable Diffusion Research (2) sd Model ControlNet1.1 Introduction and Installation
AI Painting Stable Diffusion Research (3) sd Model Types Introduction and Detailed Installation and Use
AI Painting Stable Diffusion Research (4) Detailed Explanation of sd Wensheng Diagram Function (Part 1)
AI Painting Stable Diffusion Research (5) sd Wensheng Diagram Function Detailed Explanation (Part 2)
AI Painting Stable Diffusion Research (6) sd Prompt Word Plug-in
AI Painting Stable Diffusion Research (7) ) One article to understand the working principle of Stable Diffusion
AI painting Stable Diffusion research (8) Detailed explanation of sd sampling method


In order to let everyone understand the graph generation function more intuitively, here are a few cases with relatively high practical value to introduce what the graph generation function does and what it can do.


  • The first case of old photos high-definition repair enlargement

  • The second case is the production of exquisite QR code

  • The third case


Here, the explanation will be explained in the way of case interspersed with knowledge points.

Dear friends, you can follow my steps while doing practical operations and learning theoretical knowledge at the same time, which can improve learning efficiency.


Old photo high-definition repair enlargement case


In the first step, before we repair the photo, we need to set it first.


Settings->Face Repair

  • Check the FGPGAN option
  • codeFromer weight is set to 1
  • After the tick processing is completed, unload the face repair model from the video memory to the memory
  • Save Settings
  • Overload the front end

insert image description here


The second step is to switch to the graph generation interface

insert image description here


The third step is to select the photos that need to be repaired

  • Switch to partial redraw tab page

  • Drag the image to be repaired into the image upload area


insert image description here


The fourth step, select the zoom mode


Before choosing the zoom mode, let's take a look at the knowledge points of the zoom mode, and what are the differences between the four zoom modes:


  • resize only

    The picture will be directly scaled and stretched, for example, the size is adjusted from 512x512 to 768x512, as shown in the figure

insert image description here


  • Scale after cropping

    For example, the size is adjusted from 512x512 to 400x512. After selecting this mode, the content of the image width will be cropped, as shown in the figure:


insert image description here


  • Fill blanks after scaling

    For example, the size is adjusted from 512x512 to 768x512. After selecting this mode, the width direction of the picture will be automatically filled with similar content, as shown in the figure:

insert image description here


  • Resizing (Latent Space Magnification)

This mode is similar to the first mode, but there are also differences.

In the first mode, the image is scaled after it is generated.

And this mode is to zoom in the latent space before the image is generated. With this zoom, the effect of each image output is not the same, and there are slight differences.


For example, to resize from 512x512 to 768x512:

insert image description here


Therefore, you can choose the zoom mode according to your own needs.

Here, we choose between the first scaling mode.

insert image description here


The fifth step is to select the sampling method and the number of iterations

The sampling method has also been introduced in detail earlier, interested friends can go to check:

AI Painting Stable Diffusion Research (8) Detailed Explanation of sd Sampling Method


Here are my picks and suggestions:

  • If you want to quickly generate good quality pictures, it is recommended to choose DPM++ 2M Karras (20 -30 steps), UNIPC (15-25 steps)
  • If you want high-quality images and don’t care about reproducibility, it is recommended to choose DPM++ SDE Karras (10-15 steps are slower), DDIM (10-15 steps are faster)
  • If you want a simple diagram, it is recommended to choose Euler, Heun (can reduce steps to save time)
  • If you want a stable and reproducible image, avoid any ancestor sampler (with a or SDE in the name)
  • On the contrary, if you want to generate a different image each time, you can choose a non-convergent ancestor sampler (with a or SDE in the name)

Here we choose DPM++ 2M Karras (28 steps)

insert image description here


The sixth step, facial repair selection

Before choosing the settings related to face repair, let’s introduce the knowledge points related to face repair.

There are two ways to repair the face, one is to redraw the multiple of the size, and the other is to redraw the size.


  • redraw size

We can click the "triangle" button, and it will automatically get the size of the original image

insert image description here


  • redraw size multiple

According to the multiple, you can choose according to your own needs, for example: 1 times, 2 times, 3 times

insert image description here


In this case, we directly choose to redraw the size according to the original image, and select 1 as the multiple.

  • redraw range

    If the redrawing range is set to 0, it means that AI will not do anything and keep the original image.

    If the redrawing range is set to 1, it means that the AI ​​is completely free to play, and the resulting picture has little relevance to the original picture.

Because here we are going to do high-definition restoration of photos, so there is no need for AI to redraw here, set it to 0.


Step 7. Click Generate


The effect is as follows:

insert image description here


It can be seen that the effect is not obvious and did not meet expectations. This is because in the above steps, only the facial details are processed, and other parts are not processed, so we need to perform post-processing at this time.


The eighth step, post-processing

We will generate a good image, click the "Send to post-processing" button to switch to the post-processing page.

insert image description here


Scale, select: 1

Amplification Algorithm Selection: SwinIR_4x

insert image description here


The generated effect is as follows:


insert image description here


According to the comparison chart, we can see that the facial details, hair color, and background have been processed in high-definition.


If you are not satisfied with the generated image, then I will tell you another ultimate method of high-definition image, I believe that you will have nothing to say about the image after high-definition restoration.


please watch the following part.


The ninth step, the ultimate method of high-definition images

What is the ultimate method of high-definition images? That is to use the ControlNet title to control the image effect.


I believe that friends who have read this article on AI painting Stable Diffusion Research (2) sd model ControlNet1.1 Introduction and Installation should be impressed.


When introducing the new Tile model of ConctrolNet here, it was said that the Tile model has a good effect on high-definition restoration of pictures, enhancement of details, and automatic inference of content based on the picture. Do you still remember?


Ok, without further ado, let’s go directly to the operation steps:


(1), first switch to the image generation interface, and upload the image that needs to be repaired


insert image description here


(2), select the scaling mode, sampling method, and enable face restoration


insert image description here


(3), enable ControlNet, and select the picture to be controlled


insert image description here


(4), here comes the point

  • Control type: select title block
  • Preprocessor selection: title_resample
  • Model selection: control_v11fle_sd15_title

insert image description here


(5), click generate

The comparison effect is as follows:

insert image description here


Are you still satisfied with this high-definition and detailed restoration effect?

Of course, there are many ways to do high-definition restoration of old photos on the Internet. Here I will focus on the function of generating pictures from pictures.

Well, this is the end of our first function case of graph generation.

Guess you like

Origin blog.csdn.net/lizhong2008/article/details/132314548