Class 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 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 data
        ySource - array with y coordinates of source data
        xTar - array with x coordinates of target data
        yTar - array with y coordinates of target data
        smooth - cannot be negative. If the smoothing term is nonzero, the interpolation is not exact
        baseImage - 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 data
        ySource - array with y coordinates of source data
        zSource - array with z coordinates of source data
        xTar - array with x coordinates of target data
        yTar - array with y coordinates of target data
        zTar - array with z coordinates of target data
        smooth - cannot be negative. * If the smoothing term is nonzero, the interpolation is not exact
        baseImage - 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 data
        ySource - array with y coordinates of source data
        zSource - array with z coordinates of source data
        xTar - array with x coordinates of target data
        yTar - array with y coordinates of target data
        zTar - array with z coordinates of target data
        smooth - cannot be negative. * If the smoothing term is nonzero, the interpolation is not exact
        baseImage - 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

      • getResultImage

        public ModelImage getResultImage()
        DOCUMENT ME!
        Returns:
        resultImage
      • kernel

        public final double kernel​(double fT)
        DOCUMENT ME!
        Parameters:
        fT - DOCUMENT ME!
        Returns:
        DOCUMENT ME!
      • 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 data
        y - array with y coordinates of data
        f - array with values of data at (x,y) locations
        smooth - 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 data
        ySource - array with y coordinates of source data
        xTar - array with x coordinates of target data
        yTar - array with y coordinates of target data
        smooth - 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 data
        y - array with y coordinates of data
        z - array with z coordinates of data
        f - array with values of data at (x,y,z) locations
        smooth - 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 data
        ySource - array with y coordinates of source data
        zSource - array with z coordinates of source data
        xTar - array with x coordinates of target data
        yTar - array with y coordinates of target data
        zTar - array with z coordinates of target data
        smooth - 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 path
        message - 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