Class AlgorithmELSUNCOpt2D

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

public class AlgorithmELSUNCOpt2D extends AlgorithmBase
Runs ELSUNC, LEVENBERG_MARQUARDT, or NL2SOL for a 2D image.

Based on ELSUNC allowed by the author with acknowledgement:

Gauss-Newton Based Algorithms For Constrained Nonlinear Least Squares Problems by Per Lindstrom and Per-Ake Wedin, Institute of Information Processing, University of Umea, S-901 87 Umea, Sweden This can be downleaded from http://www.cs.umu.se/~perl/reports/alg.ps.gz

Version:
0.1 March 22, 2012
Author:
William Gandler
  • Field Details

    • ELSUNC

      private final int ELSUNC
      See Also:
    • LEVENBERG_MARQUARDT

      private final int LEVENBERG_MARQUARDT
      See Also:
    • NL2SOL

      private final int NL2SOL
      See Also:
    • searchAlgorithm

      private int searchAlgorithm
    • rigid

      private boolean rigid
      Flag indicating this is a rigid transformation.
    • nDims

      private int nDims
      Degress of freedom.
    • costFunction

      private AlgorithmOptimizeFunctionBase costFunction
      Cost function called to measure cost - 1D.
    • OARTolerance

      private double[] OARTolerance
      Array of tolerances for each dimension.
    • maxIterations

      private int maxIterations
      The maximum number of iterations the optimization allows.
    • parent

      private AlgorithmBase parent
      Parent algorithm that called this optimization.
    • toOrigin

      private TransMatrixd toOrigin
      The transformation matrix to the origin of the input image.
    • fromOrigin

      private TransMatrixd fromOrigin
      The transformation matrix from the origin of the input image.
    • points

      private Vectornd[] points
      Array used to hold the initial points, final points and costs
    • functionAtBest

      private double functionAtBest
      The cost of the function at the best minimum.
    • minFunctionAtBest

      private double minFunctionAtBest
    • eModel

    • nModel

    • lmModel

    • status

      private int status
    • start

      private double[] start
      Point that was initially passed into function.
    • pathRecorded

      private boolean pathRecorded
      The flag to indicate whether the searching path need to be recorded.
    • paths

      protected Hashtable<Long,Vector<Vector<WildMagic.LibFoundation.Mathematics.Vector3f>>> paths
      Store the paths for every thread.
    • epsilon

      private double epsilon
    • huge

      private double huge
  • Constructor Details

    • AlgorithmELSUNCOpt2D

      public AlgorithmELSUNCOpt2D(AlgorithmBase parent, WildMagic.LibFoundation.Mathematics.Vector2f com, int degreeOfFreedom, AlgorithmOptimizeFunctionBase costFunc, double[] tols, int maxIter, boolean _rigid, int searchAlgorithm)
      Constructs a new algorithm with the given centers of mass (needed for setting the transformations), the given cost function (which was constructed with the proper images), the initial point we're looking at, some tolerance within that point to look for the minimum, and the maximum number of iterations.
      Parameters:
      parent - Algorithm that called this optimization.
      com - Center of Mass of the input image.
      degreeOfFreedom - Degree of freedom for transformation (must be 2, 3, 4, 5, 7).
      costFunc - Cost function to use.
      tols - Tolerance for each dimension (tols.length == degreeOfFreedom).
      maxIter - Maximum number of iterations.
      _rigid - true means this was a rigid transformation
      searchAlgorithm - ELSUNC, LEVENBERG_MARQUARDT, or NL2SOL;
  • Method Details

    • disposeLocal

      public void disposeLocal()
      Sets everything to null and prepares this class for destruction.
    • getPoints

      public Vectornd[] getPoints()
      Return an array of transformation vector. The meanings of those transformation vector are as following: the initial transformation vector: before algorithm is performed the final transformation vector: after algorithm was performed.
      Returns:
    • setPoints

      public void setPoints(Vectornd[] points)
      Sets the transformation vectors.
      Parameters:
      points - the transformation vectors.
    • runAlgorithm

      public void runAlgorithm()
      Description copied from class: AlgorithmBase
      Actually runs the algorithm. Implemented by inheriting algorithms.
      Specified by:
      runAlgorithm in class AlgorithmBase
    • runELSUNC

      private void runELSUNC()
      Runs ELSUNC along one dimension at a time as long as the costFunction improves during one cycle of runs along every dimension.
    • runNL2sol

      private void runNL2sol()
    • dfault

      private void dfault(int[] iv, double[] v)
    • runLM

      private void runLM()
      Runs Levneberg-Marqaurdt along one dimension at a time as long as the costFunction improves during one cycle of runs along every dimension.
    • isPathRecorded

      public boolean isPathRecorded()
    • setPathRecorded

      public void setPathRecorded(boolean pathRecorded)
    • getFinal

      public double[] getFinal(double[] point)
      Accessor that returns the final point with translations, rotations, scales, and skews representing the best tranformation.
      Returns:
      vector representing the best transformation in terms of translations, rotations, scales, and skews.
    • constructPoint

      public double[] constructPoint(double[] defaultPoint, double[] point)
      Construct a full 7-dimension transformation vector from the partial transformation vector. For missing values in point, the values in defaultPoint will be used. Different degree of freedom has different meanings: 2: only 2 translations 3: rigid: 1 rotation and 2 translations non-rigid: global scaling and 2 translations 4: 1 rotation, 2 translations and global scaling 5: 1 rotation, 2 translations and scalings 7: 1 rotation, 2 translations, scalings and skews
      Parameters:
      defaultPoint - a default full 7-dimension transformation vector.
      point - a partial or full transformation vector.
      Returns:
      a full transformation vector.
    • convertToMatrix

      public TransMatrixd convertToMatrix(TransMatrixd toOrigin, TransMatrixd fromOrigin, double[] vector)
      Convert a 7-dimension transformation vector to a 3x3 transformation matrix.
      Parameters:
      vector - a 7-dimension transformation vector including 1 rotation, 2 translations, 2 scalings and 2 skews.
      Returns:
      a 3x3 transformation matrix
    • extractPoint

      public double[] extractPoint(double[] startPoint)
      Extract the partial or full transformation vector from the start transformation vector, which will be optimized.
      Parameters:
      startPoint - the start full 7-dimension transformation vector.
      Returns:
      the partial or full transformation vector which will be optimized.
    • getCost

      public final double getCost(int index)
      Returns the cost for the transformation vector.
      Parameters:
      index - the index of transformation vector.
      Returns:
      the cost for the transformation vector.
    • setMaxIterations

      public void setMaxIterations(int max)
      Accessor that sets the maximum number of iterations.
      Parameters:
      max - The max number of iterations.
    • adjustTranslation

      public void adjustTranslation(TransMatrixd mat, float sample)
      See Also:
      • invalid reference
        AlgorithmELSUNCOptBase#adjustTranslation(TransMatrix, float)
    • getMatrix

      public TransMatrixd getMatrix(int index, float sample)
      See Also:
      • invalid reference
        AlgorithmELSUNCOptBase#getMatrix(int, float)
    • getMatrix

      public final TransMatrixd getMatrix(int index)
      Obtain the transformation vector and convert to the matrix representation.
      Parameters:
      index - the index of transformation vector.
      Returns:
      the transformation matrix
    • getPoint

      public double[] getPoint(int index)
      Return the full transformation vector.
      Parameters:
      index - the index of the transformation vector.
      Returns:
      the full transformation vector.
    • convertToMatrix

      public TransMatrixd convertToMatrix(double[] vector)
      Convert a transformation vector to a transformation matrix.
      Parameters:
      vector - a transformation vector.
      Returns:
      a transformation matrix
    • updatePoint

      public void updatePoint(double[] point, double cost, Vectornd v)
    • createTerrain

      public float[] createTerrain(float transXFrom, float transXTo, float transXStep, float transYFrom, float transYTo, float transYStep, float rotFrom, float rotTo, float rotStep)
    • createTerrain

      private void createTerrain(float[] terrain, float transXFrom, float transXTo, float transXStep, int xstart, int xdim, float transYFrom, float transYTo, float transYStep, int ystart, int ydim, float rotFrom, float rotTo, float rotStep, int zstart, int zdim)
    • measureCost

      public final double measureCost(double[] point)
      Measure the cost value for the given transformation vector.
      Parameters:
      point - a transformation vector.
      Returns:
      the cost value.
    • measureCost

      public final double measureCost(TransMatrixd m)
      Measure the cost value for the given transformation matrix.
      Parameters:
      m - a transformation matrix.
      Returns:
      the cost value.