Old Photo Restorer
Operator: Abdulla Al Fahad. How tools are built and checked
A scanned family print has two kinds of problems that need different fixes. Dust and scratches are local damage: a few hundred pixels that should be replaced by what was there. Fading and colour casts are global: every pixel is shifted the same way, and the fix is arithmetic on the whole picture. This page treats them as separate steps in the order that avoids trouble. It finds the damage and shows it as a red mask you can edit, fills it from the surrounding picture, and only then corrects colour, so the patches are matched to the original tones and corrected together with them.
Key features
- Dust and speck finder: bright or dark blobs smaller than a size you set, found with a signed top-hat filter and a threshold based on the picture's own noise
- Scratch finder: an elongated line detector at eight angles that responds to thin ridges and ignores step edges
- A red mask over the picture that you can paint more of, erase from, clear or find again
- Repair with PatchMatch inpainting, the same fill the remove-object tool uses, after growing the mask by 0 to 8 pixels
- Per-channel contrast stretch, gray-world colour balance, saturation down to black and white (which removes sepia), a contrast curve and an unsharp mask, with a before and after slider
How damage is found and filled
A speck is detected by comparing each pixel with a grey-scale opening and closing using a square just larger than the biggest speck you allow. What is brighter than its opening, or darker than its closing, is a candidate; smooth gradients and large objects give no response because the square fits inside them. A candidate counts when it exceeds a multiple of the picture's noise (1.4826 times the median absolute deviation of the response) and no less than 10 grey levels, and when the connected blob is no bigger than the size you set.
A scratch is a thin line, so the detector averages brightness along a short line at eight angles and subtracts the average of two parallel lines three pixels either side. A real line gives a large difference and similar levels on both sides; a step edge gives a difference only on one side and is rejected. The threshold is the larger of a multiple of the noise and a floor of 40 grey levels at the lowest sensitivity down to 10 at the highest, because a line crossing the detector at another angle leaves a faint echo, about a fifteenth of its contrast, that a purely noise-based threshold would mistake for more scratch. Only components at least three quarters as long as the shortest scratch you set are kept.
The colour steps are plain arithmetic. The stretch maps each channel's 0.5th and 99.5th percentile to 0 and 255, which restores contrast lost to fading and lines the channels up. Gray-world scales the channels so their averages become equal, which assumes the picture should average to grey and therefore removes a uniform tint, but it will also remove a real overall colour such as a sunset. Saturation at 0 gives a black-and-white picture, the quickest way to remove sepia.
How it works
All three jobs, finding, filling and colour, run in a worker that is cancelled by the Cancel button or by changing the picture. Finding runs once on opening and again when you press Find damage again; changing a colour slider reruns only the colour step, on the repaired picture.
Repair is limited to a working size of 2,000 px on the long side, which keeps the PatchMatch search practical, and the download is that size. A mask that covers more than 60 percent of the picture is refused, because there would be too little left to copy from.
The fill is applied to the original pixels before colour correction, which is why the patches blend without a visible seam after the stretch.
Common use cases
- A 1950s 8 × 10 in portrait scanned at 600 dpi (4,800 × 6,000 px) has hair-thin scratches across the sky. Raising scratch sensitivity to 70 percent marks them; erasing the marks that landed on a telegraph wire keeps the wire, and the repair takes only the sky. The restored file comes back at 1,600 × 2,000 px, the 2,000 px working size, and the original scan stays the master.
- A box of sepia prints is turned into clean black and white by setting saturation to 0 and restoring contrast at 80 percent, with no mask at all.
- A wedding album page scanned in one pass has a dust speck near every corner. At 70 percent dust sensitivity and a largest speck of 25 px the finder marks only the corners and the glass-edge lint, and a single repair clears all of them in one run.
How to use this tool
- Open the scan and wait for the first search; the red marks show what was found.
- Add marks with the brush where damage was missed, and erase marks over real detail such as a star, a freckle or a texture.
- Press Repair marked areas and look at the Compare tab.
- Adjust restore faded contrast, remove colour cast, saturation and sharpening until the picture looks right.
- Choose PNG or JPEG and download.
Example
A clean 400 × 300 test picture with 14 dust specks and two scratches painted on, then repaired with the mask grown by 3 px
Default sensitivities (50 percent), largest speck 40 px, shortest scratch 14 pxMeasured against the clean version of that picture
515 of the 528 damaged pixels are inside the mask (97.5 percent); the mask is 1,236 pixels, about 1 percent of the picture
Mean error on the damaged pixels against the clean picture: 137.3 grey levels before the repair, 8.5 after
A faded orange cast with channel averages of 148, 125 and 95 comes back to 116, 114 and 111, against 112 in the clean pictureTips for best results
- Raise Largest speck only as far as the biggest dust you can see on screen; a larger value also marks small genuine objects such as eyes in a distant group photo.
- Look at the Compare tab once with the contrast stretch at 100 percent. A patch that only shows after the stretch usually means the mask edge crossed a real boundary, and a tighter mask there fixes it.
- If the repair looks soft in one place, paint the mask more tightly there and repair again; patches copied from a flat area look smoother than the grain around them.
Common pitfalls
The fill copies texture from elsewhere in the same picture. It cannot restore a face torn off a print or a missing corner; where nothing similar exists in the picture, the fill can only smear nearby texture.
The restored picture is at most 2,000 px on the long side, and the download has that size. A 600 dpi scan of a 10 × 8 in print (6,000 × 4,800 px) comes back at 2,000 × 1,600 px, which is 200 dpi at the print size.
Gray-world balance removes any strong overall colour, genuine or not. Lower its strength for pictures dominated by one colour.
Sharpening after a repair also sharpens the film grain and any scan noise.
Common errors and how to fix them
- "The marked area covers more than 60 percent of the picture"
- Clear the mask and mark less, or lower the sensitivities and find again. A very grainy scan can be flagged almost everywhere at 100 percent.
- "The restoration worker stopped, probably from running out of memory"
- Close other heavy tabs, or crop the scan. The patch search holds several copies of the picture.
- "Nothing is marked" after pressing repair
- The button stays disabled until at least one pixel is marked. Paint a mark or raise the sensitivity.
Best practices
- Scan at 300 dpi for a print up to about 6 × 7 inches, which already fills the 2,000 px working size; extra resolution is discarded before the repair. The effort pays off in a clean scanner glass and a flat print, because every speck you do not scan in is one you do not have to fill.
Frequently asked questions
Why is my 7,000 px scan returned at 2,000 px?
Repair runs at a working size of 2,000 px on the long side, because the PatchMatch search holds several copies of the picture and becomes impractical beyond that, and the download is that working copy. Crop the scan to the damaged area first if you need more pixels there, or repair the photo here and use the mask positions as a guide for a full-size fix in another program.
Does the repair change pixels outside the red mask?
No. With the colour steps at zero, only the marked pixels change: on a synthetic test picture the mean error outside the mask was 0.00 after the repair. The colour sliders, by contrast, act on the whole picture.