Package gov.nih.mipav.model.algorithms
Class AlgorithmELSUNCOpt2D
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.AlgorithmELSUNCOpt2D
-
- All Implemented Interfaces:
java.awt.event.ActionListener,java.awt.event.WindowListener,java.lang.Runnable,java.util.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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classAlgorithmELSUNCOpt2D.FitOAR2DELSUNCModel(package private) classAlgorithmELSUNCOpt2D.FitOAR2DLMModel(package private) classAlgorithmELSUNCOpt2D.FitOAR2DNL2solModel
-
Field Summary
Fields Modifier and Type Field Description private AlgorithmOptimizeFunctionBasecostFunctionCost function called to measure cost - 1D.private intELSUNC(package private) AlgorithmELSUNCOpt2D.FitOAR2DELSUNCModeleModelprivate 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) AlgorithmELSUNCOpt2D.FitOAR2DLMModellmModelprivate intmaxIterationsThe maximum number of iterations the optimization allows.private doubleminFunctionAtBestprivate intnDimsDegress of freedom.private intNL2SOL(package private) AlgorithmELSUNCOpt2D.FitOAR2DNL2solModelnModelprivate double[]OARToleranceArray of tolerances for each dimension.private AlgorithmBaseparentParent algorithm that called this optimization.private booleanpathRecordedThe flag to indicate whether the searching path need to be recorded.protected java.util.Hashtable<java.lang.Long,java.util.Vector<java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f>>>pathsStore the paths for every thread.private Vectornd[]pointsArray used to hold the initial points, final points and costsprivate booleanrigidFlag indicating this is a rigid transformation.private 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 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadjustTranslation(TransMatrixd mat, float sample)double[]constructPoint(double[] defaultPoint, double[] point)Construct a full 7-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 7-dimension transformation vector to a 3x3 transformation matrix.private voidcreateTerrain(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)float[]createTerrain(float transXFrom, float transXTo, float transXStep, float transYFrom, float transYTo, float transYStep, float rotFrom, float rotTo, float rotStep)private 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(int index)Obtain the transformation vector and convert to the matrix representation.TransMatrixdgetMatrix(int index, float sample)double[]getPoint(int index)Return the full transformation vector.Vectornd[]getPoints()Return an array of transformation vector.booleanisPathRecorded()doublemeasureCost(double[] point)Measure the cost value for the given transformation vector.doublemeasureCost(TransMatrixd m)Measure the cost value for the given transformation matrix.voidrunAlgorithm()Actually runs the algorithm.private 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()voidsetMaxIterations(int max)Accessor that sets the maximum number of iterations.voidsetPathRecorded(boolean pathRecorded)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
-
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
AlgorithmELSUNCOpt2D.FitOAR2DELSUNCModel eModel
-
nModel
AlgorithmELSUNCOpt2D.FitOAR2DNL2solModel nModel
-
lmModel
AlgorithmELSUNCOpt2D.FitOAR2DLMModel 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 java.util.Hashtable<java.lang.Long,java.util.Vector<java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f>>> paths
Store the paths for every thread.
-
epsilon
private double epsilon
-
huge
private double huge
-
-
Constructor Detail
-
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-truemeans this was a rigid transformationsearchAlgorithm- 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
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:
AlgorithmELSUNCOptBase#adjustTranslation(TransMatrix, float)
-
getMatrix
public TransMatrixd getMatrix(int index, float sample)
- See Also:
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.
-
-