.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/virtual_imaging/setting_virtual_masks.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_examples_virtual_imaging_setting_virtual_masks.py: Creating a Custom Virtual Mask ============================== Virtual images are easily created from a series of (currently) 4 seperate masks. These masks are 8 bit images with values: 0: Negative Mask, pixel values subtracted 1: Default value, pixels not accounted for 2: Positive Mask, pixel values added Additionally virtual images can be .. GENERATED FROM PYTHON SOURCE LINES 18-31 .. code-block:: Python from deapi import Client import matplotlib.pyplot as plt import time from skimage.draw import disk c = Client() c.usingMmf = False c.connect(port=13241) # connect to the running DE Server c.virtual_masks[0][:] = 1 # Set everything to 1 c.virtual_masks[0].plot() # plot the current v0 mask .. image-sg:: /examples/virtual_imaging/images/sphx_glr_setting_virtual_masks_001.png :alt: setting virtual masks :srcset: /examples/virtual_imaging/images/sphx_glr_setting_virtual_masks_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/deapi/deapi/deapi/data_types.py:537: UserWarning: Virtual mask shape is not set to Arbitrary. Setting to Arbitrary. warnings.warn( .. GENERATED FROM PYTHON SOURCE LINES 32-38 Changing the virtual mask ------------------------- Each of the virtual masks will act like a numpy array such that you can use numpy fancy indexing to slice or assign the array. For example we can set a portion of the mask to be 2 (positive mask) .. GENERATED FROM PYTHON SOURCE LINES 38-43 .. code-block:: Python c.virtual_masks[0][0:25] = 2 # first 25 pixels c.virtual_masks[0].name = "Sum Virt Img" c.virtual_masks[0].plot() .. image-sg:: /examples/virtual_imaging/images/sphx_glr_setting_virtual_masks_002.png :alt: setting virtual masks :srcset: /examples/virtual_imaging/images/sphx_glr_setting_virtual_masks_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 44-48 Subtracting and adding ---------------------- Different modes can be used with each virtual image. These are set using The calculation attribute. Lets try that with Virtual image 1 .. GENERATED FROM PYTHON SOURCE LINES 48-55 .. code-block:: Python c.virtual_masks[1].calculation = "Difference" c.virtual_masks[1].name = "Diff Virt Img" c.virtual_masks[1][1::2] = 0 # every other pixel subtracts c.virtual_masks[1][::2] = 2 # every other pixel subtracts c.virtual_masks[1].plot() .. image-sg:: /examples/virtual_imaging/images/sphx_glr_setting_virtual_masks_003.png :alt: setting virtual masks :srcset: /examples/virtual_imaging/images/sphx_glr_setting_virtual_masks_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 56-58 Creating a Virtual BrightField Image ------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 58-67 .. code-block:: Python c.virtual_masks[2].calculation = "Sum" c.virtual_masks[2].name = "VBF" shape = c.virtual_masks[2][:].shape rr, cc = disk((shape[0] // 2, shape[1] // 2), 100) c.virtual_masks[2][:] = 1 c.virtual_masks[2][rr, cc] = 2 c.virtual_masks[2].plot() .. image-sg:: /examples/virtual_imaging/images/sphx_glr_setting_virtual_masks_004.png :alt: setting virtual masks :srcset: /examples/virtual_imaging/images/sphx_glr_setting_virtual_masks_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 68-78 .. code-block:: Python # Plotting Multiple Virtual Images # -------------------------------- # We can also make a tableau of virtual images using the matplotlib.pyplot # package and passing an Axis to the plot function fig, axs = plt.subplots(1, 2) for a, v in zip(axs, c.virtual_masks): v.plot(ax=a) .. image-sg:: /examples/virtual_imaging/images/sphx_glr_setting_virtual_masks_005.png :alt: setting virtual masks :srcset: /examples/virtual_imaging/images/sphx_glr_setting_virtual_masks_005.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 79-83 Starting an Acquisition ----------------------- Once we have set up an experiment we can start an acquisition using the start acquisition function .. GENERATED FROM PYTHON SOURCE LINES 83-95 .. code-block:: Python c["Frames Per Second"] = 5000 # 5000 frames per second c.scan(enable="On", size_x=128, size_y=128) c.start_acquisition() while c.acquiring: # wait for acquisition to finish and then plot the results time.sleep(1) fig, axs = plt.subplots(1, 3) for a, virt in zip(axs, ["virtual_image0", "virtual_image1", "virtual_image2"]): data, _, _, _ = c.get_result(virt) a.imshow(data) .. image-sg:: /examples/virtual_imaging/images/sphx_glr_setting_virtual_masks_006.png :alt: setting virtual masks :srcset: /examples/virtual_imaging/images/sphx_glr_setting_virtual_masks_006.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 5.001 seconds) .. _sphx_glr_download_examples_virtual_imaging_setting_virtual_masks.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: setting_virtual_masks.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: setting_virtual_masks.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: setting_virtual_masks.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_