{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"execution": {
"iopub.execute_input": "2020-09-29T01:08:19.500487Z",
"iopub.status.busy": "2020-09-29T01:08:19.500061Z",
"iopub.status.idle": "2020-09-29T01:08:19.791026Z",
"shell.execute_reply": "2020-09-29T01:08:19.791536Z"
}
},
"outputs": [],
"source": [
"import sys\n",
"import os\n",
"sys.path.append(os.environ.get('NOTEBOOK_ROOT'))\n",
"\n",
"%matplotlib inline \n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"\n",
"# Coastline Classifier\n",
"This coastal boundary algorithm is used to classify a given pixel as either coastline or not coastline using a simple binary format like in the table before. \n",
"\n",
"
\n",
"\n",
"$\\begin{array}{|c|c|}\n",
"\\hline\n",
"1& Coastline \\\\ \\hline\n",
"0& Not Coastline \\\\ \\hline\n",
"\\end{array}$\n",
"\n",
"
\n",
"\n",
"\n",
"The algorithm makes a classification by examining surrounding pixels and making a determination based on how many pixels around it are water \n",
"\n",
"
\n",
"\n",
" \n",
" \n",
"
\n",
"\n",
"If the count of land pixels surrounding a pixel exceeds 5, then it's likely not coastline.\n",
"If the count of land pixels surrounding a pixel does not exceed 1, then it's likely not a coastline\n",
" \n",
"
\n",
"\n",
"$$\n",
"Classification(pixel) = \\begin{cases} \n",
" 1 & 2\\le count\\_water\\_surrounding(pixel) \\leq 5 \\\\\n",
" 0 & \n",
" \\end{cases}\n",
"$$\n",
"\n",
"
\n",
" \n",
" \n",
"### Counting by applying a convolutional kernel \n",
"\n",
"A convolution applies a `kernel` to a point and it's surrounding pixels. Then maps the product to a new grid. \n",
" \n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"\n",
"In the case of coastal boundary classification, A convolution the following kernel is applied to a grid of `water`, `not-water` pixels.\n",
"\n",
"
\n",
"\n",
"\n",
"$$ \n",
"Kernel =\n",
" \\begin{bmatrix}\n",
" 1 & 1 & 1\\\\\n",
" 1 & 0 & 1\\\\ \n",
" 1 & 1 & 1\\\\\n",
" \\end{bmatrix}\n",
"$$ \n",
" \n",
"
\n",
"There exist more complicated differential kernels that would also work( see [sobel operator](https://en.wikipedia.org/wiki/Sobel_operator)). \n",
"The one used in this notebooks operates on binary variables and is easier to work with and easy to debug. \n",
"\n",
"