Package gov.nih.mipav.model.algorithms
Class AlgorithmTPSpline
java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.AlgorithmTPSpline
- All Implemented Interfaces:
ActionListener,WindowListener,Runnable,EventListener
Thin plate spline Warning: If the supplied (x,y) data set in setupTPSpline2D is nearly collinear, singular matrices
will result and a matrix inversion will fail. This code calculating the function f at interpolated points is a port
of software from Geometric Tools at www.geometrictools.com. Reference: Thin Plate Splines by David Eberly of
Geometric Tools at http://www.geometrictools.com/SampleMathematics/ThinPlateSplines/ThinPlateSplines.html.
The Eberly Thin plate splines 2D is a physically based 2D interpolation scheme for arbitrarily spaced tabulated data (xi,yi,f(xi,yi)). These splines are the generalization of the natural cubic splines in 1D. The spline surface represents a thin metal sheet that is constrained not to move at the grid points. The Eberly Thin plate spines 3D operates on data of the form (xi,yi,zi,f(xi,yi,zi).
Also given is thin plate spline code for warping from one x,y source set to another x',y' target set. This code is based on the paper Principal Warps: Thin-Plate Splines and the Decompositions of Deformations by Fred L. BookStein, IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol. 11, No. 6, June, 1989, pp. 567 - 585.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ModelImageDOCUMENT ME!private float[][]DOCUMENT ME!private booleanprivate float[]DOCUMENT ME!private ModelImageDOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private intDOCUMENT ME!private ModelImageDOCUMENT ME!private booleanprivate booleanprivate floatDOCUMENT ME!private double[]DOCUMENT ME!private intprivate floatDOCUMENT ME!private floatDOCUMENT ME!private double[]DOCUMENT ME!private double[]DOCUMENT ME!private intprivate floatDOCUMENT ME!private floatDOCUMENT ME!private double[]DOCUMENT ME!private double[]DOCUMENT ME!private intprivate floatDOCUMENT ME!private floatDOCUMENT ME!private double[]DOCUMENT ME!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
ConstructorsConstructorDescriptionAlgorithmTPSpline - default constructor.AlgorithmTPSpline(double[] xSource, double[] ySource, double[] zSource, double[] xTar, double[] yTar, double[] zTar, float smooth, ModelImage baseImage, ModelImage matchImage) AlgorithmTPSpline - constructor for 3D case.AlgorithmTPSpline(double[] xSource, double[] ySource, double[] zSource, double[] xTar, double[] yTar, double[] zTar, float smooth, ModelImage baseImage, ModelImage matchImage, boolean doSetupOnly) AlgorithmTPSpline - constructor for 3D case.AlgorithmTPSpline(double[] xSource, double[] ySource, double[] xTar, double[] yTar, float smooth, ModelImage baseImage, ModelImage matchImage) AlgorithmTPSpline - constructor for 2D case.AlgorithmTPSpline(ModelImage matchImage) Constructor used when N, xDimA, yDimA, zDimA, x[], y[], z[], and C[][] are read from a file -
Method Summary
Modifier and TypeMethodDescriptionvoidfinalize()finalize -final float[]getCorrespondingPoint(float xTar, float yTar, float zTar) float[]getCorrespondingPoint(int xTar, int yTar, int zTar) DOCUMENT ME!final doublekernel(double fT) DOCUMENT ME!voidreadMatrix(RandomAccessFile raFile) Reads: 1.)voidrun - starts the program.voidsaveMatrix(String fileName, String message) Saves: 1.)voidsetupTPSpline2D - computes the thin plate spline coefficients.voidsetupTPSpline2D(double[] xSource, double[] ySource, double[] xTar, double[] yTar, float smooth) setupTPSpline2D computes the thin plate spline coefficients.voidsetupTPSpline2D(float[] x, float[] y, float[] f, float smooth) setupTPSpline2D computes the thin plate spline coefficients.voidsetupTPSpline3D - computes the thin plate spline coefficients.voidsetupTPSpline3D(double[] xSource, double[] ySource, double[] zSource, double[] xTar, double[] yTar, double[] zTar, float smooth) setupTPSpline3D computes the thin plate spline coefficients.voidsetupTPSpline3D(float[] x, float[] y, float[] z, float[] f, float smooth) setupTPSpline3D computes the thin plate spline coefficients.private voidDOCUMENT ME!float[][]tpSpline2D(float[] xWarp, float[] yWarp) DOCUMENT ME!private voidDOCUMENT ME!private voidtransform25DVOI(ModelImage image, ModelImage destImage, float[] imgBuffer) private voidtransform3DVOI(ModelImage image, ModelImage destImage, float[] imgBuffer) voidCopy important file information to resultant image structure.Methods inherited from class gov.nih.mipav.model.algorithms.AlgorithmBase
actionPerformed, addListener, addProgressChangeListener, calculateImageSize, calculatePrincipleAxis, computeElapsedTime, computeElapsedTime, convertIntoFloat, delinkProgressToAlgorithm, delinkProgressToAlgorithmMulti, displayError, errorCleanUp, 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
-
baseImage
DOCUMENT ME! -
C
private float[][] CDOCUMENT ME! -
mA
private float[] mADOCUMENT ME! -
matchImage
DOCUMENT ME! -
mB
private float[] mBDOCUMENT ME! -
mX
private float[] mXDOCUMENT ME! -
mY
private float[] mYDOCUMENT ME! -
mZ
private float[] mZDOCUMENT ME! -
N
private int NDOCUMENT ME! -
resultImage
DOCUMENT ME! -
smooth
private float smoothDOCUMENT ME! -
x
private double[] xDOCUMENT ME! -
xInvRange
private float xInvRangeDOCUMENT ME! -
xMin
private float xMinDOCUMENT ME! -
xTar
private double[] xTarDOCUMENT ME! -
y
private double[] yDOCUMENT ME! -
yInvRange
private float yInvRangeDOCUMENT ME! -
yMin
private float yMinDOCUMENT ME! -
yTar
private double[] yTarDOCUMENT ME! -
z
private double[] zDOCUMENT ME! -
zInvRange
private float zInvRangeDOCUMENT ME! -
zMin
private float zMinDOCUMENT ME! -
zTar
private double[] zTarDOCUMENT ME! -
setupRequired
private boolean setupRequired -
run2D
private boolean run2D -
xDimA
private int xDimA -
yDimA
private int yDimA -
zDimA
private int zDimA -
doSetupOnly
private boolean doSetupOnly
-
-
Constructor Details
-
AlgorithmTPSpline
public AlgorithmTPSpline()AlgorithmTPSpline - default constructor. -
AlgorithmTPSpline
public AlgorithmTPSpline(double[] xSource, double[] ySource, double[] xTar, double[] yTar, float smooth, ModelImage baseImage, ModelImage matchImage) AlgorithmTPSpline - constructor for 2D case.- Parameters:
xSource- array with x coordinates of source dataySource- array with y coordinates of source dataxTar- array with x coordinates of target datayTar- array with y coordinates of target datasmooth- cannot be negative. If the smoothing term is nonzero, the interpolation is not exactbaseImage- DOCUMENT ME!matchImage- DOCUMENT ME!
-
AlgorithmTPSpline
public AlgorithmTPSpline(double[] xSource, double[] ySource, double[] zSource, double[] xTar, double[] yTar, double[] zTar, float smooth, ModelImage baseImage, ModelImage matchImage) AlgorithmTPSpline - constructor for 3D case.- Parameters:
xSource- array with x coordinates of source dataySource- array with y coordinates of source datazSource- array with z coordinates of source dataxTar- array with x coordinates of target datayTar- array with y coordinates of target datazTar- array with z coordinates of target datasmooth- cannot be negative. * If the smoothing term is nonzero, the interpolation is not exactbaseImage- DOCUMENT ME!matchImage- DOCUMENT ME!
-
AlgorithmTPSpline
public AlgorithmTPSpline(double[] xSource, double[] ySource, double[] zSource, double[] xTar, double[] yTar, double[] zTar, float smooth, ModelImage baseImage, ModelImage matchImage, boolean doSetupOnly) AlgorithmTPSpline - constructor for 3D case.- Parameters:
xSource- array with x coordinates of source dataySource- array with y coordinates of source datazSource- array with z coordinates of source dataxTar- array with x coordinates of target datayTar- array with y coordinates of target datazTar- array with z coordinates of target datasmooth- cannot be negative. * If the smoothing term is nonzero, the interpolation is not exactbaseImage- DOCUMENT ME!matchImage- DOCUMENT ME!
-
AlgorithmTPSpline
Constructor used when N, xDimA, yDimA, zDimA, x[], y[], z[], and C[][] are read from a file- Parameters:
matchImage-
-
-
Method Details
-
finalize
public void finalize()finalize -- Overrides:
finalizein classAlgorithmBase
-
getResultImage
DOCUMENT ME!- Returns:
- resultImage
-
kernel
public final double kernel(double fT) DOCUMENT ME!- Parameters:
fT- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
runAlgorithm
public void runAlgorithm()run - starts the program.- Specified by:
runAlgorithmin classAlgorithmBase
-
setupTPSpline2D
public void setupTPSpline2D()setupTPSpline2D - computes the thin plate spline coefficients. -
setupTPSpline2D
public void setupTPSpline2D(float[] x, float[] y, float[] f, float smooth) setupTPSpline2D computes the thin plate spline coefficients.- Parameters:
x- array with x coordinates of datay- array with y coordinates of dataf- array with values of data at (x,y) locationssmooth- nonnegative smoothing parameter
-
setupTPSpline2D
public void setupTPSpline2D(double[] xSource, double[] ySource, double[] xTar, double[] yTar, float smooth) setupTPSpline2D computes the thin plate spline coefficients.- Parameters:
xSource- array with x coordinates of source dataySource- array with y coordinates of source dataxTar- array with x coordinates of target datayTar- array with y coordinates of target datasmooth- cannot be negative If the smoothing term is nonzero, the interpolation is not exact
-
setupTPSpline3D
public void setupTPSpline3D()setupTPSpline3D - computes the thin plate spline coefficients. -
setupTPSpline3D
public void setupTPSpline3D(float[] x, float[] y, float[] z, float[] f, float smooth) setupTPSpline3D computes the thin plate spline coefficients.- Parameters:
x- array with x coordinates of datay- array with y coordinates of dataz- array with z coordinates of dataf- array with values of data at (x,y,z) locationssmooth- nonnegative smoothing parameter
-
setupTPSpline3D
public void setupTPSpline3D(double[] xSource, double[] ySource, double[] zSource, double[] xTar, double[] yTar, double[] zTar, float smooth) setupTPSpline3D computes the thin plate spline coefficients.- Parameters:
xSource- array with x coordinates of source dataySource- array with y coordinates of source datazSource- array with z coordinates of source dataxTar- array with x coordinates of target datayTar- array with y coordinates of target datazTar- array with z coordinates of target datasmooth- cannot be negative If the smoothing term is nonzero, the interpolation is not exact
-
tpSpline2D
public float[][] tpSpline2D(float[] xWarp, float[] yWarp) DOCUMENT ME!- Parameters:
xWarp- DOCUMENT ME!yWarp- DOCUMENT ME!- Returns:
- DOCUMENT ME!
-
updateFileInfo
public void updateFileInfo()Copy important file information to resultant image structure. -
tpSpline2D
private void tpSpline2D()DOCUMENT ME! -
transform25DVOI
-
getCorrespondingPoint
public float[] getCorrespondingPoint(int xTar, int yTar, int zTar) -
getCorrespondingPoint
public final float[] getCorrespondingPoint(float xTar, float yTar, float zTar) -
tpSpline3D
private void tpSpline3D()DOCUMENT ME! -
transform3DVOI
-
saveMatrix
Saves: 1.) N, the number of matching control points in baseImage and matchImage 2.) Number of rows in C matrix 3.) Number of columns in C matrix 4.) xDim of baseImage 5.) yDim of baseImage 6.) If noncoplanar 3D thin plate spline is used, saves zDim of baseImage 7.) x coordinates of baseImage control points 8.) y coordinates of baseImage control points 9.) If noncoplanar 3D thin plate spline is used, saves z coordinates of baseImage control points 10.) If 2D or coplanar 3D, saves n+3 by 2 C[][] float matrix from setupTPSpline2D If noncoplanar 3D, saves n+4 by 3 C[][] float matrix from setupTPSpline3D 11.) Saves optional message.- Parameters:
fileName- - file name, including the pathmessage- optionally write a message at the file end
-
readMatrix
Reads: 1.) N, the number of matching control points in baseImage and matchImage 2.) Number of rows in C matrix 3.) Number of columns in C matrix 4.) xDim of baseImage 5.) yDim of baseImage 6.) If noncoplanar 3D thin plate spline is used, reads zDim of baseImage 7.) x coordinates of baseImage control points 8.) y coordinates of baseImage control points 9.) If noncoplanar 3D thin plate spline is used, reads z coordinates of baseImage control points 10.) If 2D or coplanar 3D, reads n+3 by 2 C[][] float matrix from setupTPSpline2D If noncoplanar 3D, reads n+4 by 3 C[][] float matrix from setupTPSpline3D Does not read optional message at end of file.- Parameters:
raFile- file to be read
-