Remote Sensing Unit 4 – Machine Learning-Based Satellite Image Classification

Satellite Context ("A-Train" Constellation)

  • Satellites mentioned: CALIPSO, CloudSat, Glory, Aqua, GCOM-W1, Aura, OCO-2, PARASOL.
    • Typical along-track time separations: CALIPSO–CloudSat 17.5s17.5\,\text{s}; CloudSat–Glory 1min1\,\text{min}; etc. Used to obtain nearly simultaneous atmospheric / surface observations.

Unit 4 – Main Thematic Blocks

  • Introduction to Machine Learning (ML) for remote-sensing imagery.
  • Spectral-index computation & analysis.
  • Re-classification by value intervals.
  • Cloud masking & radiometric correction.
  • Image fusion (Pansharpening).

Machine Learning: Foundations

  • Artificial Intelligence ⊃ Machine Learning ⊃ Deep Learning.
  • ML divisions
    • Supervised Learning (need labelled data) – classification & regression.
    • Unsupervised Learning (no labels) – clustering, dimensionality reduction, visualisation.
    • Reinforcement Learning (agents, decisions, bots).
  • Typical public-sector uses: fraud detection, subsidy optimisation, demography, anomaly compression, NLP for documents.

Supervised vs Unsupervised Image Classification

  • Supervised
    • Requires user-provided training samples; classes predefined.
    • Algorithms: Random Forest, Support Vector Machine, Decision Tree (CART/CAST), kk-Nearest Neighbors, Naïve Bayes, Logistic Regression, etc.
  • Unsupervised
    • No prior labels; algorithm groups pixels by intrinsic similarity.
    • Algorithms: K-Means, ISODATA, DBSCAN, Principal Component Analysis.

Core Dataset Terminology

  • Training set – teaches the model.
  • Validation set – tunes hyper-parameters without affecting learning.
  • Test set – unseen data for final assessment.
  • Overfitting – memorises noise, poor generalisation.
  • Underfitting – fails to capture patterns even on training data.
  • Model – mathematical representation that maps inputs to outputs.
  • Evaluation metrics – quantitative performance measures.

Hyper-parameters & Cross-Validation (CV)

  • Hyper-parameter = user-set learning configuration (e.g. number of trees, kk in K-Means, kernel of SVM).
  • kk-fold CV: split data into kk parts; rotate train/validate; average score → robust estimate.
  • Grid/Random search on hyper-parameter combinations combined with CV yields best settings.

Obtaining Training Samples

  • Field work (GPS ground truth).
  • Visual interpretation on medium- or high-resolution imagery.
  • Existing GIS/remote-sensing databases.
  • Recommendation: mix remote techniques with random points to minimise bias; digitise points/polygons with consistent criteria.
  • QGIS tools (Vertex Editor, Add Feature, Node Tool, etc.) facilitate manual delineation.
  • After digitising, label samples via attribute table.

Typical Supervised-Classification Workflow

  1. Pre-process satellite scene (cloud mask, radiometric / atmospheric corrections, pansharpen if needed).
  2. Gather training polygons/pixels.
  3. Stack all spectral bands & indices into multi-band raster cube.
  4. Extract pixel values under training geometries → feature table.
  5. Split data → train / validate / test; perform normalisation or outlier correction if required.
  6. Select algorithm + tune hyper-parameters via CV.
  7. Train model, evaluate on validation/test; compute confusion matrix, OA, Kappa, F1, Producer/User accuracies.
  8. Apply classifier to full image; post-process (smoothing, majority filters, accuracy assessment with independent samples).

Confusion-Matrix–Based Accuracy Metrics

  • Overall Accuracy (OA): OA=<em>in</em>iiN\text{OA}=\frac{\sum<em>{i} n</em>{ii}}{N}
  • Producer Accuracy (Recall): PA<em>i=n</em>ii<em>jn</em>ij\text{PA}<em>i=\frac{n</em>{ii}}{\sum<em>j n</em>{ij}} — how many reference pixels of class ii were correctly mapped.
  • User Accuracy (Precision): UA<em>i=n</em>ii<em>jn</em>ji\text{UA}<em>i=\frac{n</em>{ii}}{\sum<em>j n</em>{ji}} — reliability of labelled pixels.
  • Kappa Index: κ=p<em>op</em>e1p<em>e\kappa = \frac{p<em>o-p</em>e}{1-p<em>e}, where p</em>op</em>o = observed agreement, pep_e = chance agreement.
  • F1-Score: F1=2PrecisionRecallPrecision+RecallF_1=2\frac{\text{Precision}\,\cdot\,\text{Recall}}{\text{Precision}+\text{Recall}}.

Data Extraction in R

  • Extract per-band values below vector features: extract(img, shp, bind=T).
  • Convert class field to categorical factor: factor(vector, levels, labels).

Core Python Libraries for RS ML

  • rasterio (GDAL-based raster IO), numpy, pandas, matplotlib, scikit-learn.

Loading & Cleaning Data (Python Snippet)

import pandas as pd, rasterio, numpy as np, matplotlib.pyplot as plt
# 1. tabular samples
samples = pd.read_csv('data_muestras.csv')
print(samples.head(), samples.shape)
# 2. drop NAs
samples = samples.dropna()
# 3. split predictors / labels
X = samples.iloc[:,3:-1]   # adjust column indices
y = samples['CLASES_NUM']

Data Normalisation

  • Standard Scaler: z=xμσz=\frac{x-\mu}{\sigma} (mean 00, std 11) – good for Gaussian-assumption models (SVM, KNN, logistic).
  • Min–Max Scaler: x=xx<em>minx</em>maxxminx' = \frac{x-x<em>{\min}}{x</em>{\max}-x_{\min}}[0,1][0,1] range – common for neural nets or distance-based models.

Decision Tree – CART/CAST

  • Splits data recursively into axis-aligned rectangular regions.
  • Impurity criteria
    • Gini: G=1<em>i=1Cp</em>i2G = 1-\sum<em>{i=1}^C p</em>i^2.
    • Entropy (Shannon): H=<em>i=1Cp</em>ilog<em>2p</em>iH=-\sum<em>{i=1}^C p</em>i\log<em>2 p</em>i.
  • Key terminology: root node, internal decision node, leaf node, splitting, pruning.
  • Stopping rules: pure node (G=0G=0), max depth, min samples per split/leaf, min impurity decrease.
  • Hyper-parameters (Scikit-learn DecisionTreeClassifier)
    • criterion ("gini" | "entropy" | "log_loss"), max_depth, min_samples_split, min_samples_leaf, ccp_alpha (cost-complexity pruning), etc.
  • Pros: intuitive, handles mixed data types, no scaling needed. Cons: prone to overfit; single tree less accurate than ensembles.
  • Python code skeleton provided (train/test split, fit, predict; plot_tree visualisation; printing feature importances, depth, n_leaves).

k-Nearest Neighbors (k-NN)

  • For new pixel xx
    1. Compute distance to all training points (often Euclidean d(x,x<em>i)=(x</em>jxij)2d(\mathbf{x},\mathbf{x<em>i}) = \sqrt{\sum (x</em>j-x_{ij})^2}).
    2. Select kk nearest; vote majority class.
  • Critical hyper-parameter kk → choose via CV, usually odd (3,5,7) when 2 classes.
  • Scaling mandatory; distance sensitive to variable scales.
  • Pros: simple, non-parametric. Cons: expensive prediction on large datasets; sensitive to irrelevant features & class imbalance.
  • Provided code: CV loop for k=1..19k=1..19 plotting mean accuracy; retrain with best kk.
  • Based on Bayes theorem P(CX)=P(XC)P(C)P(X)P(C|X)=\frac{P(X|C)\,P(C)}{P(X)} assuming conditional independence among predictors.
  • For Gaussian NB: each feature assumed normally distributed per class P(x<em>jC</em>k)=N(μ<em>jk,σ</em>jk2)P(x<em>j|C</em>k) = \mathcal{N}(\mu<em>{jk},\sigma</em>{jk}^2).
  • Steps
    1. Estimate prior P(Ck)P(C_k).
    2. Estimate μ<em>jk,σ</em>jk\mu<em>{jk},\sigma</em>{jk} for each feature/class.
    3. Compute posteriors for new XX; assign largest.
  • Fast, works well with high-dimensional sparse data; independence rarely true → may mis-model interactions.
  • Example training/prediction code with GaussianNB.

Random Forest (RF)

  • Ensemble of decision trees built via Bagging + random feature selection.
  • Key concepts
    • Bootstrap sampling (with replacement) per tree.
    • Random subset of predictors at each split (decorrelates trees).
    • Majority voting for classification; averaging for regression.
  • Benefits: reduces overfitting, handles high-dimensional & unbalanced data, needs little tuning.
  • Hyper-parameters (RandomForestClassifier): n_estimators, max_depth, max_features, min_samples_split, min_samples_leaf, class_weight, oob_score (out-of-bag accuracy).
  • Trade-off: more trees ↑ accuracy but ↑ compute.

Support Vector Machine (SVM)

  • Finds optimal separating hyperplane wx+b=0\mathbf{w}\cdot\mathbf{x}+b=0 maximising margin 2w\frac{2}{||\mathbf{w}||}.
  • Optimisation (soft-margin):
    min<em>w,b,ξ  12w2+C</em>iξ<em>i\min<em>{\mathbf{w},b,\xi}\;\frac12||\mathbf{w}||^2 + C\sum</em>i\xi<em>i subject to y</em>i(wx<em>i+b)1ξ</em>i,  ξi0y</em>i(\mathbf{w}\cdot\mathbf{x}<em>i+b) \ge 1-\xi</em>i,\;\xi_i\ge0.
  • Kernel trick projects data into higher-dimensional feature space (radial basis function, polynomial, sigmoid, linear).
  • Key hyper-parameters: C (regularisation), kernel, gamma (RBF width), degree, coef0.
  • Multiclass Strategies
    • One-vs-Rest (OvR): kk classifiers.
    • One-vs-One (OvO): k(k1)2\frac{k(k-1)}{2} classifiers (scikit-learn default).
  • Pros: effective in high-dimensional space, flexible kernels. Cons: scaling issues for very large datasets; parameter tuning crucial; limited interpretability.

Full-Scene Classification & Export (Python Snippet)

with rasterio.open('PROCESADAS/chancay_2020.tif') as src:
    bands = src.read()            # shape: (n_bands, rows, cols)
    profile = src.profile
bands = bands.reshape(bands.shape[0], -1).T            # (n_pix, n_bands)
bands_scaled = scaler.transform(bands)                 # use same scaler as training
nodata = profile.get('nodata')
mask = ~np.any(np.isnan(bands_scaled) | (bands_scaled==nodata), axis=1)
X_valid = bands_scaled[mask]
y_pred = clf.predict(X_valid)                           # clf from any trained model
# Re-insert into raster grid
pred_full = np.full(bands_scaled.shape[0], nodata, dtype='uint8')
pred_full[mask] = y_pred.astype('uint8')
classified = pred_full.reshape(profile['height'], profile['width'])
# Display & save
plt.imshow(classified, cmap='tab10'); plt.axis('off'); plt.show()
profile.update(dtype=rasterio.uint8, count=1, nodata=0)
with rasterio.open('CAST/cast_2025.tif','w', **profile) as dst:
    dst.write(classified, 1)

Additional Practical Tips

  • Always keep identical preprocessing (scaling, cloud masking) between training samples and full-scene classification.
  • Consider balancing classes (e.g. class_weight='balanced' in RF/SVM) when reference data are imbalanced.
  • For spectral-index features, compute NDVI, NDWI, NDBI, etc. and add as additional bands before stacking.
  • Apply majority or sieve filters to reduce salt-and-pepper noise after pixel-based classification.
  • Use independent accuracy samples (separate from training/validation) for final assessment.

Ethical / Practical Considerations

  • Training data collection should minimise bias; random, stratified sampling recommended.
  • Over-reliance on automated models without ground verification may propagate systematic errors (e.g., misclassification of clouds/shadows as water).
  • Computational costs (RF with many trees, SVM with non-linear kernels) must be weighed against real-time or resource constraints in public-sector deployments.