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:
java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class AlgorithmTPSpline extends AlgorithmBase
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.
-
-
Field Summary
Fields Modifier and Type Field Description private ModelImage
baseImage
DOCUMENT ME!private float[][]
C
DOCUMENT ME!private boolean
doSetupOnly
private float[]
mA
DOCUMENT ME!private ModelImage
matchImage
DOCUMENT ME!private float[]
mB
DOCUMENT ME!private float[]
mX
DOCUMENT ME!private float[]
mY
DOCUMENT ME!private float[]
mZ
DOCUMENT ME!private int
N
DOCUMENT ME!private ModelImage
resultImage
DOCUMENT ME!private boolean
run2D
private boolean
setupRequired
private float
smooth
DOCUMENT ME!private double[]
x
DOCUMENT ME!private int
xDimA
private float
xInvRange
DOCUMENT ME!private float
xMin
DOCUMENT ME!private double[]
xTar
DOCUMENT ME!private double[]
y
DOCUMENT ME!private int
yDimA
private float
yInvRange
DOCUMENT ME!private float
yMin
DOCUMENT ME!private double[]
yTar
DOCUMENT ME!private double[]
z
DOCUMENT ME!private int
zDimA
private float
zInvRange
DOCUMENT ME!private float
zMin
DOCUMENT ME!private double[]
zTar
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, threadStopped
-
-
Constructor Summary
Constructors Constructor Description AlgorithmTPSpline()
AlgorithmTPSpline - 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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
finalize()
finalize -float[]
getCorrespondingPoint(float xTar, float yTar, float zTar)
float[]
getCorrespondingPoint(int xTar, int yTar, int zTar)
ModelImage
getResultImage()
DOCUMENT ME!double
kernel(double fT)
DOCUMENT ME!void
readMatrix(java.io.RandomAccessFile raFile)
Reads: 1.)void
runAlgorithm()
run - starts the program.void
saveMatrix(java.lang.String fileName, java.lang.String message)
Saves: 1.)void
setupTPSpline2D()
setupTPSpline2D - computes the thin plate spline coefficients.void
setupTPSpline2D(double[] xSource, double[] ySource, double[] xTar, double[] yTar, float smooth)
setupTPSpline2D computes the thin plate spline coefficients.void
setupTPSpline2D(float[] x, float[] y, float[] f, float smooth)
setupTPSpline2D computes the thin plate spline coefficients.void
setupTPSpline3D()
setupTPSpline3D - computes the thin plate spline coefficients.void
setupTPSpline3D(double[] xSource, double[] ySource, double[] zSource, double[] xTar, double[] yTar, double[] zTar, float smooth)
setupTPSpline3D computes the thin plate spline coefficients.void
setupTPSpline3D(float[] x, float[] y, float[] z, float[] f, float smooth)
setupTPSpline3D computes the thin plate spline coefficients.private void
tpSpline2D()
DOCUMENT ME!float[][]
tpSpline2D(float[] xWarp, float[] yWarp)
DOCUMENT ME!private void
tpSpline3D()
DOCUMENT ME!private void
transform25DVOI(ModelImage image, ModelImage destImage, float[] imgBuffer)
private void
transform3DVOI(ModelImage image, ModelImage destImage, float[] imgBuffer)
void
updateFileInfo()
Copy 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, 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
-
baseImage
private ModelImage baseImage
DOCUMENT ME!
-
C
private float[][] C
DOCUMENT ME!
-
mA
private float[] mA
DOCUMENT ME!
-
matchImage
private ModelImage matchImage
DOCUMENT ME!
-
mB
private float[] mB
DOCUMENT ME!
-
mX
private float[] mX
DOCUMENT ME!
-
mY
private float[] mY
DOCUMENT ME!
-
mZ
private float[] mZ
DOCUMENT ME!
-
N
private int N
DOCUMENT ME!
-
resultImage
private ModelImage resultImage
DOCUMENT ME!
-
smooth
private float smooth
DOCUMENT ME!
-
x
private double[] x
DOCUMENT ME!
-
xInvRange
private float xInvRange
DOCUMENT ME!
-
xMin
private float xMin
DOCUMENT ME!
-
xTar
private double[] xTar
DOCUMENT ME!
-
y
private double[] y
DOCUMENT ME!
-
yInvRange
private float yInvRange
DOCUMENT ME!
-
yMin
private float yMin
DOCUMENT ME!
-
yTar
private double[] yTar
DOCUMENT ME!
-
z
private double[] z
DOCUMENT ME!
-
zInvRange
private float zInvRange
DOCUMENT ME!
-
zMin
private float zMin
DOCUMENT ME!
-
zTar
private double[] zTar
DOCUMENT 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 Detail
-
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
public AlgorithmTPSpline(ModelImage matchImage)
Constructor used when N, xDimA, yDimA, zDimA, x[], y[], z[], and C[][] are read from a file- Parameters:
matchImage
-
-
-
Method Detail
-
finalize
public void finalize()
finalize -- Overrides:
finalize
in classAlgorithmBase
-
getResultImage
public ModelImage 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:
runAlgorithm
in 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
private void transform25DVOI(ModelImage image, ModelImage destImage, float[] imgBuffer)
-
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
private void transform3DVOI(ModelImage image, ModelImage destImage, float[] imgBuffer)
-
saveMatrix
public void saveMatrix(java.lang.String fileName, java.lang.String message)
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
public void readMatrix(java.io.RandomAccessFile raFile)
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
-
-