Foundations to Frontier
Tests
G. Computer Vision and Remote Sensing › G6 Astronomical Imaging

Source detection and galaxy morphology classification

Turning a calibrated sky image into a catalogue means finding sources, separating blended ones and measuring them. Classifying galaxies by shape is one of the oldest tasks in astronomy and one of the first to use crowdsourcing and deep learning at scale. This page covers background estimation, matched filtering and thresholding, connected-component segmentation and deblending (SExtractor, SEP, photutils, scarlet), detection completeness and false-detection rates. For morphology it covers the Hubble sequence, Sérsic profiles, non-parametric measures (concentration, asymmetry, Gini, M20), Galaxy Zoo's volunteer labels and the CNNs trained on them, up to Zoobot and self-supervised models in current surveys such as Euclid. In the exercises you implement mesh background estimation, a PSF matched filter, connected-component labelling and the concentration index. You then detect faint point sources and classify simulated galaxies. At an optimal SNR of 8, a 3σ raw-pixel threshold found 10% of sources and a 5σ matched-filter threshold 90%, with no false detections. Lowering the matched-filter threshold to 3σ admitted 5.6 false sources per image. A concentration cut trained on resolved galaxies separated discs from ellipticals perfectly for half-light radii of 3–8 px but scored 0.43 for galaxies smaller than the PSF, calling every one of them a disc. Retuning the cut for small galaxies recovered only part of the loss (0.71).

Level 0: Foundation

★☆☆☆☆ Introductory⏱ 5 minGeneral audience. No mathematics required.

Finding and sorting things in the sky

A deep sky image holds thousands of stars and galaxies, most of them barely above the noise. To find them, a program smooths the image with the shape a point of light takes through the telescope, then marks every place that rises clearly above the noise. Lower the bar and you find fainter objects, but also more noise blips. Galaxies are then sorted by shape: smooth ellipticals with light piled in the centre, discs with spiral arms, and irregular or merging systems. The demo shows the trade-off between threshold, completeness and false detections.

Astronomical imaging lab
k = 5
Noise (orange) and a source of SNR 6 (red) after matched filtering. A 5σ cut leaves about 0.17 noise peaks per 4096² image (PSF σ 1.5 px) and detects the source with probability 0.84.
Why engineers care

Survey catalogues with billions of entries (Gaia, Rubin, Euclid) start from detection. The same matched-filter and thresholding ideas find satellites and debris in telescope frames and small targets in radar and infrared imagery.

📝 Quick check (Level 0)
0/3 answered
  1. 1. Lowering the detection threshold gives…
  2. 2. Smoothing with the PSF before thresholding is called…
  3. 3. Ellipticals differ from discs by…

Level 1: Beginner

★★☆☆☆ Basic⏱ 20 minSecondary-school mathematics: arithmetic and elementary algebra.

By hand

  • Background. Estimate the sky in a mesh of boxes (sigma-clipped median or mode), interpolate, subtract; also estimate the noise map (SExtractor, Bertin and Arnouts 1996).
  • Detection. Correlate the image with the PSF (the matched filter, optimal for an isolated point source in white noise), threshold at k times the filtered noise, keep connected groups of at least a minimum number of pixels.
  • Deblending. Split merged groups: SExtractor’s multi-threshold tree; scarlet (Melchior et al. 2018) models each source as a non-negative, monotonic morphology times a spectrum across bands and is used by the Rubin pipelines.
  • Measurement. Centroids, aperture and Kron fluxes, PSF photometry for stars, second-moment shapes; star–galaxy separation by comparing PSF and extended-model fluxes.
  • Tools. SExtractor; SEP (Barbary 2016), its Python library form; photutils (detect_sources, deblend_sources, SourceCatalog).
  • Morphology: parametric. Hubble’s sequence (1926): ellipticals, lenticulars, spirals, irregulars. Sérsic profiles I(r) ∝ exp(−b_n((r/r_e)^(1/n) − 1)): n = 1 for exponential discs, n = 4 for de Vaucouleurs ellipticals. Fitting codes include GALFIT.
  • Morphology: non-parametric. Concentration C = 5 log₁₀(r₈₀/r₂₀); asymmetry A and smoothness S (the CAS system, Conselice 2003); Gini and M20 (Lotz, Primack and Madau 2004), which flag mergers.
  • Learning from labels. Galaxy Zoo (Lintott et al. 2008) gathered volunteer votes for about 900000 SDSS galaxies; later projects asked a decision tree of questions (bars, arms, bulges, mergers). CNNs trained on these votes followed (Dieleman, Willett and Dambre 2015). Zoobot (Walmsley et al. 2023) offers pretrained models for fine-tuning, and Zoobot models trained on Galaxy Zoo labels were applied to Euclid’s first quick data release in 2025. Self-supervised and multimodal models such as AstroCLIP (Parker et al. 2024) learn galaxy representations without labels.
📝 Quick check (Level 1)
0/3 answered
  1. 1. The Sérsic index of a de Vaucouleurs elliptical:
  2. 2. Gini and M20 are useful for flagging…
  3. 3. Galaxy Zoo labels came from…

Level 2: Intermediate

★★★☆☆ Intermediate⏱ 25 minUndergraduate students and practising engineers.

Building a catalogue

Exercise 1.

  • Mesh background estimation.
  • A PSF matched filter that outputs per-pixel SNR.
  • 8-connected component labelling.
  • The concentration index.

Practice.

  • Subtract background with masks: bright galaxies bias the mesh median; mask detected sources and iterate, and use larger boxes for extended objects.
  • Choose the threshold from false-detection rates: inject fake sources and run on the negative image to measure completeness and purity.
  • Deblend with care: check crowded fields by eye; multiband deblenders such as scarlet use colour to split overlapping sources.
  • Morphology labels: use vote fractions, not hard labels, and weight by the number of votes; Zoobot fine-tunes well from a few hundred labelled galaxies.
  • Mind resolution: shape measurements and classifiers degrade when galaxies approach the PSF size; report performance by size and magnitude bins.
import numpy as np
from astropy.convolution import Gaussian2DKernel, convolve
from photutils.background import Background2D, MedianBackground
from photutils.segmentation import detect_sources, deblend_sources, SourceCatalog
bkg = Background2D(img, (64, 64), filter_size=(3, 3), bkg_estimator=MedianBackground())
data = img - bkg.background
kernel = Gaussian2DKernel(1.5)                       # PSF sigma in pixels
conv = convolve(data, kernel)
seg = detect_sources(conv, threshold=1.5 * bkg.background_rms, npixels=5)
seg = deblend_sources(conv, seg, npixels=5, nlevels=32, contrast=0.001)
cat = SourceCatalog(data, seg, convolved_data=conv).to_table()   # centroids, fluxes, moments
🐍 Exercise 1: background, matched filter, labelling and concentration
Write a mesh background, a matched filter in SNR units, 8-connected labelling and the concentration index.
📝 Quick check (Level 2)
0/3 answered
  1. 1. Measure purity by running detection on…
  2. 2. Galaxy Zoo labels are best used as…
  3. 3. Report classifier accuracy by…

Level 3: Advanced

★★★★☆ Advanced⏱ 25 minGraduate level, with full derivations and proofs.

Theory

Matched filtering. For a source of flux F with unit-sum PSF k in white noise σ, the best linear statistic is the correlation of the data with k. At the source position it has mean F Σk² and noise σ √Σk², so its SNR is F √Σk² / σ. For a Gaussian PSF of width s, Σk² = 1/(4πs²). The SNR of the brightest single pixel is smaller by a factor √π s, which is 2.66 for s = 1.5 px. A raw-pixel threshold therefore wastes most of the signal.

False detections. After filtering, the noise is correlated over about a PSF area. A rough count of false peaks is the number of independent beams times the Gaussian tail beyond k. Going from 5σ to 3σ multiplies the tail by about 4700. Real fields add artefacts (diffraction spikes, satellite trails), so purity is measured, not computed.

Resolution limits morphology. The observed image is the galaxy convolved with the PSF. When r_e falls below the PSF width, every profile tends to the PSF’s own concentration (C ≈ 2.14 for a Gaussian), and n = 1 and n = 4 galaxies become hard to tell apart. No threshold can recover information the blur removed, only priors (colour, redshift, larger training sets) can.

Truncation. Concentration depends on the aperture. Measured within a finite radius, a de Vaucouleurs profile loses its extended wings and C falls well below the textbook 5.2.

📝 Quick check (Level 3)
0/3 answered
  1. 1. The matched-filter SNR of a point source scales with…
  2. 2. Lowering k from 5 to 3 multiplies the Gaussian tail by about…
  3. 3. Below the PSF size, concentration tends to…

Level 4: Expert

★★★★★ Expert⏱ 30 minResearchers: original papers and open problems.

How faint can a detector reach, and how small can a galaxy be before its morphology is lost?

History.

  • E. Hubble, “Extragalactic nebulae” (1926), and the tuning-fork classification.
  • E. Bertin and S. Arnouts, “SExtractor: software for source extraction” (1996).
  • C. Lintott et al., “Galaxy Zoo: morphologies derived from visual inspection of galaxies from the Sloan Digital Sky Survey” (2008).
  • S. Dieleman, K. Willett and J. Dambre, “Rotation-invariant convolutional neural networks for galaxy morphology prediction” (2015).

Exercise 2. Part A: ten 128 × 128 images with unit Gaussian noise and a Gaussian PSF (σ 1.5 px), each with 24 point sources at optimal SNR 3, 4, 5, 6, 8 and 10 (four of each).

  • Detectors: a raw-pixel 3σ threshold with a 5-pixel minimum area (SExtractor style); a matched filter thresholded at 5σ and at 3σ.
  • Measure: completeness by SNR, and false detections per image.

Part B: 400 Sérsic galaxies (half n = 1, half n = 4) with half-light radii from 0.75 to 8 px, convolved with the PSF, with noise. A concentration threshold is learned on resolved training galaxies (r_e above 3 px) and tested on the other half of the sample.

detector SNR 3 SNR 5 SNR 8 SNR 10 false per image
raw pixels 3σ, area 5 0.0 0.05 0.10 0.575 0
matched filter 5σ 0.10 0.65 0.90 1.0 0
matched filter 3σ 0.50 0.95 0.875 1.0 5.6
test galaxies accuracy ellipticals called elliptical
r_e 3–8 px 1.0 1.0
r_e 1.5–3 px 0.857 0.632
r_e 0.75–1.5 px 0.429 0.0
small, threshold retuned 0.714 –
  • Matched filtering is the single biggest gain: the raw-pixel cut needs SNR about 10 for half its detections.
  • The threshold trades purity for depth: 3σ found half of the SNR-3 sources but added 5.6 noise detections per image.
  • Morphology collapses below the PSF: measured concentration fell from 3.49 (ellipticals) and 2.52 (discs) for resolved galaxies to near the PSF value, so the cut called every small elliptical a disc.
  • Null result for retuning: a threshold chosen for small galaxies reached only 0.71, 0.60 and 0.61 on seeds 0, 1 and 2; the information is gone.
  • Seeds 1 and 2: matched 5σ completeness at SNR 5 was 0.50 and 0.45, and 1.0 at SNR 8 for both; 3σ gave 6.3 and 6.0 false sources per image; small-galaxy accuracy 0.54 and 0.54; resolved 1.0 for both.
  • Caveat: isolated point sources and round galaxies; real catalogues also face blending, variable PSFs and colour information.
🐍 Exercise 2 (research): how faint can a detector reach, and how small can a galaxy be before its morphology is lost?
Measure detection completeness and false detections for raw and matched-filter thresholds, then classify simulated discs and ellipticals by concentration as a function of size.

Detection and morphology in AI, robotics and aerospace

  • Survey catalogues: Rubin’s pipelines detect on co-adds and difference images, deblend with scarlet and measure billions of objects; Euclid’s catalogues feed weak-lensing cosmology, which depends on galaxy shapes.
  • Space situational awareness: matched filtering along predicted streaks (track-before-detect) finds faint satellites and debris.
  • Citizen science plus ML: Galaxy Zoo combines volunteer votes with active learning, so people label the galaxies the model is least sure about.

References

  1. E. Bertin and S. Arnouts (1996). “SExtractor: software for source extraction.” A&AS 117.
  2. K. Barbary (2016). “SEP: Source Extractor as a library.” JOSS 1.
  3. P. Melchior et al. (2018). “scarlet: source separation in multi-band images by constrained matrix factorization.” Astronomy and Computing 24.
  4. C. Conselice (2003). “The relationship between stellar light distributions of galaxies and their formation histories.” ApJS 147.
  5. J. Lotz, J. Primack and P. Madau (2004). “A new nonparametric approach to galaxy morphological classification.” AJ 128.
  6. C. Lintott et al. (2008). “Galaxy Zoo.” MNRAS 389.
  7. S. Dieleman, K. Willett and J. Dambre (2015). “Rotation-invariant convolutional neural networks for galaxy morphology prediction.” MNRAS 450.
  8. M. Walmsley et al. (2023). “Zoobot: adaptable deep learning models for galaxy morphology.” JOSS 8.
  9. L. Parker et al. (2024). “AstroCLIP: a cross-modal foundation model for galaxies.” MNRAS 531.