Deblurring images, in Python
A companion to Hansen, Nagy & O’Leary, ending on real telescope data
Preface
These nine chapters teach how to restore a blurred image, from the first principles to the edge of a research project. They accompany a textbook,
P. C. Hansen, J. G. Nagy and D. P. O’Leary, Deblurring Images: Matrices, Spectra, and Filtering, SIAM, 2006,
which teaches with MATLAB. Here the same mathematics is taught in Python, in our own words, and every chapter ends on real data: narrowband images of the Eagle Nebula (M16) taken with a 14 cm refractor, with Hubble Space Telescope images of the same field as a reference.
This is a companion, not a substitute. Read the chapter of the book, then work through the corresponding chapter here.
Contents
The book, chapter by chapter
- The image deblurring problem: why the obvious solution fails.
- Images as arrays: NumPy in place of MATLAB; display is not data.
- The blurring function: the PSF, measured on a star; noise; boundaries.
- Structured computations: never building the matrix.
- The SVD and spectral analysis: the Picard plot.
- Regularisation by spectral filtering: Tikhonov, and how much of it.
- Colour images and smoothing norms: beyond the basic method.
Towards the research project
- From one frame to many: proper coaddition.
- Iterative methods: when there is no closed form; robust coaddition.
followed by the references and a listing of the helper module.
Chapters 1 to 7 follow the seven chapters of Hansen et al. (2006). Chapter 8 is not in that book: it extends the method from one image to many, which is the situation of every astronomer, and introduces proper coaddition (Zackay and Ofek 2017). Chapter 9 follows chapter 4 of Talbot (2024) and provides the iterative methods needed when no formula exists. Its last section lists the open questions of the research project that these notes prepare for.
The chapters were written as Jupyter notebooks, and the text calls them “notebook 1”, “notebook 2” and so on: notebook \(n\) is chapter \(n\).
Each chapter has the same shape:
- What you will take away, in a few lines;
- the ideas, each stated in plain words before any formula, each checked numerically as soon as it is stated;
- real data from our telescope;
- Your turn: exercises. Predict the answer before you run the cell;
- Where to read more.
Do the chapters in order. Each uses what the previous ones built.
Running the code
Every chapter is a Jupyter notebook; this book is those notebooks, rendered with their outputs. To run and modify them:
cd notebooks/hno
python3 -m venv .venv
.venv/bin/pip install -r requirements.txt
.venv/bin/jupyter labThe few functions shared by the chapters live in hnotools.py, listed in the appendix. It is short on purpose: read it. The data are in data/m16_sample.npz, about 4.5 MB, described at the top of make_sample.py.
Sources and credits
- The progression of chapters 1 to 7 is that of Hansen, Nagy and O’Leary. The text, the code and the examples are ours; the book is cited for the full treatment of each topic.
- The one-dimensional signal of chapters 1, 5, 6 and 7, the variational view of Tikhonov regularisation, and the iterative methods of chapter 9 come from H. Talbot, Lecture Notes on Optimisation: applications to computer vision, image and signal processing, and machine learning, CentraleSupélec.
- Proper coaddition is due to B. Zackay and E. Ofek, The Astrophysical Journal 836, 188 (2017). The declared target resolution is due to P. Magain, F. Courbin and S. Sohy, The Astrophysical Journal 494, 472 (1998).
- The telescope data were acquired by H. Talbot. The Hubble images are from the Hubble Heritage project (NASA, ESA, STScI).