Class IJProcessing

java.lang.Object
qupath.imagej.processing.IJProcessing

public class IJProcessing extends Object
Helper class for working with ImageJ.

This focuses especially on common processing operations involving ImageProcessor, including the creation of labeled images and Rois.

Since:
v0.6.0
  • Field Details

    • CONNECTIVITY_4

      public static int CONNECTIVITY_4
      Constant for 4-connectivity when tracing Rois.
    • CONNECTIVITY_8

      public static int CONNECTIVITY_8
      Constant for 8-connectivity when tracing Rois.
  • Constructor Details

    • IJProcessing

      public IJProcessing()
  • Method Details

    • autoThresholdToRoi

      public static Roi autoThresholdToRoi(ImageProcessor ip, String method)
      Apply an auto-threshold to an image, and generate a Roi from the result.

      The threshold of the image will be set temporarily and then removed afterwards.

      Parameters:
      ip - the input image
      method - a method string, as accepted by ImageProcessor.setAutoThreshold(String)
      Returns:
      the threshold Roi, or null if no thresholded pixels were found
    • autoThresholdToSplitRois

      public static List<Roi> autoThresholdToSplitRois(ImageProcessor ip, String method, int connectivity)
      Apply an auto-threshold to an image, and generate a zero or more Rois from the result based on connected components.

      The threshold of the image will be set temporarily and then removed afterwards.

      Parameters:
      ip - the input image
      method - a method string, as accepted by ImageProcessor.setAutoThreshold(String)
      connectivity - either 4 or 8
      Returns:
      a list containing a Roi for each connected component
    • thresholdToRoi

      public static Roi thresholdToRoi(ImageProcessor ip)
      Create an ImageJ ROI from a thresholded image.

      This makes use of ThresholdToSelection, and returns null if no Roi is found.

      Parameters:
      ip - the image, with min and/or max thresholds already set.
      Returns:
      a Roi generated by applying the threshold, or null if there are no thresholded pixels
    • thresholdToSplitRois

      public static List<Roi> thresholdToSplitRois(ImageProcessor ip, int connectivity)
      Create a list of ImageJ ROIs by tracing connected components in a thresholded image.

      This makes use of ThresholdToSelection, and returns null if no Roi is found.

      Parameters:
      ip - the image, with min and/or max thresholds already set
      connectivity - may be 4 or 8
      Returns:
      a Roi generated by applying the threshold, or null if there are no thresholded pixels
    • labelImage

      public static ImageProcessor labelImage(ImageProcessor ip, int connectivity)
      Create a labeled image using the thresholds set on an ImageProcessor (inclusive).
      Parameters:
      ip - the input image
      connectivity - may be 4 or 8
      Returns:
      labelled image, as a ShortProcessor (if possible) or FloatProcessor (if necessary)
    • labelImage

      public static ImageProcessor labelImage(ImageProcessor ip, int connectivity, DoublePredicate predicate)
      Create a labeled image using the thresholds set on an ImageProcessor.
      Parameters:
      ip - the input image
      connectivity - may be 4 or 8
      predicate - the predicate to determine if a pixel should be labeled based on its value
      Returns:
      labelled image, as a ShortProcessor (if possible) or FloatProcessor (if necessary)
      Since:
      v0.6.0
    • labelsToRoisArray

      public static Roi[] labelsToRoisArray(ImageProcessor ipLabels)
      Create ImageJ Rois from labels in an image.

      Note that this is intended to handle disconnected Rois and Rois that contain holes, such that the Roi contains all pixels with the given label and no other pixels.

      Parameters:
      ipLabels - the labeled image; generally this should be a ByteProcessor or ShortProcessor
      Returns:
      an array of length n; output[i] is the ROI for label i+1, or null if no Roi is found with that label.
    • labelsToRois

      public static List<Roi> labelsToRois(ImageProcessor ipLabels)
      Create ImageJ Rois from labels in an image.

      This is similar to labelsToRoisArray(ImageProcessor) but omits any null Rois. Consequently, when labels can be missing it is not possible to relate the index from the list to the original label.

      Parameters:
      ipLabels - the labeled image; generally this should be a ByteProcessor or ShortProcessor
      Returns:
      a list of Rois that were found
    • wandToRoi

      public static PolygonRoi wandToRoi(Wand wand)
      Convert a traced outline from the ImageJ Wand into a PolygonRoi.
      Parameters:
      wand -
      Returns:
    • createOverlay

      public static Overlay createOverlay(Collection<? extends Roi> rois)
      Create an overlay containing all the Rois in the provided collection.
      Parameters:
      rois -
      Returns:
    • subtract

      public static <T extends ImageProcessor> T subtract(T ip, ImageProcessor... ipOthers)
      Pixelwise subtraction of one or more images from the first image passed as a parameter. The input images are unchanged.
      Parameters:
      ip - the first image
      ipOthers - additional images
      Returns:
      a new image representing the result of the subtraction.
    • add

      public static <T extends ImageProcessor> T add(T ip, ImageProcessor... ipOthers)
      Pixelwise sum of input images. The input images are unchanged.
      Parameters:
      ip - the first image
      ipOthers - additional images
      Returns:
      a new image representing the result of the addition.
    • multiply

      public static <T extends ImageProcessor> T multiply(T ip, ImageProcessor... ipOthers)
      Pixelwise multiplication of the input images. The input images are unchanged.
      Parameters:
      ip - the first image
      ipOthers - additional images
      Returns:
      a new image representing the result of the multiplication.
    • divide

      public static <T extends ImageProcessor> T divide(T ip, ImageProcessor... ipOthers)
      Pixelwise division of the input images. The input images are unchanged.
      Parameters:
      ip - the first image
      ipOthers - additional images
      Returns:
      a new image representing the result of the division.
    • max

      public static <T extends ImageProcessor> T max(T ip, ImageProcessor... ipOthers)
      Pixelwise maximum of the input images. The input images are unchanged.
      Parameters:
      ip - the first image
      ipOthers - additional images
      Returns:
      a new image representing the result of the max operation.
    • min

      public static <T extends ImageProcessor> T min(T ip, ImageProcessor... ipOthers)
      Pixelwise minimum of the input images. The input images are unchanged.
      Parameters:
      ip - the first image
      ipOthers - additional images
      Returns:
      a new image representing the result of the min operation.