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:
ActionListener,WindowListener,Runnable,EventListener
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 ClassesModifier and TypeClassDescription(package private) class(package private) class(package private) classNested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AlgorithmOptimizeFunctionBaseCost function called to measure cost - 1D.private final int(package private) AlgorithmELSUNCOpt2D.FitOAR2DELSUNCModelprivate doubleprivate TransMatrixdThe transformation matrix from the origin of the input image.private doubleThe cost of the function at the best minimum.private doubleprivate final int(package private) AlgorithmELSUNCOpt2D.FitOAR2DLMModelprivate intThe maximum number of iterations the optimization allows.private doubleprivate intDegress of freedom.private final int(package private) AlgorithmELSUNCOpt2D.FitOAR2DNL2solModelprivate double[]Array of tolerances for each dimension.private AlgorithmBaseParent algorithm that called this optimization.private booleanThe flag to indicate whether the searching path need to be recorded.Store the paths for every thread.private Vectornd[]Array used to hold the initial points, final points and costsprivate booleanFlag indicating this is a rigid transformation.private intprivate double[]Point that was initially passed into function.private intprivate TransMatrixdThe 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, threadStoppedFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionAlgorithmELSUNCOpt2D(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
Modifier and TypeMethodDescriptionvoidadjustTranslation(TransMatrixd mat, float sample) double[]constructPoint(double[] defaultPoint, double[] point) Construct a full 7-dimension transformation vector from the partial transformation vector.convertToMatrix(double[] vector) Convert a transformation vector to a transformation matrix.convertToMatrix(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) voidSets 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.final 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.final TransMatrixdgetMatrix(int index) Obtain the transformation vector and convert to the matrix representation.getMatrix(int index, float sample) double[]getPoint(int index) Return the full transformation vector.Vectornd[]Return an array of transformation vector.booleanfinal doublemeasureCost(double[] point) Measure the cost value for the given transformation vector.final doubleMeasure the cost value for the given transformation matrix.voidActually runs the algorithm.private voidRuns 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 voidvoidsetMaxIterations(int max) Accessor that sets the maximum number of iterations.voidsetPathRecorded(boolean pathRecorded) voidSets 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, windowOpenedMethods 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, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
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 rigidFlag indicating this is a rigid transformation. -
nDims
private int nDimsDegress of freedom. -
costFunction
Cost function called to measure cost - 1D. -
OARTolerance
private double[] OARToleranceArray of tolerances for each dimension. -
maxIterations
private int maxIterationsThe maximum number of iterations the optimization allows. -
parent
Parent algorithm that called this optimization. -
toOrigin
The transformation matrix to the origin of the input image. -
fromOrigin
The transformation matrix from the origin of the input image. -
points
Array used to hold the initial points, final points and costs -
functionAtBest
private double functionAtBestThe cost of the function at the best minimum. -
minFunctionAtBest
private double minFunctionAtBest -
eModel
-
nModel
-
lmModel
-
status
private int status -
start
private double[] startPoint that was initially passed into function. -
pathRecorded
private boolean pathRecordedThe flag to indicate whether the searching path need to be recorded. -
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-truemeans this was a rigid transformationsearchAlgorithm- ELSUNC, LEVENBERG_MARQUARDT, or NL2SOL;
-
-
Method Details
-
disposeLocal
public void disposeLocal()Sets everything to null and prepares this class for destruction. -
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
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
- See Also:
-
getMatrix
- See Also:
-
getMatrix
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
Convert a transformation vector to a transformation matrix.- Parameters:
vector- a transformation vector.- Returns:
- a transformation matrix
-
updatePoint
-
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
Measure the cost value for the given transformation matrix.- Parameters:
m- a transformation matrix.- Returns:
- the cost value.
-