🛰️ 4 Steps to Detect Coastline Changes from Satellite | by Alessio Vaccaro | Towards Data Science

Coasts are a very dynamic system in which the phenomena of erosion, and therefore of retreat, or advancement of the coastline are managed by numerous meteoclimatic, geological, biological and anthropic factors.
In the case where the action of marine abrasion is greater than the deposit, there are evident cases of coastal erosion that literally lead to the disintegration and demolition of the earth’s surface.
In this article, we will use an algorithm called Canny Edge Detection on two satellite images acquired by the OLI (Operational Land Imager) sensor on Landsat 8 platform.
Through this methodology, we will be able to visualize and estimate the progress of the coastline over time of a particular European area subject to strong erosion actions: the Holderness Coast.
Here is the proposed workflow:
Let’s start! But before...
The Landsat 8 is an orbiting platform that mounts on board an 11-band multispectral sensor called OLI (Operational Land Imager).
Specifically, in this article, we will use only the bands with a resolution of 30 meters (i.e. the first 7).
The data can be downloaded free of charge, after registration, through the platform provided by the USGS: https://earthexplorer.usgs.gov/.
Moreover, as is usually used, rather than using the raw data of incident sunlight we will use reflectance, i.e. the amount of sunlight reflected from the earth’s surfaces [0–1].
Among the various common packages, in this article we will use rasterio to easily deal with raster images, OpenCV to apply the Canny algorithm and Scikit-Learn to segment images.
Let’s define a variable that tells us the number of bands to keep and the ancillary data previously entered in a JSON:
This Json is a collection of information from the Landsat OLI imager (created by me). A sort of instruction manual. It looks like this:
Remember that we will use only the bands with 30 m resolution, so only the first 7. If you are willing to have lower resolutions (100m) you can embed the significant TIRS 1 and TIRS 2 bands also.
As already mentioned a few lines above we will use two different acquisitions from Landsat-8 OLI:
2014/02/01
2019/07/25
To facilitate and speed up all the operations on the two acquisitions we will define an Acquisition() class that will allow us to encapsulate all the necessary functions.
During the execution of the code, this will allow us to perform some support functions such as:
GeoTIFF search in the specified path;
loading acquisitions;
acquisitions registration (aligning them);
acquisitions subsetting
Ok, we can now launch the entire code by using:
The result should be something like this:
Searching for 'tif' files in Data/2014-02-01Found 7 'tif' filesLoading imagesDoneSearching for 'tif' files in Data/2019-07-25Found 7 'tif' filesLoading imagesDone
Our 14 OLI images (2 acquisition in 7 bands) are now loaded.
At this stage, after the “alignment” (or more formally registration) of the two multispectral cubes, we take care of cutting out the portion of the acquisition that doesn’t interests us.
Let’s use the function subsetImages() to “cut” the unwanted data.
So let’s therefore define the AOI (Area of Interest) and proceed to subsetting using the function subsetImages() within the Acquisition() class:
Done!
Let’s try to view all the bands of the 2019/07/25 acquisition. For purely aesthetic reasons, before making the image plot, let’s perform standardization of the images using the StandardScaler().
This should be the result.
As you can see some bands are brightest than others. This is pretty normal.
Let’s now try to visualize both acquisitions in an RGB composite obtained using bands 4 (Red), 3 (Green) and 2 (Blue).
BIAS and GAIN are defined only to get a pretty viz.
And here is the result! It is funny how the two acquisitions are particularly different in terms of reflectance.
Ok, move on to coastline detection.
In this paragraph, we will perform edge detection using Canny’s methodology.
Before going to the real detection it is necessary to prepare the dataset trying to segment it through a clustering algorithm to discriminate between oceans and lands.
At this stage we should reshaping the two multispectral cubes for clustering operations.
Let’s segment of the two acquisitions through k-means (use the model you prefer).
Here are the two clusters identified representing emerged lands and water bodies.
Canny’s technique in a traditional key is divided into the following phases:
Noise reduction by convolution with a Gaussian filter;Image gradient calculation in the four directions (horizontal, vertical and 2 oblique);Extraction of gradient local maxima;Threshold with hysteresis for edge extraction.
Noise reduction by convolution with a Gaussian filter;
Image gradient calculation in the four directions (horizontal, vertical and 2 oblique);
Extraction of gradient local maxima;
Threshold with hysteresis for edge extraction.
Let’s start immediately by converting the clustering result into images and then reducing the noise through a Gaussian filter with a 15x15 kernel:
After slightly blurring the images we can proceed to the execution of the real Canny technique with the OpenCV Canny() module:
In a single line of code, we obtained the gradient, extracted the local maxima and then applied the threshold with hysteresis for each acquisition.
NOTE: Play with the Canny() parameters to explore different results.
And here are the results.
And here are a few details:
As you can see from the results, Canny’s algorithm in its original pipeline works quite well but its performance depends - as usual- on the data involved.
The clustering algorithm used, in fact, has allowed us to segment the starting multispectral cubes with performances that can certainly be improved. The use of several clustering models in parallel could overall improve the results.
🤝 If you have any doubts, feedback or requests for collaboration, please do not hesitate to contact me on Linkedin. I will be very happy to have a chat with you!
👉 For more contents like this one and to stay updated on upcoming articles don’t forget to follow me here on Medium.
👉 For any reference to this article please contact me. Thank you.