(work in progress)
This project is a simple implementation of change detection for raster imagery using Python. It utilizes rasterio to read and write GeoTIFF files, enabling efficient geospatial data processing. The solution computes pixel-wise differences between two input images and generates a binary change map 🗺️.
Change detection is a critical technique used across various domains to identify and analyze differences in spatial, structural, or environmental data over time with uses in:
- Humanitarian Assistance and Disaster Relief (HADR): assessing damage after natural disasters by comparing pre- and post-event satellite imagery;
- Imagery Intelligence (IMINT) analysis: monitor activity patterns, and infrastructure developments; and
- Cartography: detect landscape changes such as new urban developments, deforestation, or shifting coastlines to assist in mapsheet refreshes.
Rasterio is a Python library that enables reading, writing, and processing geospatial raster datasets. It provides an easy-to-use API to handle raster formats like GeoTIFF while maintaining geospatial metadata and ensuring efficient I/O operations.
The code extracts only the first band (assumes single-band grayscale images). (Note: it is recommended to use images that have the same projection system)
- If the two images have different dimensions, it resizes the second image to match the first one.
- This ensures pixel-wise comparison.
- The script calculates the absolute difference between the two images to highlight changed areas while ignoring sign differences.
- Normalization: Scales
diff_imagevalues between0-255for consistency. - Logarithmic Transformation: log(1 + diff_image)
- Thresholding: Computes a dynamic threshold (
threshold = 0.5 * max(diff)) and sets pixels above threshold to 255 (white) and below to 0 (black).
Ensure you have Python installed along with the following libraries:
- rasterio 🗺️
- numpy 🔢
- matplotlib 📊
Install them:
pip install rasterio numpy matplotlib Execute it in your terminal or command prompt
python mapmole.py 📂 Input the file paths accordingly
The script will generate an output GeoTIFF file (e.g., output_change_map.tif) containing the binary change map. It will also display visualizations of the input images and the resulting change map. (In the event that too many or too few changes are being detected in the output map, adjust the threshold parameter in the script.)
💡 Pro Tip: Try this solution for deforestation monitoring 🌳, urban expansion tracking 🏙️, or disaster impact assessment 🌊
💡 Pro Tip 2: Color correcting the imagery would generally be helpful. Note that results may vary based on the cloud cover and errors in georectification.

