.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "_gallery/guis/image_widget_imgui.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__gallery_guis_image_widget_imgui.py: ImGUI with ImageWidget ====================== Example showing how to write a custom GUI with imgui and use it with ImageWidget .. GENERATED FROM PYTHON SOURCE LINES 7-82 .. image-sg:: /_gallery/guis/images/sphx_glr_image_widget_imgui_001.webp :alt: image widget imgui :srcset: /_gallery/guis/images/sphx_glr_image_widget_imgui_001.webp :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/fastplotlib/fastplotlib/fastplotlib/graphics/_features/_base.py:18: UserWarning: casting float64 array to float32 warn(f"casting {array.dtype} array to float32") | .. code-block:: Python # test_example = true # some simple image processing functions from scipy.ndimage import gaussian_filter import imageio.v3 as iio import fastplotlib as fpl # subclass from EdgeWindow to make a custom ImGUI Window to place inside the figure! from fastplotlib.ui import EdgeWindow from imgui_bundle import imgui a = iio.imread("imageio:camera.png") iw = fpl.ImageWidget(data=a, cmap="viridis", figure_kwargs={"size": (700, 560)}) iw.show() # GUI for some basic image processing class ImageProcessingWindow(EdgeWindow): def __init__(self, figure, size, location, title): super().__init__(figure=figure, size=size, location=location, title=title) self.sigma = 0.0 self.order_x, self.order_y = 0, 0 def update(self): # implement the GUI within the update function # you do not need to call imgui.new_frame(), this is handled by Figure # window creation is handled by the base EdgeWindow.draw_window() # if you want to customize the imgui window, you can override EdgeWindow.draw_window() something_changed = False # slider for gaussian filter sigma value changed, value = imgui.slider_float(label="sigma", v=self.sigma, v_min=0.0, v_max=20.0) if changed: self.sigma = value something_changed = True # int entries for gaussian filter order for axis in ["x", "y"]: changed, value = imgui.input_int(f"order {axis}", v=getattr(self, f"order_{axis}")) if changed: if value < 0: value = 0 setattr(self, f"order_{axis}", value) something_changed = True if something_changed: self.process_image() # imgui.end() is handled by EdgeWindow.draw_window() # do not call imgui.end_frame(), this is handled by Figure def process_image(self): processed = gaussian_filter(a, sigma=self.sigma, order=(self.order_y, self.order_x)) iw.set_data(processed) gui = ImageProcessingWindow(iw.figure, size=200, location="right", title="Gaussian Filter") iw.figure.add_gui(gui) figure = iw.figure # NOTE: `if __name__ == "__main__"` is NOT how to use fastplotlib interactively # please see our docs for using fastplotlib interactively in ipython and jupyter if __name__ == "__main__": print(__doc__) fpl.run() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.753 seconds) .. _sphx_glr_download__gallery_guis_image_widget_imgui.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: image_widget_imgui.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: image_widget_imgui.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: image_widget_imgui.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_