This repository contains public MATLAB scripts that demonstrate earthquake-related change detection workflow using fully synthetic data. All inputs are anonymized and generated over a small, Kathmandu-like area.
The method implemented here follows the workflow described in:
DOI: https://doi.org/10.1016/j.jag.2025.104883 (International Journal of Applied Earth Observation and Geoinformation)
Use the headings below as a conceptual map from the article’s methodology to this code.
| Part of the paper (method / idea) | What it is in this repo |
|---|---|
| Study area, PS-like point clouds, and quality control — pre- and post-event scatterer locations after masking and thresholds (e.g. coherence), used as inputs to spatial comparison | data/generate_synthetic_grid_points.m builds synthetic pre / post and gridCells, saved as synthetic_ps.mat and synthetic_grid_2500m.mat; the README’s “Data format” describes the same roles as the paper’s inputs (here without real SAR metadata; points stand in for filtered PS). |
| Grid-based change detection — counting pre- vs post-event points per cell and forming a difference (loss of scatterers per unit area) | src/change_detection_grid_public.m — counts points in each polygon, outputs Nrpre, Nrpost, diff; mirrors the paper’s grid workflow. |
| Building-based change detection — same comparison but aggregated inside each building footprint | src/change_detection_building_public.m — uses OSM-style footprints from data/buildings_2.mat, same count-and-difference logic at building scale. |
| Grid density Dgrid — normalized indicator at grid resolution | src/density_grid_public.m — CSV column density is Dgrid from the paper (same definition as in the article’s equations). Uses the grid change-detection CSV and a synthetic numBuildings per cell in this repo; for a real case study, use building counts per grid cell as in the paper. |
| Building density Dbuilding — normalized indicator per footprint | src/density_building_public.m — CSV column density is Dbuilding from the paper, using footprint area from buildings_2.mat and building-level diff. |
| Numerical results / maps — tabulated values per spatial unit for interpretation or mapping | results/*.csv — one row per grid cell or per building with IDs, centroids, counts, diff, and density (Dgrid or Dbuilding in the density outputs). |
The density column in density_grid_synthetic.csv is Dgrid; in density_buildings_synthetic.csv it is Dbuilding (paper notation; the scripts implement the same quantities as in the paper’s density definitions).
-
data/generate_synthetic_grid_points.m: creates synthetic pre- and post-event point clouds (pre,post) and a grid of polygon cells (gridCells), and savessynthetic_ps.matandsynthetic_grid_2500m.matindata/(see How to run).
-
src/change_detection_grid_public.m: performs grid-based change detection betweenpreandpostby counting points per grid cell.change_detection_building_public.m: performs building-based change detection betweenpreandpostby counting points per building footprint.density_grid_public.m: computes Dgrid; columndensityin the output CSV is DGrid (syntheticnumBuildingsin this demo).density_building_public.m: computes Dbuilding; columndensityin the output CSV is Dbuilding (uses footprint areas).
-
results/- Output CSV files with change detection results are written here.
- Synthetic point clouds:
- Stored in
data/synthetic_ps.matas:pre[N x 3] with columns [ID, X, Y]post[M x 3] with columns [ID, X, Y]
- Points are already filtered (you can treat them as having coherence ≥ 0.7); no additional coherence column is included.
- Stored in
- Grid-based workflow:
- Uses either:
- The predefined grid in
data/synthetic_grid_2500m.mat(variablegridCellswithLon,Lat,ID), or - An auto-generated regular grid based on the extent of the synthetic points (if you switch that mode in the script).
- The predefined grid in
- Counts pre- and post-event points per cell, then computes
diff = Nrpre - Nrpost.
- Uses either:
- Building-based workflow:
- Uses Kathmandu OSM building footprints from
data/buildings_2.mat(struct arraybuildingswith fieldsX,Y,osm_id). - Counts pre- and post-event points per building, then computes
diff = Nrpre - Nrpost.
- Uses Kathmandu OSM building footprints from
The same synthetic points are used for both the grid-based and building-based analyses; only the spatial aggregation (grid vs. buildings) changes.
Prerequisites
- MATLAB with support for
polyshape,centroid,inpolygon, andreadmatrix(recent releases;readmatrixneeds R2019a+). - Image Processing Toolbox for
imgaussfiltin the data generator only. data/buildings_2.matis required for the building-based and building-density steps. It is not created by the generator and is not included in this Git repository (file size). Add your own copy underdata/if you use those scripts (the grid-only pipeline does not need it).
Workflow (run in this order)
Keep MATLAB’s current folder as indicated so paths like ../data and ../results resolve correctly.
-
Generate synthetic data
- In MATLAB, set the current folder to
data(the folder that containsgenerate_synthetic_grid_points.m). - Run:
generate_synthetic_grid_points(This calls the function defined in that file; it writes outputs into the currentdata/folder.) - Creates:
data/synthetic_ps.mat—preandpostpoint sets (synthetic points before / after the event). These are the data you count inside cells or buildings.data/synthetic_grid_2500m.mat—gridCells, the grid alone (polygon boundaries and IDs for ~2500 m cells). It does not contain points; the grid script uses it to decide where to aggregatepre/post.
- In MATLAB, set the current folder to
-
Run grid-based change detection
- Set the current folder to
src. - Inputs (read from
../data/by the script):data/synthetic_ps.mat— variablespre,postdata/synthetic_grid_2500m.mat— variablegridCells(cell polygons and IDs)
- Open and run
change_detection_grid_public.m(Editor Run or type the script name if it is on the path). - Output:
results/change_detection_grid_synthetic_diff.csv
- Columns:
ID,Xc,Yc,Nrpre,Nrpost,diff
- Set the current folder to
-
Run building-based change detection
- Current folder still
src. - Inputs (read from
../data/by the script):data/synthetic_ps.mat— variablespre,postdata/buildings_2.mat— variablebuildings(footprint polygons andosm_id)
- Open and run
change_detection_building_public.m. - Output:
results/change_detection_buildings_synthetic_diff.csv
- Columns:
ID,Xc,Yc,Nrpre,Nrpost,diff
- Current folder still
-
Run density analyses (Dgrid and Dbuilding)
- Current folder still
src. density_grid_public.m— columndensityis Dgrid (paper).- Inputs (script reads
../results/; paths below are relative to repo root):results/change_detection_grid_synthetic_diff.csv— output of step 2 (ID,Xc,Yc,Nrpre,Nrpost,diff)numBuildingsis not a file here: the script generates a synthetic count per grid cell for this demo (for a real study, replace that logic with your vector of building counts per cell, as in the paper).
- Output:
results/density_grid_synthetic.csv
- Columns:
ID,Xc,Yc,Nrpre,Nrpost,diff,numBuildings,density(= DGrid). density_building_public.m— columndensityis Dbuilding (paper).- Inputs (read from
../results/and../data/):results/change_detection_buildings_synthetic_diff.csv— output of step 3data/buildings_2.mat— variablebuildings(footprints used to compute area per row)
- Output:
results/density_buildings_synthetic.csv
- Columns:
ID,Xc,Yc,Nrpre,Nrpost,diff,area,density(= Dbuilding).
- Current folder still
- All inputs (EXCEPT OSM building footprints) are synthetic and do not contain any proprietary or real earthquake data.
- Random number generator seeds are fixed so that anyone cloning the repo can reproduce the same synthetic example.