Package gov.nih.mipav.model.algorithms
Class AlgorithmELSUNCOpt3D
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.AlgorithmELSUNCOpt3D
-
- All Implemented Interfaces:
java.awt.event.ActionListener,java.awt.event.WindowListener,java.lang.Runnable,java.util.EventListener
public class AlgorithmELSUNCOpt3D extends AlgorithmBase
Runs ELSUNC, LEVENBERG_MARQUARDT, or NL2SOL for a 3D 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 23, 2012
- Author:
- William Gandler
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classAlgorithmELSUNCOpt3D.FitOAR3DELSUNCModel(package private) classAlgorithmELSUNCOpt3D.FitOAR3DLMModel(package private) classAlgorithmELSUNCOpt3D.FitOAR3DNL2solModel
-
Field Summary
Fields Modifier and Type Field Description private AlgorithmOptimizeFunctionBasecostFunctionCost function called to measure cost - 1D.private intELSUNC(package private) AlgorithmELSUNCOpt3D.FitOAR3DELSUNCModeleModelprivate doubleepsilonprivate TransMatrixdfromOriginThe transformation matrix from the origin of the input image.private doublefunctionAtBestThe cost of the function at the best minimum.private doublehugeprivate intLEVENBERG_MARQUARDT(package private) AlgorithmELSUNCOpt3D.FitOAR3DLMModellmModelprivate intmaxIterationsThe maximum number of iterations the optimization allows.private doubleminFunctionAtBestprivate intnDimsDegress of freedom.private intNL2SOL(package private) AlgorithmELSUNCOpt3D.FitOAR3DNL2solModelnModelprivate double[]OARToleranceArray of tolerances for each dimension.private AlgorithmBaseparentParent algorithm that called this optimization.private Vectornd[]pointsArray used to hold the initial points, final points and costsprivate intsearchAlgorithmprivate double[]startPoint that was initially passed into function.private intstatusprivate TransMatrixdtoOriginThe transformation matrix to the origin of the input image.-
Fields inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
destFlag, destImage, image25D, mask, maxProgressValue, minProgressValue, multiThreadingEnabled, nthreads, progress, progressModulus, progressStep, runningInSeparateThread, separable, srcImage, threadStopped
-
-
Constructor Summary
Constructors Constructor Description AlgorithmELSUNCOpt3D(AlgorithmBase parent, WildMagic.LibFoundation.Mathematics.Vector3f com, int degreeOfFreedom, AlgorithmOptimizeFunctionBase costFunc, double[] tols, int maxIter, 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.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadjustTranslation(TransMatrixd mat, float sample)double[]constructPoint(double[] defaultPoint, double[] point)Construct a full 12-dimension transformation vector from the partial transformation vector.TransMatrixdconvertToMatrix(double[] vector)Convert a transformation vector to a transformation matrix.TransMatrixdconvertToMatrix(TransMatrixd toOrigin, TransMatrixd fromOrigin, double[] vector)Convert a 12-dimension transformation vector to a 4x4 transformation matrix.double[]convertToMidsagittal(double[] point)Converts a full transformation vector into a midsagittal transformation vector.static double[]copyPoint(double[] point)Make a copy of the transformation vectorprivate voiddfault(int[] iv, double[] v)voiddisposeLocal()Sets everything to null and prepares this class for destruction.double[]extractPoint(double[] startPoint)Extract the partial or full transformation vector from the start transformation vector, which will be optimized.doublegetCost(int index)Returns the cost for the transformation vector.double[]getFinal(double[] point)Accessor that returns the final point with translations, rotations, scales, and skews representing the best tranformation.TransMatrixdgetMatrix(double[] point, float sample)TransMatrixdgetMatrix(int index)Obtain the transformation vector and convert to the matrix representation.TransMatrixdgetMatrix(int index, float sample)TransMatrixdgetMatrixHalf(int index)Obtain the transformation vector, scale it by 0.5, then convert it to transformation matrix.TransMatrixdgetMatrixHalf(int index, float sample)Obtain the transformation vector, scale it by 0.5, then convert it to transformation matrix and scale the translations by sample parameter.TransMatrixdgetMatrixMidsagittal(int index)Accessor that returns the matrix representing the best tranformation.TransMatrixdgetMatrixMidsagittal(int index, float sample)Accessor that returns the matrix representing the best tranformation.intgetMaxIterations()double[]getPoint(int index)Return the full transformation vector.double[]getPoint(int index, float sample)Obtain the transformation vector and adjust its translation by sample parameters.Vectornd[]getPoints()Return an array of transformation vector.doublemeasureCost(double[] point)voidrunAlgorithm()Actually runs the algorithm.voidrunELSUNC()Runs ELSUNC along one dimension at a time as long as the costFunction improves during one cycle of runs along every dimension.private voidrunLM()Runs Levneberg-Marqaurdt along one dimension at a time as long as the costFunction improves during one cycle of runs along every dimension.private voidrunNL2sol()static double[]scalePoint(double[] point, double scale)Scale the point by scale parameter and store it into another vector.double[]scalePoint(int index, double scale)Obtain the transformation vector and make a copy, then scale it by scale parameter.voidsetMaxIterations(int max)Accessor that sets the maximum number of iterations.voidsetPoints(Vectornd[] points)Sets the transformation vectors.voidupdatePoint(double[] point, double cost, Vectornd v)-
Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, finalize, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, fireProgressStateChanged, generateProgressValues, getDestImage, getElapsedTime, getMask, getMaxProgressValue, getMinProgressValue, getNumberOfThreads, getProgress, getProgressChangeListener, getProgressChangeListeners, getProgressModulus, getProgressStep, getProgressValues, getSrcImage, isCompleted, isImage25D, isMultiThreadingEnabled, isRunningInSeparateThread, isThreadStopped, linkProgressToAlgorithm, linkProgressToAlgorithm, makeProgress, notifyListeners, removeListener, removeProgressChangeListener, run, setCompleted, setImage25D, setMask, setMaxProgressValue, setMinProgressValue, setMultiThreadingEnabled, setNumberOfThreads, setProgress, setProgressModulus, setProgressStep, setProgressValues, setProgressValues, setRunningInSeparateThread, setSrcImage, setStartTime, setThreadStopped, startMethod, windowActivated, windowClosed, windowClosing, windowDeactivated, windowDeiconified, windowIconified, windowOpened
-
Methods inherited from class java.lang.Thread
activeCount, checkAccess, clone, countStackFrames, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, join, join, join, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, start, stop, suspend, toString, yield
-
-
-
-
Field Detail
-
ELSUNC
private final int ELSUNC
- See Also:
- Constant Field Values
-
LEVENBERG_MARQUARDT
private final int LEVENBERG_MARQUARDT
- See Also:
- Constant Field Values
-
NL2SOL
private final int NL2SOL
- See Also:
- Constant Field Values
-
searchAlgorithm
private int searchAlgorithm
-
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
AlgorithmELSUNCOpt3D.FitOAR3DELSUNCModel eModel
-
nModel
AlgorithmELSUNCOpt3D.FitOAR3DNL2solModel nModel
-
lmModel
AlgorithmELSUNCOpt3D.FitOAR3DLMModel lmModel
-
status
private int status
-
start
private double[] start
Point that was initially passed into function.
-
epsilon
private double epsilon
-
huge
private double huge
-
-
Constructor Detail
-
AlgorithmELSUNCOpt3D
public AlgorithmELSUNCOpt3D(AlgorithmBase parent, WildMagic.LibFoundation.Mathematics.Vector3f com, int degreeOfFreedom, AlgorithmOptimizeFunctionBase costFunc, double[] tols, int maxIter, 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 3, 4, 6, 7, 9, or 12).costFunc- Cost function to use.tols- Tolerance for each dimension (tols.length == degreeOfFreedom).maxIter- Maximum number of iterations.searchAlgorithm- ELSUNC, LEVENBERG_MARQUARDT, or NL2SOL;
-
-
Method Detail
-
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:AlgorithmBaseActually runs the algorithm. Implemented by inheriting algorithms.- Specified by:
runAlgorithmin classAlgorithmBase
-
runELSUNC
public 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.
-
constructPoint
public double[] constructPoint(double[] defaultPoint, double[] point)Construct a full 12-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: 3: only 3 translations 4: 3 translation and global scaling 6: 3 rotations and translations 7: 3 rotations and translations, and global scaling 9: 3 rotations, translations and scalings 12: 3 rotations, translations, scalings and skewings.- Parameters:
defaultPoint- a default full 12-dimension transformation vector.point- a partial or full transformation vector.- Returns:
- a full transformation vector.
-
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.
-
convertToMatrix
public TransMatrixd convertToMatrix(TransMatrixd toOrigin, TransMatrixd fromOrigin, double[] vector)
Convert a 12-dimension transformation vector to a 4x4 transformation matrix.- Parameters:
vector- a 12-dimension transformation vector including 3 rotations, translations, scalings and skews.- Returns:
- a 4x4 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 12-dimension transformation vector.- Returns:
- the partial or full transformation vector which will be optimized.
-
getMatrix
public TransMatrixd getMatrix(int index, float sample)
- See Also:
AlgorithmPowellOptBase#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
-
convertToMatrix
public TransMatrixd convertToMatrix(double[] vector)
Convert a transformation vector to a transformation matrix.- Parameters:
vector- a transformation vector.- Returns:
- a transformation matrix
-
measureCost
public final double measureCost(double[] point)
-
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.
-
getPoint
public double[] getPoint(int index)
Return the full transformation vector.- Parameters:
index- the index of the transformation vector.- Returns:
- the full transformation vector.
-
getPoint
public double[] getPoint(int index, float sample)Obtain the transformation vector and adjust its translation by sample parameters.- Parameters:
index- the index of transformation vector.sample- the translation scaling parameter.- Returns:
- the translation scaled transformation vector.
-
getMatrix
public TransMatrixd getMatrix(double[] point, float sample)
- See Also:
AlgorithmPowellOptBase#getMatrix(int, float)
-
adjustTranslation
public void adjustTranslation(TransMatrixd mat, float sample)
- See Also:
AlgorithmPowellOptBase#adjustTranslation(TransMatrix, float)
-
getMatrixHalf
public TransMatrixd getMatrixHalf(int index)
Obtain the transformation vector, scale it by 0.5, then convert it to transformation matrix.- Parameters:
index- the index of transformation vector.- Returns:
- the scaled transformation matrix.
-
scalePoint
public static final double[] scalePoint(double[] point, double scale)Scale the point by scale parameter and store it into another vector.- Parameters:
point- the transformation vector.scale- the scale parameter.- Returns:
- the scaled transformation vector
-
scalePoint
public final double[] scalePoint(int index, double scale)Obtain the transformation vector and make a copy, then scale it by scale parameter.- Parameters:
index- the index of transformation vectorscale- the scale parameter- Returns:
- the new scaled transformation vector.
-
getMatrixHalf
public TransMatrixd getMatrixHalf(int index, float sample)
Obtain the transformation vector, scale it by 0.5, then convert it to transformation matrix and scale the translations by sample parameter.- Parameters:
index- the index of transformation vector.sample- the translation scaling parameter.- Returns:
- the scaled transformation matrix.
-
convertToMidsagittal
public double[] convertToMidsagittal(double[] point)
Converts a full transformation vector into a midsagittal transformation vector.- Parameters:
point- the full 12-dimension transformation vector.- Returns:
- the transformation vector complying with midsagittal alignment algorithm.
-
copyPoint
public static final double[] copyPoint(double[] point)
Make a copy of the transformation vector- Parameters:
point- a transformation vector.- Returns:
- the copy of the transformation vector.
-
getMatrixMidsagittal
public TransMatrixd getMatrixMidsagittal(int index)
Accessor that returns the matrix representing the best tranformation. This transformation contains only the z rotation and the x and y translation, to be used in the midsagittal alignment algorithm.- Returns:
- matrix representing the best transformation's z rot and x and y trans.
-
getMatrixMidsagittal
public TransMatrixd getMatrixMidsagittal(int index, float sample)
Accessor that returns the matrix representing the best tranformation. The passed in parameter represents the resolution (same in all directions and for both input and reference images, since resampled isotropically). Since the optimization was done in pixel space, not millimeter space, the translation parameters need to be scaled by the sample value. This transformation contains only the z rotation and the x and y translation, to be used in the midsagittal alignment algorithm.- Parameters:
sample- the voxel resolution- Returns:
- matrix representing the best transformation's z rot and x and y trans.
-
updatePoint
public void updatePoint(double[] point, double cost, Vectornd v)
-
setMaxIterations
public void setMaxIterations(int max)
Accessor that sets the maximum number of iterations.- Parameters:
max- The max number of iterations.
-
getMaxIterations
public int getMaxIterations()
-
-