Secure Diffusion Venture: Reviving Outdated Images


Pictures has been round for greater than a century. There are numerous previous pictures round, and possibly your loved ones has some, too. Restricted by the digicam and movie of the time, you will have pictures of low decision, blurry, or with folds or scratches. Restoring these previous pictures and making them like new ones taken with in the present day’s digicam is a difficult process, however even you are able to do that with picture enhancing software program akin to Photoshop.

On this put up, you will note how you need to use Secure Diffusion to repair previous pictures and produce a brand new life to them. After ending this put up, you’ll study:

  • The best way to clear up defects in scanned picture
  • The best way to colorize a black and white picture

Let’s get began.

Secure Diffusion Venture: Reviving Outdated Images
Picture by Antonio Scant. Some rights reserved.


This tutorial is in three components; they’re

  • Venture Concept
  • Superresolution
  • Reconstruction

Venture Concept

Let’s contemplate an previous picture from the New York Public Library:

Picture of “Younger oyster shuckers”. From NYPL Digital Collections.

In the event you obtain it, you’ll discover that the picture is at a low decision. It has somewhat noise from movie grain (not too apparent). And the picture is in black and white. The objective of this undertaking is to make this right into a excessive decision colour picture depicting the identical individuals.


The unique image has a low decision. Scaling up the decision known as super-resolution, and a number of machine studying fashions have been developed for it.

Step one in processing an previous picture is to carry out superresolution. Normally, the previous picture is in a low decision, however that’s not the rationale. Even when the decision is excessive (e.g., since you scan the previous picture in excessive decision), you should still need to downsample the picture and run superresolution for its facet impact of eradicating noise and movie grains.

On the Secure Diffusion Internet UI, you’ll be able to add the picture to the “Further” tab. This tab means that you can do many issues however none is expounded to the diffusion course of. Somewhat, it’s to use a picture to varied current machine studying fashions. Right here, you allow “Upscale” and set “Scale by” for an affordable issue. For this specific picture, you’ll be able to set the issue to 2. Then you need to decide an upscaler, akin to “R-ESRGAN 4x+”.

The subsequent factor you are able to do on the Further tab is CodeFormer. It’s a mannequin for fixing faces. Allow it and set the load. A low weight provides CodeFormer extra freedom to alter the face, whereas a excessive weight tends to protect the unique facial expressions. The optimum weight ought to rely on the standard of the unique picture. If there are extra scratches or marks on the faces, you desire a decrease weight to permit for simpler reconstruction.

Superresolution is step one in processing an previous picture.

You need to obtain the upscaled output for the following step.


To reconstruct an previous picture, you’ll use txt2img. You shouldn’t use img2img as a result of offering the previous picture as a place to begin is imposing an excessive amount of affect on the output, and you can’t see the correction that you’re anticipating.

However first, you need to use img2img tab, add the upscaled output, and click on on the paper clip icon for the “CLIP interrogator”. This can auto-fill the constructive immediate primarily based on the uploaded picture. You’ll assemble your immediate on the txt2img tab primarily based on the CLIP interrogator’s outcome.

You should use CLIP interrogator from the img2img tab

Now proceed to txt2img tab. Let’s use a SD1.5 mannequin for photorealistic technology, akin to Reasonable Imaginative and prescient v6. Set the constructive immediate, akin to

a gaggle of kids standing subsequent to one another holding buckets of water and carrying hats and clothes with a constructing within the background, August Sander, a colorized picture, wpa, american barbizon college, highest quality, 8k uncooked picture, detailed face

The previous couple of key phrases are added to manage the fashion within the output. You should use a boilerplate destructive immediate, akin to

drawing, portray, crayon, sketch, graphite, impressionist, noisy, blur, tender, deformed, ugly, lowres, unhealthy anatomy, unhealthy palms, cropped, worst high quality, low high quality, regular high quality, jpeg artifacts, signature, watermark, monochrome, greyscale, previous picture

The important thing for previous picture reconstruction is to make use of ControlNet. You want two ControlNet models for one of the best outcome.

First add the upscaled picture to first ControlNet unit and set the kind to be Canny. Keep in mind to allow this unit and verify “Pixel Excellent”. This helps the ControlNet preprocessor to make use of the optimum decision. Set the primary unit’s management weight to 0.8.

Then allow the second ControlNet unit. Add the identical picture, activate Pixel Excellent, and choose the management sort to be “Recolor”. It is a ControlNet mannequin to paint a black and white picture. You need to use “recolor_luminance” mannequin as preprocessor. Set the second unit’s management weight to 0.2. Optionally, you’ll be able to modify the Gamma correction if it is advisable to fine-tune the output’s brightness.

Keep in mind to set the output dimension in txt2img to a facet ratio just like the unique and across the native decision of your Secure Diffusion mannequin. On this instance, we use 760×600 pixels. Click on generate, you will note the next:

An previous picture colorized utilizing Secure Diffusion

You’ll be able to obtain the outcome. Let’s see what you get:

The reconstructed previous picture.

This picture is a bit overexposed however you’ll be able to see an previous picture revived. All the small print are preserved: All individual’s facial features are saved, the stains on the garments they wore, and so forth.

However how does it work? That is asking Secure Diffusion to redraw the picture. Therefore, you want a immediate to information the diffusion strategy of the draw. However to manage exactly the form and individuals, you used the Canny sort ControlNet to stipulate the drawing and ask the diffusion course of to suit into the define. Nonetheless, this define will not be excellent as a result of the Canny edge detection algorithm doesn’t convert an image right into a line drawing. To decrease the distortion, you utilize the second ControlNet unit to recolor the enter picture primarily based on brightness. All the unique colours had been ignored (and there have been none), and colours had been crammed primarily based on a machine studying mannequin. Nonetheless, you don’t want these defects within the picture. Therefore, you set the next weight for Canny and a a lot decrease weight for Recolor.

In the event you click on the generate button once more, you may even see individuals carrying garments of various colours. It’s because the mannequin will not be assured about what colour they need to be carrying. It’s possible you’ll need to describe their colour within the immediate to manage that. It’s also possible to attempt to flip off one of many ControlNet models and observe the outcome. The perfect outcome ought to solely be obtained when each are working collectively.

Observe a couple of picture with faces: In case your unique picture is in unhealthy form that the individuals’s faces usually are not very recognizable, you need to activate ADetailer to reconstruct the faces. However do this solely when obligatory! In any other case you could discover your picture are depicting fully completely different individual.

Within the above, the output was set to decision 760×600. However it’s your decision the next decision than the Secure Diffusion mannequin can assist. You should use the “Hires. repair” characteristic in txt2img to run an upscaler after the picture is generated. The choices are similar to that in Further tab. However bear in mind to set the denoising power within the upscaler to a low worth (akin to 0.2) as a result of you don’t want to impose extra distortion.

Additional Readings

This part gives extra assets on the subject if you wish to go deeper.


On this put up, you cleaned up an previous picture. You eliminated the defects and coloured a black-and-white picture, bringing the picture to the fashionable day. Within the course of, you used textual prompts to drive the diffusion course of to generate photos on the coarse degree. Then you definately use ControlNet to wonderful tune the output. You managed the environment at a rough degree and preserved the element on the wonderful degree. Secure Diffusion is to fill the hole and rebuilt the picture.