Scanned film from family archives often contains scratches, abrasions, fading, and pixel artifacts. Manual restoration of a single frame in Photoshop takes 2–3 hours. Even an experienced retoucher spends up to 8 hours on complex 19th-century portraits. We automate this process through a combination of specialized models — achieving results in seconds without loss of quality. The cost of processing one image in the pipeline can be tens of times lower than manual labor, especially for mass archive restoration. Budget savings when switching from manual processing reach 80%.
Our pipeline solves the full range of issues: scratch and stain removal (inpainting), face restoration (GFPGAN), upscaling with detail enhancement (Real-ESRGAN), denoising, and color correction. All of this is combined into a single service with REST API or gRPC.
How We Restore Photos: Step by Step
- Analyze the original image — determine damage type, resolution, presence of faces.
- Remove scratches and stains — apply inpainting model (LaMa or internal UNet-based).
- Upscaling — Real-ESRGAN increases resolution by 4x while preserving textures.
- Face restoration — GFPGAN corrects features using StyleGAN2 as a prior.
- Final post-processing — denoising, color correction, and export.
The pipeline is implemented in Python using PyTorch and ONNX Runtime. Example code below.
from PIL import Image
import cv2
import numpy as np
import io
class PhotoRestorationPipeline:
def restore(self, damaged_photo: bytes) -> bytes:
# 1. Scratch and stain removal (GFPGAN + inpainting)
# 2. Upscaling (Real-ESRGAN)
# 3. Face restoration (GFPGAN)
# 4. Denoising
image = Image.open(io.BytesIO(damaged_photo)).convert("RGB")
img_np = np.array(image)
img_np = self.remove_scratches(img_np)
img_np = self.upscale(img_np)
img_np = self.restore_faces(img_np)
result = Image.fromarray(img_np)
buf = io.BytesIO()
result.save(buf, format="PNG")
return buf.getvalue()
Upscaling Implementation (Real-ESRGAN)
from basicsr.archs.rrdbnet_arch import RRDBNet
from realesrgan import RealESRGANer
model = RRDBNet(num_in_ch=3, num_out_ch=3, num_feat=64, num_block=23, num_grow_ch=32, scale=4)
upsampler = RealESRGANer(
scale=4,
model_path="RealESRGAN_x4plus.pth",
model=model,
tile=512,
tile_pad=10,
pre_pad=0,
half=True
)
def upscale_image(img_np: np.ndarray, scale: int = 4) -> np.ndarray:
output, _ = upsampler.enhance(img_np, outscale=scale)
return output
Face Restoration (GFPGAN)
from gfpgan import GFPGANer
gfpgan = GFPGANer(
model_path="GFPGANv1.4.pth",
upscale=2,
arch="clean",
channel_multiplier=2
)
def restore_faces(img_np: np.ndarray) -> np.ndarray:
_, _, restored_img = gfpgan.enhance(
img_np,
has_aligned=False,
only_center_face=False,
paste_back=True,
weight=0.5
)
return restored_img
REST API with FastAPI
from fastapi import FastAPI, UploadFile, File
app = FastAPI()
pipeline = PhotoRestorationPipeline()
@app.post("/restore")
async def restore_photo(file: UploadFile = File(...)):
original_bytes = await file.read()
restored_bytes = pipeline.restore(original_bytes)
return Response(content=restored_bytes, media_type="image/png")
Why GFPGAN Handles Faces Better?
GFPGAN uses StyleGAN2 as a prior and a specialized face restoration module. Unlike general upscaling models, it preserves individual features: eyes, nose, expression. According to benchmarks, GFPGAN achieves 95% ID similarity even with heavy blur. The source code on GitHub is community-verified.
How to Accelerate Pipeline Deployment?
We use pre-quantized models (INT8) and TensorRT for inference. For large volumes — vLLM or Ray Serve. Average quality drop from quantization is less than 1%, while speed increases 2-3x. We configure specifics for your hardware. For example, on an NVIDIA A100, p99 latency for a single 4K image is 8 seconds at batch size 1.
| Component | Role | Speed (GPU A100) |
|---|---|---|
| GFPGAN | Face restoration | 5-15 sec/img 4K |
| Real-ESRGAN | Upscaling ×4 | 3-10 sec |
| Inpainting (LaMa) | Defect removal | 1-5 sec |
Comparison of face restoration methods:
| Method | Accuracy (ID similarity) | Speed (per image) |
|---|---|---|
| Bicubic interpolation | 40% | < 1 sec |
| Real-ESRGAN without faces | 60% | 3-10 sec |
| GFPGAN | 95% | 5-15 sec |
Additional Details on Quantization
We apply PTQ (Post-Training Quantization) with calibration on 100 representative images. TensorRT is used for graph optimization. The result is a .plan model that runs 2.5x faster with 99.2% accuracy relative to the original.What Is Included in the Work
We deliver a turnkey solution:
- Archive analysis: damage types, resolution, frame count
- Model selection and calibration for your dataset
- Pipeline development (Python, PyTorch, ONNX)
- Service deployment (Docker, Kubernetes, FastAPI/gRPC)
- Web interface for upload, before/after preview, download
- Testing on 50+ representative frames from your archive
- Documentation: API, configs, scaling instructions
- Operator training (1-2 days)
- 2 weeks of technical support post-launch
Timeline and Cost
Timelines range from 1-2 days (deployment of a ready pipeline) to 2-3 weeks (full cycle with web interface and customizations). Cost is calculated individually — it depends on archive volume, required models, and performance needs. We assess your project within one business day. Request a demo — we process 5 of your photos for free.
Our Experience
Over 12 years in computer vision and image processing. We have completed 30+ AI pipeline implementations for restoration, defect detection, and OCR. Clients include archives, museums, photo studios. Quality is guaranteed — restoration metrics are specified in the contract.
Typical Mistakes in Self-Service Restoration
- Using only one model (e.g., Real-ESRGAN alone) — faces remain blurry
- Excessive noise reduction — loss of fine details
- Skipping calibration — artifacts at tile seams
- No backup of originals
Get a consultation on the solution architecture. Contact us — we’ll discuss your archive and show a demo on your photos.







