AutoHDR – Lens Distortion Correction.
Automatic lens barrel distortion correction without a lens profile, using a FeGAN flow-map architecture and a custom geometry-weighted loss.

Cameras introduce barrel distortion — bent lines, warped edges — that is normally fixed using manufacturer lens profiles. The challenge: build one model that corrects distortion for any lens, without needing a profile. I used the FE-GAN architecture (from the self-supervised fisheye rectification paper). The generator outputs a pixel-level flow map that warps each pixel back to its correct position, rather than estimating camera parameters. The key contribution is a custom weighted composite loss aligned to the evaluation metrics: edge alignment 40%, line straightness 22%, gradient orientation 18%, SSIM 15%, pixel accuracy 5%. Training directly against these weights meant the model learned geometry-first rather than chasing pixel similarity. Outputs are upscaled back to original resolution via Real-ESRGAN.
Problem
Lens profiles fix barrel distortion in Lightroom, but coverage for newer lenses is incomplete. Real-estate and architectural photos are particularly affected — bent lines look unprofessional and are hard to fix in post without the right profile.
Solution
I trained a FeGAN to predict a dense flow map that physically unwarps each pixel, paired with a composite loss that directly matches the 5-metric evaluation scorer so the model optimizes for the right thing from day one.
- 01FeGAN generator predicts a pixel-level flow map to unwarp distortion — no camera parameter estimation needed
- 02Custom composite loss targeting evaluation metrics: edge (40%), line (22%), gradient (18%), SSIM (15%), L1 (5%)
- 03Trained at 256×256 then upscaled to original resolution with Real-ESRGAN
- 04Geometry-first approach outperforms pixel-loss baselines on edge alignment and line straightness
- < 0.10Target MAE
- 5Loss Components

backend
- Python
- PyTorch
- OpenCV
- scikit-image
other
- Real-ESRGAN
- NumPy