#!/usr/bin/env python # coding: utf-8 # This notebook is part of the PyImageJ [Tutorial Series](./notebooks.rst), and assumes familiarity with the ImageJ API. Dedicated tutorials for ImageJ can be found [here](https://imagej.net/tutorials/). # # 5 Convenience methods of PyImageJ # # PyImageJ is built to provide easy access to key ImageJ resources. We call these collective methods "convenience methods". These methods are attached to`ij.py` after initializing ImageJ. Here's a quick list of some of the more useful methods and additional information. # | `ij.py.` | function | more information | # | :---: | :---: | :---: | # | `show` | Show an image | [06-Working-with-Images](06-Working-with-Images.ipynb) # | `to_java` | Convert data from Python to Java | [03-Sending-Data-to-Java](03-Sending-Data-to-Java.ipynb) | # | `from_java` | Convert data from Java to Python | [04-Retrieving-Data-from-Java](04-Retrieving-Data-from-Java.ipynb) | # | `run_macro` | Run an original ImageJ macro | [07-Running-Macros-Scripts-and-Plugins](07-Running-Macros-Scripts-and-Plugins.ipynb) | # | `run_script` | Run an ImageJ script (supported languages) | [07-Running-Macros-Scripts-and-Plugins](07-Running-Macros-Scripts-and-Plugins.ipynb) | # | `run_plugin` | Run a plugin | [07-Running-Macros-Scripts-and-Plugins](07-Running-Macros-Scripts-and-Plugins.ipynb) | # | `initialize_numpy_image` | Create a new numpy image in the same shape as input image | [06-Working-with-Images](06-Working-with-Images.ipynb) | # | `sync_image` | Synchronize data between ImageJ and ImageJ2 data structures | -- | # | `active_dataset` | Get the active image as a `Dataset` | -- | # | `active_xarray` | Get a copy of the active image as an `xarray.DataArray` | -- | # | `active_imageplus` | Get the `ImagePlus` from the current window | -- | # There are other convenience methods that are attached to `ij.py`. After initializing ImageJ you can explore `ij.py`'s methods with `dir`. # ## 5.1 Other convenient access to ImageJ functions # # When the original ImageJ is available (_i.e._ the legacy layer is active) `IJ`, `WindowManager`, `ResultsTable` and `RoiManager` are accessible directly from the initialized `ij` object. # In[1]: import imagej # initialize imagej ij = imagej.init() print(f"ImageJ2 version: {ij.getVersion()}") # first check if the legacy layer is active print(f"Legacy layer active: {ij.legacy.isActive()}") # In[2]: # demonstrate access to classes print(ij.IJ) print(ij.ResultsTable) print(ij.RoiManager) print(ij.WindowManager) # Note the warnings! We're currently in headless mode. The many legacy ImageJ functions operate limitedly or not at all in headless mode. For example the `RoiManager` is not functional in a true headless enviornment.