Class GuiTools

java.lang.Object
imagingbook.common.ij.GuiTools

public abstract class GuiTools extends Object
Defines static helper methods related to ImageJ's GUI.
Version:
2022/09/15
  • Field Details

  • Method Details

    • chooseOpenImage

      public static ImagePlus chooseOpenImage(String title, ImagePlus exclude)
      Queries the user to select one of the currently open images.
      Parameters:
      title - name of the dialog window (if null, DEFAULT_DIALOG_TITLE is used)
      exclude - image to exclude from being selected (typically the current image)
      Returns:
      a reference to the chosen image (ImagePlus) or null, if the dialog was cancelled
    • chooseOpenImage

      public static ImagePlus chooseOpenImage(String title)
      Queries the user to select one of the currently open images.
      Parameters:
      title - name of the dialog window (if null, DEFAULT_DIALOG_TITLE is used)
      Returns:
      a reference to the chosen image (ImagePlus) or null, if the dialog was cancelled
    • chooseOpenImage

      public static ImagePlus chooseOpenImage()
      Queries the user to select one of the currently open images.
      Returns:
      a reference to the chosen image (ImagePlus) or null, if the dialog was cancelled
    • setImageView

      public static Rectangle setImageView(ImagePlus im, double magnification, int xa, int ya)
      Modifies the view of the given ImagePlus image to the specified magnification (zoom) factor and the anchor position in the source image. The size of the image window remains unchanged. The specified anchor point is the top-left corner of the source rectangle, both coordinates must be positive. The method fails (does nothing and returns null) if the resulting source rectangle does not fit into the image. If successful, the view is modified and the resulting source rectangle is returned. Otherwise null is returned.
      Parameters:
      im - the image, which must be currently open (displayed)
      magnification - the new magnification factor (1.0 = 100%)
      xa - the x-coordinate of the anchor point
      ya - the y-coordinate of the anchor point
      Returns:
      the resulting source rectangle if successful, null otherwise
    • zoomExact

      public static boolean zoomExact(ImagePlus im, double magnification, int marginX, int marginY)
      Resizes the window of the given image to fit an arbitrary, user-specified magnification factor. The resulting window size is limited by the current screen size. The window size is reduced if too large but the given magnification factor remains always unchanged.
      Adapted from https://albert.rierol.net/plugins/Zoom_Exact.java by Albert Cardona @ 2006 General Public License applies.
      Parameters:
      im - the image, which must be currently open (displayed)
      magnification - the new magnification factor (1.0 = 100%)
      marginX - horizontal screen margin
      marginY - vertical screen margin
      Returns:
      true if successful, false otherwise
    • zoomExact

      public static boolean zoomExact(ImagePlus im, double magnification)
      Convenience method for zoomExact(ImagePlus, double, int, int) using default screen margins.
      Parameters:
      im - the image, which must be currently open (displayed)
      magnification - the new magnification factor (1.0 = 100%)
      Returns:
      true if successful, false otherwise
    • getMagnification

      public static double getMagnification(ImagePlus im)
      Returns the current magnification (zoom) factor for the specified ImagePlus instance. Throws an exception if the image is currently not displayed.
      Parameters:
      im - the image, which must be currently open (displayed)
      Returns:
      the magnification factor
    • captureImage

      public static ImagePlus captureImage(ImagePlus im)
      Captures the specified image window and returns it as a new ImagePlus instance. Uses ImageJ's built-in ScreenGrabber plugin.
      Parameters:
      im - the image, which must be currently open (displayed)
      Returns:
      a new image with the grabbed contents