{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "# Gaussian Smoothing {#gaussian_smoothing_example}\n\nPerform a Gaussian convolution on a uniformly gridded data set.\n\n`pyvista.ImageData`{.interpreted-text role=\"class\"} data sets (a.k.a.\nimages) a can be smoothed by convolving the image data set with a\nGaussian for one- to three-dimensional inputs. This is commonly referred\nto as Gaussian blurring and typically used to reduce noise or decrease\nthe detail of an image dataset.\n\nSee also `pyvista.ImageDataFilters.gaussian_smooth`{.interpreted-text\nrole=\"func\"}.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import pyvista as pv\nfrom pyvista import examples\n\n# Load dataset\ndata = examples.download_gourds()\n\n# Define a good point of view\ncp = [(319.5, 239.5, 1053.7372980874645), (319.5, 239.5, 0.0), (0.0, 1.0, 0.0)]"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Let\\'s apply the Gaussian smoothing with different values of standard\ndeviation.\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "p = pv.Plotter(shape=(2, 2))\n\np.subplot(0, 0)\np.add_text(\"Original Image\", font_size=14)\np.add_mesh(data, rgb=True)\np.camera_position = cp\n\np.subplot(0, 1)\np.add_text(\"Gaussian smoothing, std=2\", font_size=14)\np.add_mesh(data.gaussian_smooth(std_dev=2.0), rgb=True)\np.camera_position = cp\n\np.subplot(1, 0)\np.add_text(\"Gaussian smoothing, std=4\", font_size=14)\np.add_mesh(data.gaussian_smooth(std_dev=4.0), rgb=True)\np.camera_position = cp\n\np.subplot(1, 1)\np.add_text(\"Gaussian smoothing, std=8\", font_size=14)\np.add_mesh(data.gaussian_smooth(std_dev=8.0), rgb=True)\np.camera_position = cp\n\np.show()"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "| \n\n# Volume Rendering\n\nNow let\\'s see an example on a 3D dataset with volume rendering:\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "data = examples.download_brain()\n\nsmoothed_data = data.gaussian_smooth(std_dev=3.0)\n\n\ndargs = dict(clim=smoothed_data.get_data_range(), opacity=[0, 0, 0, 0.1, 0.3, 0.6, 1])\n\nn = [100, 150, 200, 245, 255]\n\np = pv.Plotter(shape=(1, 2))\np.subplot(0, 0)\np.add_text(\"Original Image\", font_size=24)\n# p.add_mesh(data.contour(n), **dargs)\np.add_volume(data, **dargs)\np.subplot(0, 1)\np.add_text(\"Gaussian smoothing\", font_size=24)\n# p.add_mesh(smoothed_data.contour(n), **dargs)\np.add_volume(smoothed_data, **dargs)\np.link_views()\np.camera_position = [(-162.0, 704.8, 65.02), (90.0, 108.0, 90.0), (0.0068, 0.0447, 0.999)]\np.show()"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.12.2"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}