.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/plot_tif_processing_steps.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_plot_tif_processing_steps.py: Tif Processing Steps ==================== This example applies common processing steps to a Zeiss SEM TIF image and compares the intermediate results. .. GENERATED FROM PYTHON SOURCE LINES 8-19 .. code-block:: Python from pathlib import Path import matplotlib.pyplot as plt import micromechanics from micromechanics.tif import Tif repository_root = Path(micromechanics.__file__).resolve().parents[1] file_name = repository_root / "examples" / "Zeiss" / "Zeiss.tif" .. GENERATED FROM PYTHON SOURCE LINES 20-22 Load the Zeiss SEM image and crop to a region of interest. Keeping a copy after each stage makes it easy to compare the effect of each processing step. .. GENERATED FROM PYTHON SOURCE LINES 22-27 .. code-block:: Python image = Tif(str(file_name)) image.crop(xMin=50, xMax=450, yMin=50, yMax=350) cropped = image.image.copy() .. rst-class:: sphx-glr-script-out .. code-block:: none After cropping: new size of image: 400 300 .. GENERATED FROM PYTHON SOURCE LINES 28-30 Apply a median filter to suppress isolated pixel noise, then a Gaussian filter for mild smoothing. The two filters target different kinds of image noise. .. GENERATED FROM PYTHON SOURCE LINES 30-35 .. code-block:: Python image.medianFilter(level=2) image.gaussFilter(level=1) filtered = image.image.copy() .. GENERATED FROM PYTHON SOURCE LINES 36-38 Adjust contrast and add a scale bar. The processed copy is the version that would typically be used in a figure or report. .. GENERATED FROM PYTHON SOURCE LINES 38-43 .. code-block:: Python image.contrast(magnitude=1.4, offset=0.45, save=True) image.addScaleBar(site="BR", length=1) processed = image.image.copy() .. GENERATED FROM PYTHON SOURCE LINES 44-46 Compare the intermediate results side by side. This helps tune the crop, filtering, and contrast parameters before saving a final image. .. GENERATED FROM PYTHON SOURCE LINES 46-56 .. code-block:: Python fig, axes = plt.subplots(1, 3, figsize=(9, 3)) for ax, title, data in zip(axes, ["cropped", "filtered", "processed"], [cropped, filtered, processed]): ax.imshow(data, cmap="gray") ax.set_title(title) ax.axis("off") plt.tight_layout() .. image-sg:: /auto_examples/images/sphx_glr_plot_tif_processing_steps_001.png :alt: cropped, filtered, processed :srcset: /auto_examples/images/sphx_glr_plot_tif_processing_steps_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.174 seconds) .. _sphx_glr_download_auto_examples_plot_tif_processing_steps.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_tif_processing_steps.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_tif_processing_steps.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_tif_processing_steps.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_