.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/07_ui/viz_image_container_2d.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_07_ui_viz_image_container_2d.py: ================== ImageContainer2D ================== This example demonstrates how to use the ``ImageContainer2D`` UI element to display 2D images in the FURY rendering window. ``ImageContainer2D`` supports various input formats including local image paths and raw NumPy arrays. First, let's import the necessary modules. .. GENERATED FROM PYTHON SOURCE LINES 12-19 .. code-block:: Python import numpy as np from fury.ui import ImageContainer2D from fury.window import Scene, ShowManager from fury.data import fetch_viz_cubemaps, read_viz_cubemap .. GENERATED FROM PYTHON SOURCE LINES 20-22 Fetch an existing image (a skybox texture) from FURY's datasets to use as a file path input. .. GENERATED FROM PYTHON SOURCE LINES 22-27 .. code-block:: Python fetch_viz_cubemaps() skybox_images = read_viz_cubemap("skybox") texture_path = skybox_images[0] .. rst-class:: sphx-glr-script-out .. code-block:: none Dataset is already in place. If you want to fetch it again please first remove the folder /Users/maharshigor/.fury/cubemaps .. GENERATED FROM PYTHON SOURCE LINES 28-29 Generate a 256x256 RGB image array with varying color gradients using NumPy. .. GENERATED FROM PYTHON SOURCE LINES 29-36 .. code-block:: Python img_rgb = np.zeros((256, 256, 3), dtype=np.uint8) for i in range(256): img_rgb[:, i, 0] = i img_rgb[i, :, 1] = (i * 2) % 256 img_rgb[:, :, 2] = 128 .. GENERATED FROM PYTHON SOURCE LINES 37-38 Generate an RGBA image array, which includes an alpha channel for transparency. .. GENERATED FROM PYTHON SOURCE LINES 38-46 .. code-block:: Python img_rgba = np.zeros((256, 256, 4), dtype=np.uint8) for i in range(256): img_rgba[:, i, 0] = 255 - i img_rgba[i, :, 1] = (i * 2) % 256 img_rgba[:, :, 2] = 128 img_rgba[:, i, 3] = 255 - i .. GENERATED FROM PYTHON SOURCE LINES 47-48 Convert the RGB image into a single-channel grayscale image. .. GENERATED FROM PYTHON SOURCE LINES 48-55 .. code-block:: Python img_gray = ( 0.2989 * img_rgb[..., 0].astype(np.float32) + 0.5870 * img_rgb[..., 1].astype(np.float32) + 0.1140 * img_rgb[..., 2].astype(np.float32) ).astype(np.uint8) .. GENERATED FROM PYTHON SOURCE LINES 56-58 Initialize a Scene and create an ImageContainer2D for each image type. Set the position to arrange them in a 2x2 grid on the window. .. GENERATED FROM PYTHON SOURCE LINES 58-85 .. code-block:: Python scene = Scene() gray_container = ImageContainer2D( img_path=img_gray, position=(50, 450), size=(256, 256), ) rgb_container = ImageContainer2D( img_path=img_rgb, position=(350, 450), size=(256, 256), ) rgba_container = ImageContainer2D( img_path=img_rgba, position=(50, 100), size=(256, 256), ) skybox_container = ImageContainer2D( img_path=texture_path, position=(350, 100), size=(256, 256), ) .. GENERATED FROM PYTHON SOURCE LINES 86-87 Add all image containers to the scene. .. GENERATED FROM PYTHON SOURCE LINES 87-93 .. code-block:: Python scene.add(gray_container) scene.add(rgb_container) scene.add(rgba_container) scene.add(skybox_container) .. GENERATED FROM PYTHON SOURCE LINES 94-95 Create and start the ShowManager. .. GENERATED FROM PYTHON SOURCE LINES 95-102 .. code-block:: Python show_manager = ShowManager( scene=scene, size=(700, 800), title="FURY ImageContainer2D Example", ) show_manager.start() .. image-sg:: /auto_examples/07_ui/images/sphx_glr_viz_image_container_2d_001.png :alt: viz image container 2d :srcset: /auto_examples/07_ui/images/sphx_glr_viz_image_container_2d_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.278 seconds) .. _sphx_glr_download_auto_examples_07_ui_viz_image_container_2d.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: viz_image_container_2d.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: viz_image_container_2d.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: viz_image_container_2d.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_