.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/algorithms/dilate_image.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_algorithms_dilate_image.py: Basic Image Cleaning and Dilation ================================= Here we create an example shower image, do a tail-cuts (picture/boundary) cleaning, and then dilate the resulting cleaning mask by several neighbor pixels .. GENERATED FROM PYTHON SOURCE LINES 10-36 .. code-block:: Python :lineno-start: 11 import astropy.units as u # %matplotlib inline from matplotlib import pyplot as plt from ctapipe.image import dilate, tailcuts_clean, toymodel from ctapipe.instrument import SubarrayDescription from ctapipe.visualization import CameraDisplay # Load a camera from an example file subarray = SubarrayDescription.read("dataset://gamma_prod5.simtel.zst") geom = subarray.tel[100].camera.geometry # Create a fake camera image to display: model = toymodel.Gaussian( x=0.2 * u.m, y=0.0 * u.m, width=0.05 * u.m, length=0.15 * u.m, psi="35d", ) image, sig, bg = model.generate_image(geom, intensity=1500, nsb_level_pe=5) .. GENERATED FROM PYTHON SOURCE LINES 37-39 Apply the image cleaning: .. GENERATED FROM PYTHON SOURCE LINES 39-48 .. code-block:: Python :lineno-start: 40 cleanmask = tailcuts_clean(geom, image, picture_thresh=10, boundary_thresh=5) clean = image.copy() clean[~cleanmask] = 0.0 disp = CameraDisplay(geom, image=image) disp.highlight_pixels(cleanmask, color="red") .. image-sg:: /auto_examples/algorithms/images/sphx_glr_dilate_image_001.png :alt: NectarCam :srcset: /auto_examples/algorithms/images/sphx_glr_dilate_image_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 49-51 Now dialte the mask a few times: .. GENERATED FROM PYTHON SOURCE LINES 51-62 .. code-block:: Python :lineno-start: 53 def show_dilate(mask, times=1): m = mask.copy() for ii in range(times): m = dilate(geom, m) CameraDisplay( geom, image=(m.astype(int) + mask.astype(int)), title="dilate{}".format(times) ) .. GENERATED FROM PYTHON SOURCE LINES 63-68 .. code-block:: Python :lineno-start: 63 plt.figure(figsize=(18, 3)) for ii in range(0, 6): plt.subplot(1, 7, ii + 1) show_dilate(cleanmask.copy(), times=ii) .. image-sg:: /auto_examples/algorithms/images/sphx_glr_dilate_image_002.png :alt: dilate0, dilate1, dilate2, dilate3, dilate4, dilate5 :srcset: /auto_examples/algorithms/images/sphx_glr_dilate_image_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 2.732 seconds) .. _sphx_glr_download_auto_examples_algorithms_dilate_image.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: dilate_image.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: dilate_image.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: dilate_image.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_