{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "8b339e39",
            "cell_type": "markdown",
            "source": "<div class='alert alert-warning'>\n\nSciPy's interactive examples with Jupyterlite are experimental and may not always work as expected. Execution of cells containing imports may result in large downloads (up to 60MB of content for the first import from SciPy). Load times when importing from SciPy may take roughly 10-20 seconds. If you notice any problems, feel free to open an [issue](https://github.com/scipy/scipy/issues/new/choose).\n\n</div>",
            "metadata": {}
        },
        {
            "id": "23ab9d68",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy import ndimage\nimport numpy as np\nstruct = ndimage.generate_binary_structure(2, 1)\nstruct",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[False,  True, False],\n       [ True,  True,  True],\n       [False,  True, False]], dtype=bool)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "5eb9f3cb",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "a = np.zeros((5,5))\na[2, 2] = 1\na",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ 0.,  0.,  0.,  0.,  0.],\n       [ 0.,  0.,  0.,  0.,  0.],\n       [ 0.,  0.,  1.,  0.,  0.],\n       [ 0.,  0.,  0.,  0.,  0.],\n       [ 0.,  0.,  0.,  0.,  0.]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "e9b8e416",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "b = ndimage.binary_dilation(a, structure=struct).astype(a.dtype)\nb",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ 0.,  0.,  0.,  0.,  0.],\n       [ 0.,  0.,  1.,  0.,  0.],\n       [ 0.,  1.,  1.,  1.,  0.],\n       [ 0.,  0.,  1.,  0.,  0.],\n       [ 0.,  0.,  0.,  0.,  0.]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "6dd4f976",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ndimage.binary_dilation(b, structure=struct).astype(a.dtype)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ 0.,  0.,  1.,  0.,  0.],\n       [ 0.,  1.,  1.,  1.,  0.],\n       [ 1.,  1.,  1.,  1.,  1.],\n       [ 0.,  1.,  1.,  1.,  0.],\n       [ 0.,  0.,  1.,  0.,  0.]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "cb02a3c7",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "struct = ndimage.generate_binary_structure(2, 2)\nstruct",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[ True,  True,  True],\n       [ True,  True,  True],\n       [ True,  True,  True]], dtype=bool)"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "70252b6b",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "struct = ndimage.generate_binary_structure(3, 1)\nstruct # no diagonal elements",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[[False, False, False],\n        [False,  True, False],\n        [False, False, False]],\n       [[False,  True, False],\n        [ True,  True,  True],\n        [False,  True, False]],\n       [[False, False, False],\n        [False,  True, False],\n        [False, False, False]]], dtype=bool)"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}