Class AlgorithmSubsample

java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.utilities.AlgorithmSubsample
All Implemented Interfaces:
ActionListener, WindowListener, Runnable, EventListener

public class AlgorithmSubsample extends AlgorithmBase
Takes in an image and subsamples it to a new set of dimensions. The subsample image is a Gaussian weighted average of neighboring pixels (voxels) of the original image. For 4D images only the first 3 dimensions are subsampled
Author:
Evan McCreedy
  • Field Details

    • posRatios

      private double[] posRatios
      Ratios used to translate points in the result image to points in the source image.
    • processIndep

      private boolean processIndep
      DOCUMENT ME!
    • resultExtents

      private int[] resultExtents
      Extents the resultImage should have.
    • resultImage

      private ModelImage resultImage
      Result image.
    • paddedImage

      private ModelImage paddedImage
      Padded image.
    • sigmas

      private float[] sigmas
      Std deviation of the Gaussian function.
    • srcImage

      private ModelImage srcImage
      Image to subsample from.
    • transformVOI

      private boolean transformVOI
      DOCUMENT ME!
    • transMatrix

      private TransMatrix transMatrix
      DOCUMENT ME!
    • trilinearFlag

      private boolean trilinearFlag
      Whether to perform trilinear filtering when getting intensities of points on the source image.
  • Constructor Details

    • AlgorithmSubsample

      public AlgorithmSubsample(ModelImage src, ModelImage result, int[] newExtents, int[] padExtents, float[] _sigmas, boolean indep, boolean transformVOI, TransMatrix transMatrix, boolean doPad)
      Setup for a later subsampling of an image.
      Parameters:
      src - image to be subsampled
      result - image created by subsampling
      newExtents - dimensions of the result image to be sampled into
      _sigmas - x, y, and z scales for the gaussian function
      indep - process slices independently (cannot change the z dimension)
      transformVOI - if true transform the VOIs
      transMatrix - transformation matrix
  • Method Details

    • finalize

      public void finalize()
      Prepares this class for destruction.
      Overrides:
      finalize in class AlgorithmBase
    • getResultImage

      public ModelImage getResultImage()
      Return the result image (or null if not created yet).
      Returns:
      the subsampled image
    • runAlgorithm

      public void runAlgorithm()
      Subsample the image.
      Specified by:
      runAlgorithm in class AlgorithmBase
    • computeGaussian2D

      private double computeGaussian2D(double locX, double locY, double sigmaX, double sigmaY)
      Compute the value of the 2D gaussian at a point.
      Parameters:
      locX - x location of the value to compute
      locY - y location of the value to compute
      sigmaX - standard deviation of the guassian in the x dimension
      sigmaY - standard deviation of the guassian in the y dimension
      Returns:
      the value of the 2D gaussian at the given point
    • computeGaussian3D

      private double computeGaussian3D(double locX, double locY, double locZ, double sigmaX, double sigmaY, double sigmaZ)
      Computes the gaussian weights for a particular point. Written by Paul Hemler in AlgorithmVesselSegmenation.
      Parameters:
      locX - distance to go in the x dir from the point
      locY - distance to go in the y dir from the point
      locZ - distance to go in the z dir from the point
      sigmaX - stddev of the gaussian function in the x dir
      sigmaY - stddev of the gaussian function in the y dir
      sigmaZ - stddev of the gaussian function in the z dir
      Returns:
      the gaussian weight coeff.
    • computeRatios

      private void computeRatios()
      Computes the image scaling ratios.
    • getNearestNeighborPos2D

      private float[] getNearestNeighborPos2D(float x, float y)
      Translates a point from the result image to the source image.
      Parameters:
      x - x coordinate of point to be translated
      y - y coordinate of point to be translated
      Returns:
      the translated point on the source image
    • getNearestNeighborPos3D

      private float[] getNearestNeighborPos3D(float x, float y, float z)
      Translates a point from the result image to the source image.
      Parameters:
      x - x coordinate of point to be translated
      y - y coordinate of point to be translated
      z - z coordinate of point to be translated
      Returns:
      the translated point on the source image
    • getTriLinearVal3D

      private float getTriLinearVal3D(float x, float y, float z, int channelIndex, ModelSimpleImage src)
      Version of get that performs tri-linear interpoloation. Note: does NOT perform bounds checking.
      Parameters:
      x - x coordinate
      y - y coordinate
      z - z coordinate
      channelIndex - color channel
      src - image to get intensity value from
      Returns:
      the tri-linear interpolated value
    • getTriLinearVal3D

      private float getTriLinearVal3D(float x, float y, float z, int t, int channelIndex, ModelSimpleImage src)
      Version of get that performs tri-linear interpoloation. Note: does NOT perform bounds checking.
      Parameters:
      x - x coordinate
      y - y coordinate
      z - z coordinate
      t - t coordinate
      channelIndex - color channel
      src - image to get intensity value from
      Returns:
      the tri-linear interpolated value
    • getValue2D

      private float getValue2D(float x, float y, float z, int channelIndex, ModelSimpleImage src)
      Get the value of a 2D point.
      Parameters:
      x - x coordinate
      y - y coordinate
      z - z coordinate (0 if really 2D)
      channelIndex - color channel
      src - image to sample from
      Returns:
      the point's value
    • getValue3D

      private float getValue3D(float x, float y, float z, int channelIndex, ModelSimpleImage src)
      Get the value of a 3D point.
      Parameters:
      x - x coordinate
      y - y coordinate
      z - z coordinate
      channelIndex - color channel
      src - image to sample from
      Returns:
      the point's value
    • getValue3D

      private float getValue3D(float x, float y, float z, int t, int channelIndex, ModelSimpleImage src)
      Get the value of a 4D point.
      Parameters:
      x - x coordinate
      y - y coordinate
      z - z coordinate
      t - DOCUMENT ME!
      channelIndex - color channel
      src - image to sample from
      Returns:
      the point's value
    • subsample2D

      private ModelSimpleImage subsample2D(int nImages)
      Subsample a 2D image.
      Parameters:
      nImages - the number of 2D images to subsample (1 if really 2D)
      Returns:
      the subsampled image
    • subsample3D

      private ModelSimpleImage subsample3D()
      Perform the subsampling. Create a result image with the extents given into the constuctor. Then, for each point in the result image, find point which corresponds to it in the source image. Add up weighted intensities of the neighbors of this point in the source image and the intensity of the point itself. Store this value in the point of the result image. Once all points in the result image have been visted, return the result image.
      Returns:
      resampled image
    • subsample4D

      private ModelSimpleImage subsample4D()
      Perform the subsampling. Create a result image with the extents given into the constuctor. Then, for each point in the result image, find point which corresponds to it in the source image. Add up weighted intensities of the neighbors of this point in the source image and the intensity of the point itself. Store this value in the point of the result image. Once all points in the result image have been visted, return the result image. Does not subsample in fourth time dimension - 3.5D operation
      Returns:
      resampled image
    • transform25DVOI

      private void transform25DVOI(ModelImage image, float[] imgBuffer, TransMatrix xfrm)
      Transforms and resamples a 2D or 25D VOI using nearest neighbor interpolation.
      1. Export VOIs as a mask image
      2. Transform mask
      3. Extract VOI contours from mask image and put in new image.
      Parameters:
      image - Image where VOIs are stored
      imgBuffer - Image array
      xfrm - Transformation matrix to be applied
    • transform3DVOI

      private void transform3DVOI(ModelImage image, float[] imgBuffer, TransMatrix xfrm)
      Transforms and resamples a 3D VOI using nearest neighbor interpolation.
      1. Export VOIs as a mask image
      2. Transform mask
      3. Extract VOI contours from mask image and put in new image.
      Parameters:
      image - Image where VOIs are stored
      imgBuffer - Image array
      xfrm - Transformation matrix to be applied
    • padImage

      private ModelImage padImage(ModelImage kImage, int[] padExtents)
    • makeImageName

      private static String makeImageName(String image_name, String ext)
      Helper method for making the result image's name. Strips the current extension from the original name, adds the given extension, and returns the new name.
      Parameters:
      image_name - the original image's name
      ext - Extension to add which gives information about what algorithm was performed on the image.
      Returns:
      The new image name.