Class VolumeFunctions

java.lang.Object
mgui.geometry.volume.VolumeFunctions

public class VolumeFunctions
extends java.lang.Object
Utility class providing various functions for use on volume data (Volume3DInt and its descendants).
Since:
1.0
Version:
1.0
Author:
Andrew Reid
  • Constructor Details

    • VolumeFunctions

      public VolumeFunctions()
  • Method Details

    • getMappedValueByte

      public static byte getMappedValueByte​(Volume3DInt volume, int x, int y, int z)
      Returns the value of voxel [i,j,k] mapped with its colour model, as a byte. Uses the current vertex data column.
      Parameters:
      volume -
      x -
      y -
      z -
      Returns:
    • getMappedValueDouble

      public static double getMappedValueDouble​(Volume3DInt volume, int x, int y, int z)
    • getMaskedImages

      public static java.awt.image.BufferedImage[] getMaskedImages​(Volume3DInt volume)
      Produces a stack of R-planar images from volume, based upon the current data column and its associated colour map. If the volume is currently in composite mode, returns the masked composite images.
      Parameters:
      volume -
      Returns:
    • getMaskedImages

      public static java.awt.image.BufferedImage[] getMaskedImages​(Volume3DInt volume, java.lang.String column)
      Produces a stack of R-planar images from volume, based upon the data in column and its associated colour map.
      Parameters:
      volume -
      Returns:
    • getMaskedCompositeImages

      public static java.awt.image.BufferedImage[] getMaskedCompositeImages​(Volume3DInt volume)
      Returns a set of composite images, comprised of all data columns specified for the composite, with alpha values and ordering as specified in the Volume3DInt object. Images will be masked by the volume's current set of masks, if any are set.
      Parameters:
      volume -
      Returns:
    • getMaskedCompositeRSliceImage

      public static java.awt.image.BufferedImage getMaskedCompositeRSliceImage​(Volume3DInt volume, int r, boolean[][][] mask)
      Returns a composite image from an R-slice plane, volume, and set of colour models and composite alphas. Columns render from bottom to top. Image will be masked by mask.
      Parameters:
      volume -
      models -
      alphas -
    • getCompositeRSliceImage

      public static java.awt.image.BufferedImage getCompositeRSliceImage​(Volume3DInt volume, int r, java.util.ArrayList<java.lang.String> ordered_columns, java.util.ArrayList<WindowedColourModel> colour_models, java.util.ArrayList<java.lang.Double> alphas)
      Returns a composite image from an R-slice plane, volume, and set of colour models and composite alphas. Columns render from bottom to top.
      Parameters:
      volume -
      models -
      alphas -
    • getCompositeRSliceImage

      public static java.awt.image.BufferedImage getCompositeRSliceImage​(Volume3DInt volume, int r, java.util.ArrayList<java.lang.String> ordered_columns, java.util.ArrayList<WindowedColourModel> colour_models, java.util.ArrayList<java.lang.Double> alphas, java.util.ArrayList<java.lang.Boolean> include)
      Returns a composite image from an R-slice plane, volume, and set of colour models and composite alphas. Columns render from bottom to top.
      Parameters:
      volume -
      models -
      alphas -
    • getCompositeSliceImage

      public static java.awt.image.BufferedImage getCompositeSliceImage​(Volume3DInt volume, int orientation, int section)
      Returns a composite image from an S,T, or R-slice plane, determined by section, and volume. Columns render from bottom to top.
      Parameters:
      volume -
      orientation - - 0 = S, 1 = T, 2 = R
      section - specifies which section to render
    • getCompositeSliceImage

      public static java.awt.image.BufferedImage getCompositeSliceImage​(Volume3DInt volume, int orientation, int section, java.util.ArrayList<java.lang.String> ordered_columns, java.util.ArrayList<WindowedColourModel> colour_models, java.util.ArrayList<java.lang.Double> alphas, java.util.ArrayList<java.lang.Boolean> include)
      Returns a composite image from an image plane, volume, determined by orientation, and set of colour models and composite alphas. Columns render from bottom to top.
      Parameters:
      volume -
      models -
      alphas -
      orientation - - 0 = S, 1 = T, 3 = R
      section - specifies which section to render
    • getCompositeRSliceImage

      public static java.awt.image.BufferedImage getCompositeRSliceImage​(Volume3DInt volume, int r)
      Returns a composite image from an R-slice plane and a volume
      Parameters:
      volume -
      Returns:
    • getColourModel

      public static WindowedColourModel getColourModel()
    • getColourModel

      public static WindowedColourModel getColourModel​(int transferType)
    • getColourModel

      public static WindowedColourModel getColourModel​(int transferType, ColourMap cmap)
    • getColourModel

      public static WindowedColourModel getColourModel​(int transferType, ColourMap cmap, boolean setAlpha)
    • getColourModel

      public static WindowedColourModel getColourModel​(int transferType, ColourMap cmap, double scale, double intercept, double window_width, double window_mid, boolean setAlphaFromIntensity)
    • getIntersectionImage

      public static Volume2DInt getIntersectionImage​(Volume3DInt volume, Plane3D plane, boolean setAlpha)
      Returns an Volume2DInt object representing the intersection of the given 3D volume with plane. Returns null if the volume does not intersect the plane.
      Parameters:
      volume -
      plane -
      Returns:
      Volume2DInt object, in plane coordinates relative to its reference point
    • getIntersectionImage

      public static Volume2DInt getIntersectionImage​(Volume3DInt volume, Plane3D plane, boolean setAlpha, org.jogamp.vecmath.Matrix4d transform)
      Returns an Volume2DInt object representing the intersection of the given 3D volume with plane. Returns null if the volume does not intersect the plane.
      Parameters:
      volume -
      plane -
      Returns:
      Volume2DInt object, in plane coordinates relative to its reference point
    • getIntersectionCompositeImage

      public static Volume2DInt getIntersectionCompositeImage​(Volume3DInt volume, Plane3D plane, boolean setAlpha)
      Returns an Volume2DInt object representing the intersection of the given 3D composite volume with plane. Returns null if the volume does not intersect the plane.
      Parameters:
      volume -
      plane -
      Returns:
      Volume2DInt object, in plane coordinates relative to its reference point
    • getInvertedVolume

      public static Volume3DInt getInvertedVolume​(Volume3DInt volume)
      Returns a Grid3D object whose data is the inverse of grid.
      Parameters:
      grid -
      column -
      Returns:
    • getInvertedVolume

      public static Volume3DInt getInvertedVolume​(Volume3DInt volume, java.lang.String column)
      Returns a Grid3D object whose data is the inverse of grid.
      Parameters:
      grid -
      column -
      Returns:
    • getInvertedVolume

      public static Volume3DInt getInvertedVolume​(Volume3DInt volume, java.lang.String column, ProgressUpdater progress)
      Returns a Grid3D object whose data is the inverse of grid.
      Parameters:
      volume - - Volume to invert
      column - - Column to invert
      Returns:
    • smoothVolumeGaussian

      public static boolean smoothVolumeGaussian​(Volume3DInt volume, java.lang.String source_column, java.lang.String target_column, double fwhm, double max_radius)
      Geometrically smooths values from source_column in volume with an isotropic Gaussian smoothing kernel with a full-width-at-half-maximum of fwhm. Writes the results to target_column. If target_column doesn't exist, it will be created with the same data type as source_column. If it exists, it will maintain its current data type and its values will be overwritten. target_column can be the same as source_column.
      Parameters:
      volume -
      source_column -
      target_column -
      fwhm - Full-width at half maximum of Gaussian kernel
      max_radius - Maximum radius at which to obtain values for smoothing. Values of 0 or less specify an infinite radius (not recommended)
      Returns:
    • smoothVolumeGaussian

      public static boolean smoothVolumeGaussian​(Volume3DInt volume, java.lang.String source_column, java.lang.String target_column, double fwhm, double max_radius, ProgressUpdater progress, double default_value)
      Geometrically smooths values from source_column in volume with an isotropic Gaussian smoothing kernel with a full-width-at-half-maximum of fwhm. Writes the results to target_column. If target_column doesn't exist, it will be created with the same data type as source_column. If it exists, it will maintain its current data type and its values will be overwritten. target_column can be the same as source_column.
      Parameters:
      volume -
      source_column -
      target_column -
      fwhm -
      max_radius -
      Returns:
    • smoothVolumeGaussianBlocking

      public static boolean smoothVolumeGaussianBlocking​(Volume3DInt volume, java.lang.String source_column, java.lang.String target_column, double fwhm, double max_radius, ProgressUpdater progress, double default_value)
      Geometrically smooths values from source_column in volume with an isotropic Gaussian smoothing kernel with a full-width-at-half-maximum of fwhm. Writes the results to target_column. If target_column doesn't exist, it will be created with the same data type as source_column. If it exists, it will maintain its current data type and its values will be overwritten. target_column can be the same as source_column.
      Parameters:
      volume -
      source_column -
      target_column -
      fwhm -
      max_radius -
      Returns:
    • getGaussianSmoothedValue

      public static double getGaussianSmoothedValue​(Volume3DInt volume, int[] voxel, int channel, org.jogamp.vecmath.Vector3f normal, float sigma_normal, float sigma_tangent, float cutoff)
      Computes a value for voxel which is the weighted average of a Gaussian sampling of its neighbouring voxels, where the Gaussian is defined by a normal vector, its corresponding plane, and the sigma parameters sigma_normal and sigma_tangent.
      Parameters:
      grid - grid from which to compute value
      voxel - voxel for which to compute a value
      normal - normal direction of Gaussian distribution
      sigma_normal - sigma of Gaussian in normal direction
      sigma_tangent - sigma of Gaussian in tangent direction
      cutoff - value at which to bound search space, in multiples of sigma
      Returns:
    • performOperationBlocking

      public static Volume3DInt performOperationBlocking​(Volume3DInt volume1, Volume3DInt volume2, VolumeFunctions.Operation op, ProgressUpdater progress)
      Performs the specified operation on the two volumes, and returns the result as a new Grid3D instance. Uses the current vertex data columns.
      Parameters:
      grid1 -
      grid2 -
      op -
      Returns:
    • performOperationBlocking

      public static Volume3DInt performOperationBlocking​(Volume3DInt volume, java.lang.Double value, VolumeFunctions.Operation op, ProgressUpdater progress)
      Performs the specified operation on one grid and a constant value, and returns and new volume.
      Parameters:
      grid -
      value -
      op -
      Returns:
    • applyMask

      public static void applyMask​(org.jogamp.java3d.ImageComponent3D iComp, int index, int x, int y, int width, int height, VolumeMaskOptions_old params)
      Applies a voxel mask to an ImageComponent3D object, using the parameters in params.
      Parameters:
      grid - Grid3D object upon which to apply mask
      params - specifies the parameters describing the mask
    • getMask

      public static boolean[][][] getMask​(Grid3D grid, VolumeMaskOptions_old params)
      Applies a voxel mask to an ImageComponent3D object, using the parameters in params.
      Parameters:
      grid - Grid3D object upon which to apply mask
      params - specifies the parameters describing the mask
    • getOverlayImage

      public static java.awt.image.BufferedImage getOverlayImage​(java.util.ArrayList<java.awt.image.BufferedImage> images, WindowedColourModel colour_model)
      Compiles an overlay from the list of images by adding them one-by-one starting from the last element (since this will be on the bottom).
      Parameters:
      images -
      Returns:
      the overlaid image
    • getIntMaskedByValue

      public static Volume3DInt getIntMaskedByValue​(Volume3DInt volume, double comp_value)
      Returns an integer mask of grid, where a voxel has value = 1, when grid(i,j,k,v) == comp_value (within tolerance), and 0 otherwise.
      Parameters:
      grid -
      value -
      Returns:
    • getIntMaskedByValue

      public static Volume3DInt getIntMaskedByValue​(Volume3DInt volume, double comp_value, boolean round)
      Returns an integer mask of grid, where a voxel has value = 1, when grid(i,j,k,v) == comp_value (within tolerance), and 0 otherwise.
      Parameters:
      grid -
      value -
      round - If true, rounds the grid value before comparison
      Returns:
    • isInMask

      public static boolean isInMask​(int i, int j, int k, VolumeMaskOptions_old params)
      Determines whether the voxel at i, j, k is in the mask specified by params.
      Parameters:
      i -
      j -
      k -
      params -
      Returns:
      true if voxel is in mask shape, false otherwise
    • applyRotation

      public static Volume3DInt applyRotation​(VolumeFunctions.VolumeAxis axis, VolumeFunctions.VolumeRotationAngle angle, Volume3DInt volume, InterfaceProgressBar progress_bar)
      Rotates a Grid3D about one of its basis vectors (axes), either 90, 180, or 270 degrees, resizes the relevant dimensions, and returns the new grid.

      Note: only operates currently on the default channel.

      TODO: implement this on generic channel

      Parameters:
      axis - The spatial axis about which to rotate (one of S, T, or R).
    • applyRotationBlocking

      public static Volume3DInt applyRotationBlocking​(VolumeFunctions.VolumeAxis axis, VolumeFunctions.VolumeRotationAngle angle, Volume3DInt volume)
      Rotates a Grid3D about one of its basis vectors (axes), either 90, 180, or 270 degrees, resizes the relevant dimensions, and returns the new grid.

      Note: only operates currently on the default channel.

      TODO: implement this on generic channel

      Parameters:
      axis - The spatial axis about which to rotate (one of S, T, or R).
      angle - The angle to rotate (one of 90, 180, 270)
      grid - The grid to rotate
    • applyRotationBlocking

      public static Volume3DInt applyRotationBlocking​(VolumeFunctions.VolumeAxis axis, VolumeFunctions.VolumeRotationAngle angle, Volume3DInt volume, InterfaceProgressBar progress_bar)
      Rotates a Volume3DInt about one of its basis vectors (axes), either 90, 180, or 270 degrees, resizes the relevant dimensions, and returns the new grid.

      Note: only operates currently on the default channel.

      TODO: implement this on generic channel

      Parameters:
      axis - The spatial axis about which to rotate (one of S, T, or R).
      angle - The angle to rotate (one of 90, 180, 270)
      grid - The grid to rotate
      progress_bar - The progress bar to track progress; can be null.
    • getRotatedDims

      protected static int[] getRotatedDims​(int[] dims, VolumeFunctions.VolumeAxis axis, VolumeFunctions.VolumeRotationAngle angle)
    • getRotatedBox

      protected static Box3D getRotatedBox​(Box3D box, VolumeFunctions.VolumeAxis axis, VolumeFunctions.VolumeRotationAngle angle)
    • rotateDims

      public static int[] rotateDims​(int[] dims, int axis, int rotation)
      Returns new dimensions for a rotation about a basis axis.
    • rotate

      public static int[] rotate​(int[] coords, int[] dims, int axis, int rotation)
    • powerOfTwo

      public static int powerOfTwo​(int value)
    • getByteValue

      public static byte getByteValue​(double d)
    • intToByte

      public static byte intToByte​(int i)
    • getDoubleValue

      public static double getDoubleValue​(byte b)
    • byteToInt

      public static int byteToInt​(byte b)
    • getHistogram

      public static Histogram getHistogram​(Volume3DInt volume, int bins)
      Returns a histogram for the current column of volume.
      Parameters:
      volume -
      bins -
      Returns:
    • getHistogram

      public static Histogram getHistogram​(Volume3DInt volume, int t, int bins, double min, double max)
      Returns a histogram for the current column of volume.
      Parameters:
      volume -
      t -
      bins -
      min -
      max -
      Returns:
    • getHistogram

      public static Histogram getHistogram​(Volume3DInt volume, java.lang.String column, int t, int bins, double min, double max)
      Returns a histogram for the vertex column column of volume.
      Parameters:
      volume - The volume for which to produce a histogram
      column - The name of the column for which to produce a histogram
      t - The temporal index (0 for 3D volumes)
      bins - The number of bins in the histogram
      min - The minimum of the range to use
      max - The maximum of the range to use
      Returns:
    • mapVolumeToVolumeEV

      public static void mapVolumeToVolumeEV​(Volume3DInt volume_source, Volume3DInt volume_target, java.lang.String column_source, java.lang.String column_target)
      Maps volume_source to volume_target, using the enclosing voxel to assign the value. If no enclosing voxel exists, assigns a value of 0.
      Parameters:
      volume_source -
      volume_target -
      column_source -
      column_target -
    • mapVolumeToVolumeEV

      public static void mapVolumeToVolumeEV​(Volume3DInt volume_source, Volume3DInt volume_target, java.lang.String column_source, java.lang.String column_target, ProgressUpdater progress)
      Maps volume_source to volume_target, using the enclosing voxel to assign the value. If no enclosing voxel exists, assigns a value of 0.
      Parameters:
      volume_source -
      volume_target -
      column_source -
      column_target -
      progress -
    • mapVolumeToVolumeEV

      public static boolean mapVolumeToVolumeEV​(Volume3DInt volume_source, Volume3DInt volume_target, java.lang.String column_source, java.lang.String column_target, double default_value, ProgressUpdater progress)
      Maps volume_source to volume_target, using the enclosing voxel to assign the value. If no enclosing voxel exists, assigns default_value. This method is equivalent to "nearest-neighbour" interpolation.
      Parameters:
      volume_source -
      volume_target -
      column_source -
      column_target -
      default_value -
      Returns:
    • mapVolumeToVolumeEVBlocking

      protected static boolean mapVolumeToVolumeEVBlocking​(Volume3DInt volume_source, Volume3DInt volume_target, java.lang.String column_source, java.lang.String column_target, double default_value, ProgressUpdater progress)
      Maps volume_source to volume_target, using the enclosing voxel to assign the value. If no enclosing voxel exists, assigns default_value.
      Parameters:
      volume_source -
      volume_target -
      column_source -
      column_target -
      default_value -
      Returns:
    • mapVolumeToVolumeInterp

      public static void mapVolumeToVolumeInterp​(Volume3DInt volume_source, Volume3DInt volume_target, java.lang.String column_source, java.lang.String column_target, java.lang.String method, java.util.ArrayList<java.lang.Object> parameters)
      Maps volume_source to volume_target, using interpolation from all overlapping voxels to assign the value. The method must be one of:
      • nearest neighbour
      • tri-linear
      • tri-cubic
      Parameters:
      volume_source -
      volume_target -
      column_source -
      column_target -
      method -
    • mapVolumeToVolumeInterp

      public static void mapVolumeToVolumeInterp​(Volume3DInt volume_source, Volume3DInt volume_target, java.lang.String column_source, java.lang.String column_target, java.lang.String method, java.util.ArrayList<java.lang.Object> parameters, ProgressUpdater progress)
      Maps volume_source to volume_target, using interpolation from all overlapping voxels to assign the value. The method must be one of:
      • nearest neighbour
      • tri-linear
      • tri-cubic
      Parameters:
      volume_source -
      volume_target -
      column_source -
      column_target -
      method -
      progress -
    • mapVolumeToVolumeInterp

      public static boolean mapVolumeToVolumeInterp​(Volume3DInt volume_source, Volume3DInt volume_target, java.lang.String column_source, java.lang.String column_target, java.lang.String method, java.util.ArrayList<java.lang.Object> parameters, double default_value, ProgressUpdater progress)
      Maps volume_source to volume_target, using interpolation from all overlapping voxels to assign the value. The method must be one of:
      • nearest neighbour
      • tri-linear
      • tri-cubic
      Parameters:
      volume_source -
      volume_target -
      column_source -
      column_target -
      method -
      default_value -
      Returns:
    • mapVolumeToVolumeInterpBlocking

      protected static boolean mapVolumeToVolumeInterpBlocking​(Volume3DInt volume_source, Volume3DInt volume_target, java.lang.String column_source, java.lang.String column_target, java.lang.String method, java.util.ArrayList<java.lang.Object> parameters, double default_value, ProgressUpdater progress)
      Maps volume_source to volume_target, using interpolation from all overlapping voxels to assign the value. The method must be one of:
      • nearest neighbour
      • tri-linear
      • tri-cubic
      Parameters:
      volume_source -
      volume_target -
      column_source -
      column_target -
      default_value -
      Returns:
    • getVolumeSpaceMidPoint

      public static org.jogamp.vecmath.Point3f getVolumeSpaceMidPoint​(Grid3D grid, int voxel)
      Returns the midpoint of this voxel in grid's coordinate space.
      Parameters:
      grid -
      voxel -
      Returns:
    • getVolumeSpaceMidPoint

      public static org.jogamp.vecmath.Point3f getVolumeSpaceMidPoint​(Grid3D grid, int[] voxel)
      Returns the midpoint of this voxel in grid's coordinate space.
      Parameters:
      grid -
      voxel -
      Returns:
    • getTrilinearVoxels

      protected static int[] getTrilinearVoxels​(Grid3D grid, org.jogamp.vecmath.Point3f point)
      Returns the trilinear neighbourhood of point, which includes the 8 voxels surrounding and enclosing it. Returns a list of 8 absolute indices, where a negative value indicate the neighbouring voxel is outside the bounds.

      Voxels are arranged as:
      0 -> [0 0 0]
      1 -> [1 1 1]

      Parameters:
      grid -
      point -
      Returns:
    • getNeighbouringVoxels

      public static int[] getNeighbouringVoxels​(Grid3D grid, org.jogamp.vecmath.Point3f point)
      Returns the indices off all first neighbours of the voxel enclosing point, plus that voxel.
      Parameters:
      grid -
      point -
      Returns:
    • getNeighbouringVoxels

      public static int[] getNeighbouringVoxels​(Grid3D grid, org.jogamp.vecmath.Point3f point, int n)
      Returns the indices off all first neighbours of the voxel enclosing point, plus that voxel.
      Parameters:
      grid -
      point -
      Returns:
    • getNeighbouringVoxels

      public static int[] getNeighbouringVoxels​(Grid3D grid, int[] voxel, int n)
      Returns the indices off all first neighbours of voxel, plus voxel.
      Parameters:
      grid -
      point -
      Returns:
    • getBlobsFromVolume

      public static boolean getBlobsFromVolume​(Volume3DInt volume, java.lang.String source_column, java.lang.String target_column, ProgressUpdater progress, int min_blob, double threshold)
      Finds connected blobs in a thresholded volume.
      Parameters:
      volume - Volume to search
      column - Column to search
      min_blob - Minimum size (in voxels) at which to include a blob
      threshold - Value to threshold the volume
      Returns:
    • getBlobsFromVolumeBlocking

      public static java.util.ArrayList<MguiNumber> getBlobsFromVolumeBlocking​(Volume3DInt volume, java.lang.String column, ProgressUpdater progress, int min_blob, double threshold)
      Finds connected blobs in a thresholded volume.
      Parameters:
      volume - Volume to search
      column - Column to search
      min_blob - Minimum size (in voxels) at which to include a blob
      threshold - Value to threshold the volume
      Returns:
    • findMaximaBlocking

      public static PointSet3DInt findMaximaBlocking​(Volume3DInt volume, java.lang.String source_column, java.lang.String mask_column, java.lang.String label_column)
      Returns a global maximum for a given volume or within a given mask, or mulitple maxima from a set of masks, specified by mask_column. Will optionally add labels based on label_column.
      Parameters:
      volume -
      source_column -
      mask_column -
      max_point -
      label_column -
      Returns:
    • getRoiCentroidsBlocking

      public static PointSet3DInt getRoiCentroidsBlocking​(Volume3DInt volume, java.lang.String source_column, int[] value_range, int min_size, boolean map_values, java.lang.String label_column, ProgressUpdater progress)
      Finds the centroids for all ROIs (identified as voxels with the same value). Optionally maps values of the source column to the point set.
      Parameters:
      volume - Volume containing ROIs
      source_column - Column identifying the ROIs; should be of type INTEGER, otherwise values will be rounded
      value_range - The range of values outside which to exclude ROIs
      min_size - Minimal size of an ROI (in voxels) at which to generate a centroid
      map_values - If true, maps the value of the ROI index to the point set
      Returns: