Skip to content

Latest commit

 

History

10 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Advanced Image Processing — From-Scratch Implementations

25+ classical image-processing algorithms across 13 topic areas, implemented in Python and NumPy without calling library versions of the algorithms themselves.

Author: Arshia Jafari

Python License NumPy

Overview · Results · Getting Started · Module Reference


Overview

This repository covers the core algorithm families of a graduate image-processing curriculum: frequency-domain filtering, statistical image analysis, orthogonal transforms, photogrammetric geo-referencing, feature and edge detection, unsupervised segmentation, and mathematical morphology.

The algorithms under study are written from first principles on NumPy. OpenCV appears only for file I/O (cv2.imread) or as a primitive inside a larger hand-written pipeline, such as cv2.Sobel supplying the gradient step within a manual Canny or SIFT implementation. No script substitutes a library call for the algorithm it is meant to demonstrate.

The code originated as graduate coursework and was later restructured for public release: paths were centralized, randomness was seeded for reproducibility, several correctness bugs were fixed, and a missing module was added.

Results

Repository Structure

.
├── src/
│   ├── common/
│   │   ├── paths.py                     # Data-directory resolution (AIP_DATA_DIR override)
│   │   └── gcp.py                       # Reproducible GCP/ICP train-test split
│   ├── item01_fft_lowpass_quicksort.py  # 2D FFT, Gaussian low-pass, inverse FFT, Quicksort
│   ├── item02_band_statistics.py        # Histogram statistics, covariance/correlation
│   ├── item03_0{1..7}_*_basis.py        # Fourier / Hartley / DCT / DST / Walsh-Hadamard / Haar / Wavelet
│   ├── item04_0{1,2}_geometric_correction_{2d,3d}.py
│   ├── item05_0{1,2}_*hough*.py         # Standard & probabilistic Hough line detection
│   ├── item06_pca_landsat.py            # Principal Component Analysis
│   ├── item07_sift.py                   # SIFT detection & matching
│   ├── item08_log_edge_detection.py     # Laplacian of Gaussian
│   ├── item09_dog_edge_detection.py     # Difference of Gaussians
│   ├── item10_canny_edge_detection.py   # Canny edge detector
│   ├── item11_0{1,2}_*clustering.py     # K-Means / ISODATA
│   ├── item12_slic_superpixels.py       # SLIC superpixel segmentation
│   └── item13_0{1..5}_*.py              # Dilation / Erosion / Opening / Closing / Hit-or-Miss
├── Data/
│   └── README.md                        # Dataset provenance and expected filenames
├── requirements.txt
├── LICENSE
└── README.md

Each script runs on its own (python src/<script>.py) and resolves its own inputs. There is no shared driver or notebook.

Getting Started

Requires Python 3.10 or later.

git clone https://github.com/arshiajfri/advanced-image-processing
cd advanced-image-processing

python -m venv .venv
source .venv/bin/activate        # Windows: .venv\Scripts\activate

pip install -r requirements.txt

Data

The repository ships code, not data. Data/ is excluded from version control because it holds large geospatial rasters that are better fetched from their public sources, one non-redistributable photograph, and a SIFT test pair you supply yourself. Data/README.md lists the exact filename each module expects and where to download it. Landsat-9 and SPOT imagery are public.

Paths resolve through src/common/paths.py, defaulting to <repo_root>/Data/ and overridable with an environment variable:

export AIP_DATA_DIR=/path/to/your/data
python src/item06_pca_landsat.py

Quick Start

# Frequency-domain filtering
python src/item01_fft_lowpass_quicksort.py

# PCA over 6 Landsat-9 bands
python src/item06_pca_landsat.py

# SIFT matching between two images
python src/item07_sift.py --image1 path/to/a.jpg --image2 path/to/b.jpg

# Canny, implemented end to end
python src/item10_canny_edge_detection.py

Module Reference

Frequency-Domain & Statistical Analysis

Module Description
item01_fft_lowpass_quicksort.py 2D FFT of a Landsat-9 band, Gaussian low-pass mask applied in the frequency domain, reconstruction by inverse FFT, plus a recursive Quicksort over the spectrum data.
item02_band_statistics.py Skewness, kurtosis, Histogram Flatness Measure, Histogram Spreadness, variance, pairwise inter-band covariance and correlation matrices, and linear brightness/contrast adjustment.
item03_01item03_07 Complete 8×8 discrete basis-function sets for seven orthogonal transform families: Fourier, Hartley (cas function), DCT-II, DST-I, sequency-ordered Walsh–Hadamard, Haar, and Daubechies-2 wavelets. Each basis is checked for orthonormality before use.

Photogrammetry & Geometric Correction

Module Description
item04_01_geometric_correction_2d.py Fits Conformal, Affine, degree-2 and degree-3 Polynomial, and Projective 2D models between image and ground coordinates by least squares. Accuracy is measured as out-of-sample RMSE on Independent Check Points. Resampling onto a regular ground grid uses both nearest-neighbor and bilinear interpolation.
item04_02_geometric_correction_3d.py Extends to 3D with Affine 3D, Global Polynomial 3D, and full Direct Linear Transformation, using terrain elevation sampled from a DEM.

Models are fit on a seeded 67/33 split of the control points, with GCPs used for fitting and ICPs held out for validation.

Feature & Edge Detection

Module Description
item05_01_hough_lines.py, item05_02_probabilistic_hough_lines.py Standard and probabilistic Hough transforms with hand-written voting accumulators.
item07_sift.py Full SIFT pipeline: multi-octave Gaussian and DoG pyramids, scale-space extremum detection with contrast and Hessian-based edge rejection, gradient-histogram orientation assignment, 128-D descriptors, and ratio-test matching.
item08_log_edge_detection.py Laplacian of Gaussian via manual 5×5 kernel convolution and zero-crossing analysis.
item09_dog_edge_detection.py Difference of Gaussians: two manually convolved blurs at different scales, differenced and zero-crossing thresholded.
item10_canny_edge_detection.py Gaussian smoothing, Sobel gradients, non-maximum suppression, double thresholding, and 8-connected hysteresis linking.

Dimensionality Reduction

Module Description
item06_pca_landsat.py PCA over 6 Landsat-9 bands by covariance-matrix eigendecomposition, producing ranked components PC1 through PC6.

Clustering & Segmentation

Module Description
item11_01_kmeans_clustering.py K-Means color quantization with hand-written assignment and update steps.
item11_02_isodata_clustering.py ISODATA, extending K-Means with automatic splitting of high-variance clusters and merging of nearby centers, producing a data-driven cluster count.
item12_slic_superpixels.py SLIC superpixel segmentation in CIELAB space with gradient-aware seed initialization.

Mathematical Morphology

Module Description
item13_01item13_05 Binary dilation, erosion, opening, closing, and a ternary-kernel Hit-or-Miss transform applied to corner detection, all built on a manual structuring-element sliding window.

Performance Notes

A few modules implement their core operation as explicit loops rather than array operations. This is deliberate: the point of these modules is a transparent implementation, not an optimized one. At the image sizes the scripts are configured for, each finishes in well under a minute on a laptop.

With substantially larger inputs, expect item08item10 (LoG, DoG, Canny), item11 (K-Means), and item12 (SLIC) to scale with pixel count, and the accumulator in item05_02 to scale with edge-pixel count. Downscaling the input first is the simplest fix, following the pattern already used by default in item05_02.

Some scripts import shared helpers from a sibling in the same item (item04_02 from item04_01; item13_03 and item13_04 from item13_01 and item13_02), so run them from inside the cloned repository rather than as files copied elsewhere.

License

MIT. See LICENSE.

References

Landsat-9 imagery courtesy of the USGS/NASA Landsat program. Algorithm formulations follow Gonzalez & Woods, Digital Image Processing, and Lowe, Distinctive Image Features from Scale-Invariant Keypoints (2004).

About

From-scratch Python/NumPy implementations of 13 classical image-processing algorithms — FFT, SIFT, Canny, PCA, and more.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages