Class ImageUtils

java.lang.Object
inra.ijpb.data.image.ImageUtils

public class ImageUtils
extends java.lang.Object
A collection of static utility methods for processing 2D or 3D images.
Author:
dlegland
  • Method Summary

    Modifier and Type Method Description
    static ij.process.ByteProcessor createByteProcessor​(int[][] data)
    Creates a new ByteProcessor initialized with the content of the input array.
    static ij.process.FloatProcessor createFloatProcessor​(float[][] data)
    Creates a new FloatProcessor initialized with the content of the input array.
    static ij.process.ImageProcessor createImageProcessor​(int width, int height, int bitDepth)
    Creates a new ImageProcessor from image dimensions and bit depth.
    static ij.process.ShortProcessor createShortProcessor​(int[][] data)
    Creates a new ShortProcessor initialized with the content of the input array.
    static void fillRect​(ij.process.ImageProcessor image, int x0, int y0, int w, int h, double value)
    Fills a rectangle within the image with the specified value.
    static void fillRect3d​(ij.ImageStack image, int x0, int y0, int z0, int w, int h, int d, double value)
    Fills a 3D rectangle within the image with the specified value.
    static double findMaxValue​(ij.ImagePlus imagePlus)
    Computes maximum value within the input image.
    static double findMaxValue​(ij.ImageStack image)
    Computes maximum value in the input 3D image.
    static double findMaxValue​(ij.process.ImageProcessor image)
    Computes maximum value within the input 2D image.
    static boolean isColorImage​(ij.ImagePlus imagePlus)
    Checks if the specified image is a color image.
    static boolean isSameSize​(ij.ImagePlus image1, ij.ImagePlus image2)
    Checks if the two input images have the same dimensionality and the same size in each direction.
    static boolean isSameSize​(ij.ImageStack image1, ij.ImageStack image2)
    Checks if the two input 3D images have the same size in each direction.
    static boolean isSameSize​(ij.process.ImageProcessor image1, ij.process.ImageProcessor image2)
    Checks if the two input images have the same size in each direction.
    static boolean isSameType​(ij.ImagePlus image1, ij.ImagePlus image2)
    Checks if the two input images have the same data type.
    static boolean isSameType​(ij.ImageStack image1, ij.ImageStack image2)
    Checks if the two input 3D images have the same data type.
    static boolean isSameType​(ij.process.ImageProcessor image1, ij.process.ImageProcessor image2)
    Checks if the two input images have the same data type.
    static void print​(ij.ImageStack image)
    Prints the content of the given 3D image on the console.
    static void print​(ij.process.ImageProcessor image)
    Prints the content of the given ImageProcessor on the console.
    static void replaceValue​(ij.ImagePlus image, double initialValue, double finalValue)
    Replaces the elements of an image with a given value by a new value.
    static void replaceValue​(ij.ImageStack image, double initialValue, double finalValue)
    Replaces the elements of a 3D image with a given value by a new value.
    static void replaceValue​(ij.process.ImageProcessor image, double initialValue, double finalValue)
    Replaces the elements of a 2D image with a given value by a new value.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • createImageProcessor

      public static final ij.process.ImageProcessor createImageProcessor​(int width, int height, int bitDepth)
      Creates a new ImageProcessor from image dimensions and bit depth.
      Parameters:
      width - the width of the new image
      height - the height of the new image
      bitDepth - the bit-depth of the new image (must be one of 8, 16, 24, or 32).
      Returns:
      the new image
    • createByteProcessor

      public static final ij.process.ByteProcessor createByteProcessor​(int[][] data)
      Creates a new ByteProcessor initialized with the content of the input array.
      
          ImageProcessor image = ImageUtils.createByteProcessor(new int[][] {
              { 0,  0,  0,  0,  0},  
              { 0, 20, 20, 20,  0},  
              { 0, 20, 50, 20,  0},  
              { 0, 20, 20, 20,  0},  
              { 0,  0,  0,  0,  0},  
          });
       
       
      Parameters:
      data - the array containing image data, as integer values
      Returns:
      a new ByteProcessor initialized with data array.
    • createShortProcessor

      public static final ij.process.ShortProcessor createShortProcessor​(int[][] data)
      Creates a new ShortProcessor initialized with the content of the input array.
      
          ImageProcessor image = ImageUtils.createShortProcessor(new int[][] {
              { 0,  0,  0,  0,  0},  
              { 0, 20, 20, 20,  0},  
              { 0, 20, 50, 20,  0},  
              { 0, 20, 20, 20,  0},  
              { 0,  0,  0,  0,  0},  
          });
       
       
      Parameters:
      data - the array containing image data, as integer values
      Returns:
      a new ShortProcessor initialized with data array.
    • createFloatProcessor

      public static final ij.process.FloatProcessor createFloatProcessor​(float[][] data)
      Creates a new FloatProcessor initialized with the content of the input array.
      
          ImageProcessor image = ImageUtils.createFloatProcessor(new float[][] {
              { 0,  0,  0,  0,  0},  
              { 0, 20, 20, 20,  0},  
              { 0, 20, 50, 20,  0},  
              { 0, 20, 20, 20,  0},  
              { 0,  0,  0,  0,  0},  
          });
       
       
      Parameters:
      data - the array containing image data, as float values
      Returns:
      a new FloatProcessor initialized with data array.
    • isColorImage

      public static final boolean isColorImage​(ij.ImagePlus imagePlus)
      Checks if the specified image is a color image.
      Parameters:
      imagePlus - the instance of ImagePlus to check
      Returns:
      true if the type is COLOR_256 or COLOR_RGB.
    • isSameSize

      public static final boolean isSameSize​(ij.ImagePlus image1, ij.ImagePlus image2)
      Checks if the two input images have the same dimensionality and the same size in each direction.
      Parameters:
      image1 - the first image
      image2 - the second image
      Returns:
      true if both images have same dimensionality and same size.
    • isSameSize

      public static final boolean isSameSize​(ij.process.ImageProcessor image1, ij.process.ImageProcessor image2)
      Checks if the two input images have the same size in each direction.
      Parameters:
      image1 - the first image
      image2 - the second image
      Returns:
      true if both images have same width and height, and false otherwise.
    • isSameSize

      public static final boolean isSameSize​(ij.ImageStack image1, ij.ImageStack image2)
      Checks if the two input 3D images have the same size in each direction.
      Parameters:
      image1 - the first image
      image2 - the second image
      Returns:
      true if both images have same width, height and number of slices, and false otherwise.
    • isSameType

      public static final boolean isSameType​(ij.ImagePlus image1, ij.ImagePlus image2)
      Checks if the two input images have the same data type.
      Parameters:
      image1 - the first image
      image2 - the second image
      Returns:
      true if both images have the same data type, given by the bit depth.
    • isSameType

      public static final boolean isSameType​(ij.process.ImageProcessor image1, ij.process.ImageProcessor image2)
      Checks if the two input images have the same data type.
      Parameters:
      image1 - the first image
      image2 - the second image
      Returns:
      true if both images have the same data type, given by the bit depth.
    • isSameType

      public static final boolean isSameType​(ij.ImageStack image1, ij.ImageStack image2)
      Checks if the two input 3D images have the same data type.
      Parameters:
      image1 - the first image
      image2 - the second image
      Returns:
      true if both images have the same data type, given by the bit depth.
    • fillRect

      public static final void fillRect​(ij.process.ImageProcessor image, int x0, int y0, int w, int h, double value)
      Fills a rectangle within the image with the specified value. This will replace by the specified value all the pixels within image that are located:
      • between x0 (inclusive) and x0+width-1 (inclusive)
      • between y0 (inclusive) and y0+height-1 (inclusive)
      Parameters:
      image - the image to process.
      x0 - the x-coordinate of the left corner of the rectangle to fill
      y0 - the y-coordinate of the top corner of the rectangle to fill
      w - the width of the rectangle to fill, in pixels
      h - the height of the rectangle to fill, in pixels
      value - the value to fill the rectangle with
    • fillRect3d

      public static final void fillRect3d​(ij.ImageStack image, int x0, int y0, int z0, int w, int h, int d, double value)
      Fills a 3D rectangle within the image with the specified value. This will replace by the specified value all the pixels within image that are located:
      • between x0 (inclusive) and x0+width-1 (inclusive)
      • between y0 (inclusive) and y0+height-1 (inclusive)
      • between z0 (inclusive) and z0+depth-1 (inclusive)
      Parameters:
      image - the image to process.
      x0 - the x-coordinate of the left corner of the rectangle to fill
      y0 - the y-coordinate of the top corner of the rectangle to fill
      z0 - the z-coordinate of the front corner of the rectangle to fill
      w - the width of the rectangle to fill, in voxels
      h - the height of the rectangle to fill, in voxels
      d - the depth of the rectangle to fill, in voxels
      value - the value to fill the 3D rectangle with
    • findMaxValue

      public static final double findMaxValue​(ij.ImagePlus imagePlus)
      Computes maximum value within the input image.
      Parameters:
      imagePlus - the image the analyze
      Returns:
      the maximum value within the image, as a double.
    • findMaxValue

      public static final double findMaxValue​(ij.process.ImageProcessor image)
      Computes maximum value within the input 2D image. This method may be used to compute display range of result ImagePlus.
      Parameters:
      image - the image the analyze
      Returns:
      the maximum value within the image, as a double.
    • findMaxValue

      public static final double findMaxValue​(ij.ImageStack image)
      Computes maximum value in the input 3D image. This method may be used to compute display range of result ImagePlus.
      Parameters:
      image - the 3D image the analyze
      Returns:
      the maximum value within the image, as a double.
    • replaceValue

      public static final void replaceValue​(ij.ImagePlus image, double initialValue, double finalValue)
      Replaces the elements of an image with a given value by a new value.
      Parameters:
      image - the image to process
      initialValue - the value of the elements to replace
      finalValue - the new value of the elements
    • replaceValue

      public static final void replaceValue​(ij.process.ImageProcessor image, double initialValue, double finalValue)
      Replaces the elements of a 2D image with a given value by a new value.
      Parameters:
      image - the 3D image to process
      initialValue - the value of the elements to replace
      finalValue - the new value of the elements
    • replaceValue

      public static final void replaceValue​(ij.ImageStack image, double initialValue, double finalValue)
      Replaces the elements of a 3D image with a given value by a new value.
      Parameters:
      image - the 3D image to process
      initialValue - the value of the elements to replace
      finalValue - the new value of the elements
    • print

      public static final void print​(ij.process.ImageProcessor image)
      Prints the content of the given ImageProcessor on the console. This can be used for debugging (small) images.
      Parameters:
      image - the image to display on the console
    • print

      public static final void print​(ij.ImageStack image)
      Prints the content of the given 3D image on the console. This can be used for debugging (small) images.
      Parameters:
      image - the 3D image to display on the console