{
    "nbformat": 4,
    "nbformat_minor": 5,
    "metadata": {
        "kernelspec": {
            "display_name": "Python",
            "language": "python",
            "name": "python"
        },
        "language_info": {
            "name": "python"
        }
    },
    "cells": [
        {
            "id": "392452c7",
            "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": "e0214a48",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "from scipy import ndimage\nimport numpy as np\na = np.zeros((7,7), dtype=int)\na[2:5, 2:5] = 1\na[4,4] = 2; a[2,3] = 3\na",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[0, 0, 0, 0, 0, 0, 0],\n       [0, 0, 0, 0, 0, 0, 0],\n       [0, 0, 1, 3, 1, 0, 0],\n       [0, 0, 1, 1, 1, 0, 0],\n       [0, 0, 1, 1, 2, 0, 0],\n       [0, 0, 0, 0, 0, 0, 0],\n       [0, 0, 0, 0, 0, 0, 0]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "103dd205",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ndimage.grey_dilation(a, size=(3,3))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[0, 0, 0, 0, 0, 0, 0],\n       [0, 1, 3, 3, 3, 1, 0],\n       [0, 1, 3, 3, 3, 1, 0],\n       [0, 1, 3, 3, 3, 2, 0],\n       [0, 1, 1, 2, 2, 2, 0],\n       [0, 1, 1, 2, 2, 2, 0],\n       [0, 0, 0, 0, 0, 0, 0]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "ce845717",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ndimage.grey_dilation(a, footprint=np.ones((3,3)))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[0, 0, 0, 0, 0, 0, 0],\n       [0, 1, 3, 3, 3, 1, 0],\n       [0, 1, 3, 3, 3, 1, 0],\n       [0, 1, 3, 3, 3, 2, 0],\n       [0, 1, 1, 2, 2, 2, 0],\n       [0, 1, 1, 2, 2, 2, 0],\n       [0, 0, 0, 0, 0, 0, 0]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "5f9f860a",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "s = ndimage.generate_binary_structure(2,1)\ns",
            "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": "67ac174f",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ndimage.grey_dilation(a, footprint=s)",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[0, 0, 0, 0, 0, 0, 0],\n       [0, 0, 1, 3, 1, 0, 0],\n       [0, 1, 3, 3, 3, 1, 0],\n       [0, 1, 1, 3, 2, 1, 0],\n       [0, 1, 1, 2, 2, 2, 0],\n       [0, 0, 1, 1, 2, 0, 0],\n       [0, 0, 0, 0, 0, 0, 0]])"
                    },
                    "execution_count": null
                }
            ]
        },
        {
            "id": "7ee69090",
            "cell_type": "code",
            "metadata": {},
            "execution_count": null,
            "source": "ndimage.grey_dilation(a, size=(3,3), structure=np.ones((3,3)))",
            "outputs": [
                {
                    "output_type": "execute_result",
                    "metadata": {},
                    "data": {
                        "text/plain": "array([[1, 1, 1, 1, 1, 1, 1],\n       [1, 2, 4, 4, 4, 2, 1],\n       [1, 2, 4, 4, 4, 2, 1],\n       [1, 2, 4, 4, 4, 3, 1],\n       [1, 2, 2, 3, 3, 3, 1],\n       [1, 2, 2, 3, 3, 3, 1],\n       [1, 1, 1, 1, 1, 1, 1]])"
                    },
                    "execution_count": null
                }
            ]
        }
    ]
}