bunwarpj
Class Transformation

java.lang.Object
  extended by bunwarpj.Transformation

public class Transformation
extends java.lang.Object

Class to perform the transformation for bUnwarpJ:


Nested Class Summary
private  class Transformation.ColorResultTileMaker
          Class to run concurrent tile windows for final results (color)
private  class Transformation.ConcurrentDeformation
          Class to concurrently calculate the two deformation mapping tables
private  class Transformation.EvaluateConsistencyTile
          Class to run concurrent consistency evaluation
private  class Transformation.EvaluateSimilarityTile
          Class to run concurrent similarity evaluation
private  class Transformation.GrayscaleResultTileMaker
          Class to run concurrent tile windows for final results (grayscale)
private  class Transformation.OutputTileMaker
          Class to run concurrent tile windows updaters (for intermediate results)
 
Field Summary
private  int accurate_mode
          level of accuracy
private  double consistencyWeight
          weight for the deformations consistency
private  double curlWeight
          curl weight
private  double[][] cxSourceToTarget
          x- B-spline coefficients keeping the transformation from source to target
private  double[][] cxTargetToSource
          x- B-spline coefficients keeping the transformation from target to source
private  double[][] cySourceToTarget
          y- B-spline coefficients keeping the transformation from source to target
private  double[][] cyTargetToSource
          y- B-spline coefficients keeping the transformation from target to source
private  MainDialog dialog
          pointer to the dialog of the bUnwarpJ interface
private  double divWeight
          divergence weight
private  double finalDirectConsistencyError
          direct consistency error at the end of the registration
private  double finalDirectLandmarkError
          direct landmarks error at the end of the registration
private  double finalDirectRegularizationError
          direct regularization error at the end of the registration
private  double finalDirectSimilarityError
          direct similarity error at the end of the registration
private  double finalInverseConsistencyError
          inverse consistency error at the end of the registration
private  double finalInverseLandmarkError
          inverse landmarks error at the end of the registration
private  double finalInverseRegularizationError
          inverse regularization error at the end of the registration
private  double finalInverseSimilarityError
          inverse similarity error at the end of the registration
private  double FLT_EPSILON
          float epsilon
private  java.lang.String fn_tnf_1
          direct transformation file name
private  java.lang.String fn_tnf_2
          inverse transformation file name
private  double imageWeight
          weight for image similarity
private  int intervals
          number of intervals to place B-spline coefficients
private  double landmarkWeight
          landmark weight
private  int max_scale_deformation
          maximum scale deformation
private  int min_scale_deformation
          minimum scale deformation
private  int min_scale_image
          minimum scale image
private  boolean ORIGINAL
          original flag
private  ij.process.ImageProcessor originalSourceIP
          initial source image processor
private  ij.process.ImageProcessor originalTargetIP
          initial target image processor
private  ij.ImagePlus output_ip_1
          reference to the first output image
private  ij.ImagePlus output_ip_2
          reference to the second output image
private  int outputLevel
          flag to specify the level of resolution in the output
private  double[][] P11_SourceToTarget
          regularization P11 (source to target) matrix
private  double[][] P11_TargetToSource
          regularization P11 (target to source) matrix
private  double[][] P12_SourceToTarget
          regularization P12 (source to target) matrix
private  double[][] P12_TargetToSource
          regularization P12 (target to source) matrix
private  double[][] P22_SourceToTarget
          regularization P22 (source to target) matrix
private  double[][] P22_TargetToSource
          regularization P22 (target to source) matrix
private  double partialDirectConsitencyError
          direct consistency error for the current iteration
private  double partialDirectLandmarkError
          direct landmarks error for the current iteration
private  double partialDirectRegularizationError
          direct regularization error for the current iteration
private  double partialDirectSimilarityError
          direct similarity error for the current iteration
private  double partialInverseConsitencyError
          inverse consistency error for the current iteration
private  double partialInverseLandmarkError
          inverse landmarks error for the current iteration
private  double partialInverseRegularizationError
          inverse regularization error for the current iteration
private  double partialInverseSimilarityError
          inverse similarity error for the current iteration
private  boolean PYRAMID
          pyramid flag
private  boolean showMarquardtOptim
          flag to show the optimizer
private  BSplineModel source
          pointer to the source image model
private  double[][] sourceAffineMatrix
          initial affine matrix for the source image
private  int sourceCurrentHeight
          source image current height
private  int sourceCurrentWidth
          source image current width
private  double sourceFactorHeight
          height factor in the source image
private  double sourceFactorWidth
          width factor in the source image
private  int sourceHeight
          source image height
private  ij.ImagePlus sourceImp
          pointer to the source image representation
private  Mask sourceMsk
          pointer to the source mask
private  PointHandler sourcePh
          pointer to the source point handler
private  int sourceWidth
          source image width
private  double stopThreshold
          stopping threshold
private  BSplineModel swxSourceToTarget
          image model to interpolate the cxSourceToTarget coefficients
private  BSplineModel swxTargetToSource
          image model to interpolate the cxTargetToSource coefficients
private  BSplineModel swySourceToTarget
          image model to interpolate the cySourceToTarget coefficients
private  BSplineModel swyTargetToSource
          image model to interpolate the cyTargetToSource coefficients
private  BSplineModel target
          pointer to the target image model
private  double[][] targetAffineMatrix
          initial affine matrix for the target image
private  int targetCurrentHeight
          target image current height
private  int targetCurrentWidth
          target image current width
private  double targetFactorHeight
          height factor in the target image
private  double targetFactorWidth
          width factor in the target image
private  int targetHeight
          target image height
private  ij.ImagePlus targetImp
          pointer to the target image representation
private  Mask targetMsk
          pointer to the target mask
private  PointHandler targetPh
          pointer to the target point handler
private  int targetWidth
          source image width
private  int transformationSplineDegree
          degree of the B-splines involved in the transformation
 
Constructor Summary
Transformation(ij.ImagePlus sourceImp, ij.ImagePlus targetImp, BSplineModel source, BSplineModel target, PointHandler sourcePh, PointHandler targetPh, Mask sourceMsk, Mask targetMsk, double[][] sourceAffineMatrix, double[][] targetAffineMatrix, int min_scale_deformation, int max_scale_deformation, int min_scale_image, double divWeight, double curlWeight, double landmarkWeight, double imageWeight, double consistencyWeight, double stopThreshold, int outputLevel, boolean showMarquardtOptim, int accurate_mode, java.lang.String fn_tnf_1, java.lang.String fn_tnf_2, ij.ImagePlus output_ip_1, ij.ImagePlus output_ip_2, MainDialog dialog)
          Create an instance of Transformation.
Transformation(ij.ImagePlus sourceImp, ij.ImagePlus targetImp, BSplineModel source, BSplineModel target, PointHandler sourcePh, PointHandler targetPh, Mask sourceMsk, Mask targetMsk, double[][] sourceAffineMatrix, double[][] targetAffineMatrix, int min_scale_deformation, int max_scale_deformation, int min_scale_image, double divWeight, double curlWeight, double landmarkWeight, double imageWeight, double consistencyWeight, double stopThreshold, int outputLevel, boolean showMarquardtOptim, int accurate_mode, java.lang.String fn_tnf_1, java.lang.String fn_tnf_2, ij.ImagePlus output_ip_1, ij.ImagePlus output_ip_2, MainDialog dialog, ij.process.ImageProcessor originalSourceIP, ij.process.ImageProcessor originalTargetIP)
          Create an instance of Transformation.
 
Method Summary
private  ij.ImagePlus applyTransformationMultiThread(int intervals, double[][] cx, double[][] cy, boolean bIsReverse)
          Apply the final transformation (multi-thread version).
private  void build_Matrix_B(int intervals, int K, double[][] B, boolean bIsReverse)
          Build the matrix for the landmark interpolation.
private  double build_Matrix_R_computeIntegral_aa(double x0, double xF, double s1, double s2, double h, int q1, int q2)
          Compute the following integral
private  double build_matrix_R_computeIntegral_BB(double x0, double xF, double s1, double s2, double h, int n1, int n2)
          Compute the following integral
private  double build_matrix_R_computeIntegral_xx(double x0, double xF, double s1, double s2, int q1, int q2)
          
private  void build_Matrix_R_geteta(double[][] etaq1q2, int q1, int q2, int dim, int intervals)
          Build matrix R, get eta.
private  boolean build_Matrix_R_getetaindex(int ki1, int ki2, int intervals, int[] ip)
          Build matrix R, get eta index.
private  void build_Matrix_Rq1q2(int intervals, double weight, int q1, int q2, double[][] R, boolean bIsReverse)
          Build matrix Rq1q2.
private  void build_Matrix_Rq1q2q3q4(int intervals, double weight, int q1, int q2, int q3, int q4, double[][] R, boolean bIsReverse)
          Build matrix Rq1q2q3q4.
private  void buildRegularizationTemporary(int intervals, boolean bIsReverse)
          Build regularization temporary.
private  double[][] computeAffineMatrix(boolean bIsReverse)
          Compute the affine matrix.
private  void computeAffineResidues(double[][] affineMatrix, double[] dx, double[] dy, boolean bIsReverse)
          Deprecated.  
private  boolean computeCoefficientsScale(int intervals, double[] dx, double[] dy, double[][] cx, double[][] cy, boolean bIsReverse)
          Compute the coefficients at this scale.
private  boolean computeCoefficientsScaleWithRegularization(int intervals, double[] dx, double[] dy, double[][] cx, double[][] cy, boolean bIsReverse)
          Compute the coefficients scale with regularization.
private  void computeDeformation(int intervals, double[][] cx, double[][] cy, double[][] transformation_x, double[][] transformation_y, boolean bIsReverse)
          Compute the deformation.
private  void computeDeformationGrid(int intervals, double[][] cx, double[][] cy, ij.ImageStack is, boolean bIsReverse)
          Compute and draw the final deformation grid.
private  void computeDeformationVectors(int intervals, double[][] cx, double[][] cy, ij.ImageStack is, boolean bIsReverse)
          Compute and draw the final deformation vectors.
private  void computeInitialResidues(double[] dx, double[] dy, boolean bIsReverse)
          Deprecated.  
private  double[][] computeRotationMatrix(boolean bIsReverse)
          Compute the rotation matrix.
private  void computeScaleResidues(int intervals, double[][] cx, double[][] cy, double[] dx, double[] dy, boolean bIsReverse)
          Deprecated.  
private  void computeTotalWorkload()
          This code is an excerpt from doRegistration() to compute the exact number of steps.
 void doRegistration()
          Registration method.
 void doUnidirectionalRegistration()
          Unidirectional registration method.
private  double energyFunction(double[] c, int intervals, double[] grad, boolean only_image, boolean show_error)
          Energy function to be minimized by the optimizer in the bidirectional case.
private  double evaluateConsistency(double[] c_direct, double[] c_inverse, int intervals, double[] grad)
          Deprecated.  
private  double evaluateConsistency(int intervals, double[] grad)
          Deprecated.  
private  double evaluateConsistencyMultiThread(int intervals, double[] grad)
          Calculate the geometric error between the source-target and target-source deformations.
 double evaluateImageSimilarity(boolean bIsReverse)
          Evaluate the similarity between the images.
private  double evaluatePartialEnergy(double[] c, int intervals, double[] grad_direct, double[] grad_inverse, boolean only_image, boolean show_error, boolean bIsReverse)
          Evaluate the energy function in one direction (direct or inverse) and calculates its gradient.
private  double evaluateSimilarity(double[] c, int intervals, double[] grad, boolean only_image, boolean show_error, boolean bIsReverse)
          Deprecated.  
private  double evaluateSimilarityMultiThread(double[] c, int intervals, double[] grad, boolean only_image, boolean bIsReverse)
          Evaluate the similarity between the source and the target images but also the transformation regularization and and landmarks energy term if necessary.
 void getDeformation(double[][] transformation_x, double[][] transformation_y, boolean bIsReverse)
          Get the deformation from the corresponding coefficients.
 double[][] getDirectDeformationCoefficientsX()
          Get the direct deformation X coefficients.
 double[][] getDirectDeformationCoefficientsY()
          Get the direct deformation Y coefficients.
 ij.ImagePlus getDirectResults()
          Get direct results window
 int getIntervals()
          Get the current number of intervals between B-spline coefficients.
 double[][] getInverseDeformationCoefficientsX()
          Get the inverse deformation X coefficients.
 double[][] getInverseDeformationCoefficientsY()
          Get the inverse deformation Y coefficients.
 ij.ImagePlus getInverseResults()
          Get inverse results window
private  void Marquardt_it(double[] x, boolean[] optimize, double[] gradient, double[] Hessian, double lambda)
          In this function the system (H+lambda*Diag(H))*update=gradient is solved for update.
private  double optimizeCoeffs(int intervals, double thChangef, double[][] cxTargetToSource, double[][] cyTargetToSource)
          Optimize the B-spline coefficients (unidirectional method).
private  double optimizeCoeffs(int intervals, double thChangef, double[][] cxTargetToSource, double[][] cyTargetToSource, double[][] cxSourceToTarget, double[][] cySourceToTarget)
          Optimize the B-spline coefficients (bidirectional method).
private  double[][] propagateCoeffsToNextLevel(int intervals, double[][] c, double expansionFactor)
          Propagate deformation coefficients to the next level.
 void saveDirectTransformation()
          Save source transformation.
 void saveInverseTransformation()
          Save target transformation.
private  void saveTransformation(int intervals, double[][] cx, double[][] cy, boolean bIsReverse)
          Save the transformation.
 void showDirectResults()
          Show the direct transformation results(multi-thread version).
 void showInverseResults()
          Show the inverse transformation results (multi-thread version).
private  void showTransformation(int intervals, double[][] cx, double[][] cy, boolean bIsReverse)
          Deprecated.  
private  void showTransformationMultiThread(int intervals, double[][] cx, double[][] cy, boolean bIsReverse)
          Show the transformation (multi-thread version).
 void transform(double u, double v, double[] xyF, boolean bIsReverse)
          Apply the current transformation to a given point.
private  void update_current_output(double[] c, int intervals, boolean bIsReverse)
          Method to update a current output (multi-thread).
private  void update_outputs(double[] c, int intervals)
          Method to update both current outputs (source-target and target-source).
private  double[] xWeight(double x, int xIntervals, boolean extended, boolean bIsReverse)
          Calculate the cubic B-spline x weight.
private  double[] yWeight(double y, int yIntervals, boolean extended, boolean bIsReverse)
          Calculate the cubic B-spline y weight.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FLT_EPSILON

private final double FLT_EPSILON
float epsilon


PYRAMID

private final boolean PYRAMID
pyramid flag

See Also:
Constant Field Values

ORIGINAL

private final boolean ORIGINAL
original flag

See Also:
Constant Field Values

transformationSplineDegree

private final int transformationSplineDegree
degree of the B-splines involved in the transformation

See Also:
Constant Field Values

output_ip_1

private ij.ImagePlus output_ip_1
reference to the first output image


output_ip_2

private ij.ImagePlus output_ip_2
reference to the second output image


dialog

private MainDialog dialog
pointer to the dialog of the bUnwarpJ interface


sourceImp

private ij.ImagePlus sourceImp
pointer to the source image representation


targetImp

private ij.ImagePlus targetImp
pointer to the target image representation


source

private BSplineModel source
pointer to the source image model


target

private BSplineModel target
pointer to the target image model


originalSourceIP

private ij.process.ImageProcessor originalSourceIP
initial source image processor


originalTargetIP

private ij.process.ImageProcessor originalTargetIP
initial target image processor


sourcePh

private PointHandler sourcePh
pointer to the source point handler


targetPh

private PointHandler targetPh
pointer to the target point handler


sourceMsk

private Mask sourceMsk
pointer to the source mask


targetMsk

private Mask targetMsk
pointer to the target mask


sourceAffineMatrix

private double[][] sourceAffineMatrix
initial affine matrix for the source image


targetAffineMatrix

private double[][] targetAffineMatrix
initial affine matrix for the target image


sourceHeight

private int sourceHeight
source image height


sourceWidth

private int sourceWidth
source image width


targetHeight

private int targetHeight
target image height


targetWidth

private int targetWidth
source image width


targetCurrentHeight

private int targetCurrentHeight
target image current height


targetCurrentWidth

private int targetCurrentWidth
target image current width


sourceCurrentHeight

private int sourceCurrentHeight
source image current height


sourceCurrentWidth

private int sourceCurrentWidth
source image current width


targetFactorHeight

private double targetFactorHeight
height factor in the target image


targetFactorWidth

private double targetFactorWidth
width factor in the target image


sourceFactorHeight

private double sourceFactorHeight
height factor in the source image


sourceFactorWidth

private double sourceFactorWidth
width factor in the source image


partialDirectSimilarityError

private double partialDirectSimilarityError
direct similarity error for the current iteration


partialDirectRegularizationError

private double partialDirectRegularizationError
direct regularization error for the current iteration


partialDirectLandmarkError

private double partialDirectLandmarkError
direct landmarks error for the current iteration


partialDirectConsitencyError

private double partialDirectConsitencyError
direct consistency error for the current iteration


finalDirectSimilarityError

private double finalDirectSimilarityError
direct similarity error at the end of the registration


finalDirectRegularizationError

private double finalDirectRegularizationError
direct regularization error at the end of the registration


finalDirectLandmarkError

private double finalDirectLandmarkError
direct landmarks error at the end of the registration


finalDirectConsistencyError

private double finalDirectConsistencyError
direct consistency error at the end of the registration


partialInverseSimilarityError

private double partialInverseSimilarityError
inverse similarity error for the current iteration


partialInverseRegularizationError

private double partialInverseRegularizationError
inverse regularization error for the current iteration


partialInverseLandmarkError

private double partialInverseLandmarkError
inverse landmarks error for the current iteration


partialInverseConsitencyError

private double partialInverseConsitencyError
inverse consistency error for the current iteration


finalInverseSimilarityError

private double finalInverseSimilarityError
inverse similarity error at the end of the registration


finalInverseRegularizationError

private double finalInverseRegularizationError
inverse regularization error at the end of the registration


finalInverseLandmarkError

private double finalInverseLandmarkError
inverse landmarks error at the end of the registration


finalInverseConsistencyError

private double finalInverseConsistencyError
inverse consistency error at the end of the registration


min_scale_deformation

private int min_scale_deformation
minimum scale deformation


max_scale_deformation

private int max_scale_deformation
maximum scale deformation


min_scale_image

private int min_scale_image
minimum scale image


outputLevel

private int outputLevel
flag to specify the level of resolution in the output


showMarquardtOptim

private boolean showMarquardtOptim
flag to show the optimizer


divWeight

private double divWeight
divergence weight


curlWeight

private double curlWeight
curl weight


landmarkWeight

private double landmarkWeight
landmark weight


imageWeight

private double imageWeight
weight for image similarity


consistencyWeight

private double consistencyWeight
weight for the deformations consistency


stopThreshold

private double stopThreshold
stopping threshold


accurate_mode

private int accurate_mode
level of accuracy


fn_tnf_1

private java.lang.String fn_tnf_1
direct transformation file name


fn_tnf_2

private java.lang.String fn_tnf_2
inverse transformation file name


intervals

private int intervals
number of intervals to place B-spline coefficients


cxSourceToTarget

private double[][] cxSourceToTarget
x- B-spline coefficients keeping the transformation from source to target


cySourceToTarget

private double[][] cySourceToTarget
y- B-spline coefficients keeping the transformation from source to target


cxTargetToSource

private double[][] cxTargetToSource
x- B-spline coefficients keeping the transformation from target to source


cyTargetToSource

private double[][] cyTargetToSource
y- B-spline coefficients keeping the transformation from target to source


swxSourceToTarget

private BSplineModel swxSourceToTarget
image model to interpolate the cxSourceToTarget coefficients


swySourceToTarget

private BSplineModel swySourceToTarget
image model to interpolate the cySourceToTarget coefficients


swxTargetToSource

private BSplineModel swxTargetToSource
image model to interpolate the cxTargetToSource coefficients


swyTargetToSource

private BSplineModel swyTargetToSource
image model to interpolate the cyTargetToSource coefficients


P11_SourceToTarget

private double[][] P11_SourceToTarget
regularization P11 (source to target) matrix


P22_SourceToTarget

private double[][] P22_SourceToTarget
regularization P22 (source to target) matrix


P12_SourceToTarget

private double[][] P12_SourceToTarget
regularization P12 (source to target) matrix


P11_TargetToSource

private double[][] P11_TargetToSource
regularization P11 (target to source) matrix


P22_TargetToSource

private double[][] P22_TargetToSource
regularization P22 (target to source) matrix


P12_TargetToSource

private double[][] P12_TargetToSource
regularization P12 (target to source) matrix

Constructor Detail

Transformation

public Transformation(ij.ImagePlus sourceImp,
                      ij.ImagePlus targetImp,
                      BSplineModel source,
                      BSplineModel target,
                      PointHandler sourcePh,
                      PointHandler targetPh,
                      Mask sourceMsk,
                      Mask targetMsk,
                      double[][] sourceAffineMatrix,
                      double[][] targetAffineMatrix,
                      int min_scale_deformation,
                      int max_scale_deformation,
                      int min_scale_image,
                      double divWeight,
                      double curlWeight,
                      double landmarkWeight,
                      double imageWeight,
                      double consistencyWeight,
                      double stopThreshold,
                      int outputLevel,
                      boolean showMarquardtOptim,
                      int accurate_mode,
                      java.lang.String fn_tnf_1,
                      java.lang.String fn_tnf_2,
                      ij.ImagePlus output_ip_1,
                      ij.ImagePlus output_ip_2,
                      MainDialog dialog)
Create an instance of Transformation.

Parameters:
sourceImp - image representation for the source
targetImp - image representation for the target
source - source image model
target - target image model
sourcePh - point handler for the landmarks in the source image
targetPh - point handler for the landmarks in the target image
sourceMsk - source image mask
targetMsk - target image mask
sourceAffineMatrix - source initial affine matrix
targetAffineMatrix - source initial affine matrix
min_scale_deformation - minimum scale deformation
max_scale_deformation - maximum scale deformation
min_scale_image - minimum image scale
divWeight - divergence weight
curlWeight - curl weight
landmarkWeight - landmark weight
imageWeight - weight for image similarity
consistencyWeight - weight for the deformations consistency
stopThreshold - stopping threshold
outputLevel - flag to specify the level of resolution in the output
showMarquardtOptim - flag to show the optimizer
accurate_mode - level of accuracy
fn_tnf_1 - direct transformation file name
fn_tnf_2 - inverse transformation file name
output_ip_1 - pointer to the first output image
output_ip_2 - pointer to the second output image
dialog - pointer to the dialog of the bUnwarpJ interface

Transformation

public Transformation(ij.ImagePlus sourceImp,
                      ij.ImagePlus targetImp,
                      BSplineModel source,
                      BSplineModel target,
                      PointHandler sourcePh,
                      PointHandler targetPh,
                      Mask sourceMsk,
                      Mask targetMsk,
                      double[][] sourceAffineMatrix,
                      double[][] targetAffineMatrix,
                      int min_scale_deformation,
                      int max_scale_deformation,
                      int min_scale_image,
                      double divWeight,
                      double curlWeight,
                      double landmarkWeight,
                      double imageWeight,
                      double consistencyWeight,
                      double stopThreshold,
                      int outputLevel,
                      boolean showMarquardtOptim,
                      int accurate_mode,
                      java.lang.String fn_tnf_1,
                      java.lang.String fn_tnf_2,
                      ij.ImagePlus output_ip_1,
                      ij.ImagePlus output_ip_2,
                      MainDialog dialog,
                      ij.process.ImageProcessor originalSourceIP,
                      ij.process.ImageProcessor originalTargetIP)
Create an instance of Transformation.

Parameters:
sourceImp - image representation for the source
targetImp - image representation for the target
source - source image model
target - target image model
sourcePh - point handler for the landmarks in the source image
targetPh - point handler for the landmarks in the target image
sourceMsk - source image mask
targetMsk - target image mask
sourceAffineMatrix - source initial affine matrix
targetAffineMatrix - source initial affine matrix
min_scale_deformation - minimum scale deformation
max_scale_deformation - maximum scale deformation
min_scale_image - minimum image scale
divWeight - divergence weight
curlWeight - curl weight
landmarkWeight - landmark weight
imageWeight - weight for image similarity
consistencyWeight - weight for the deformations consistency
stopThreshold - stopping threshold
outputLevel - flag to specify the level of resolution in the output
showMarquardtOptim - flag to show the optimizer
accurate_mode - level of accuracy
fn_tnf_1 - direct transformation file name
fn_tnf_2 - inverse transformation file name
output_ip_1 - pointer to the first output image
output_ip_2 - pointer to the second output image
dialog - pointer to the dialog of the bUnwarpJ interface
Method Detail

doRegistration

public void doRegistration()
Registration method. It applies the consistent and elastic registration algorithm to the selected source and target images.


doUnidirectionalRegistration

public void doUnidirectionalRegistration()
Unidirectional registration method. It applies unidirectional elastic registration to the selected source and target images.


evaluateImageSimilarity

public double evaluateImageSimilarity(boolean bIsReverse)
Evaluate the similarity between the images.

Parameters:
bIsReverse - determines the transformation direction (source-target=TRUE or target-source=FALSE)
Returns:
image similarity value

getDeformation

public void getDeformation(double[][] transformation_x,
                           double[][] transformation_y,
                           boolean bIsReverse)
Get the deformation from the corresponding coefficients.

Parameters:
transformation_x - matrix to store the x- transformation
transformation_y - matrix to store the y- transformation
bIsReverse - flag to choose the deformation coefficients (source-target=TRUE or target-source=FALSE)

getDirectDeformationCoefficientsX

public double[][] getDirectDeformationCoefficientsX()
Get the direct deformation X coefficients.

Returns:
coefficients array

getDirectDeformationCoefficientsY

public double[][] getDirectDeformationCoefficientsY()
Get the direct deformation Y coefficients.

Returns:
coefficients array

getInverseDeformationCoefficientsX

public double[][] getInverseDeformationCoefficientsX()
Get the inverse deformation X coefficients.

Returns:
coefficients array

getInverseDeformationCoefficientsY

public double[][] getInverseDeformationCoefficientsY()
Get the inverse deformation Y coefficients.

Returns:
coefficients array

getIntervals

public int getIntervals()
Get the current number of intervals between B-spline coefficients.

Returns:
coefficients array

transform

public void transform(double u,
                      double v,
                      double[] xyF,
                      boolean bIsReverse)
Apply the current transformation to a given point.

Parameters:
u - input, x- point coordinate
v - input, y- point coordinate
xyF - output, transformed point
bIsReverse - flag to decide the transformation direction (direct-inverse) (source-target=TRUE or target-source=FALSE)

build_Matrix_B

private void build_Matrix_B(int intervals,
                            int K,
                            double[][] B,
                            boolean bIsReverse)
Build the matrix for the landmark interpolation.

Parameters:
intervals - Intervals in the deformation
K - Number of landmarks
B - System matrix of the landmark interpolation
bIsReverse - determines the transformation direction (source-target=TRUE or target-source=FALSE)

build_Matrix_Rq1q2

private void build_Matrix_Rq1q2(int intervals,
                                double weight,
                                int q1,
                                int q2,
                                double[][] R,
                                boolean bIsReverse)
Build matrix Rq1q2.


build_Matrix_Rq1q2q3q4

private void build_Matrix_Rq1q2q3q4(int intervals,
                                    double weight,
                                    int q1,
                                    int q2,
                                    int q3,
                                    int q4,
                                    double[][] R,
                                    boolean bIsReverse)
Build matrix Rq1q2q3q4.


build_Matrix_R_computeIntegral_aa

private double build_Matrix_R_computeIntegral_aa(double x0,
                                                 double xF,
                                                 double s1,
                                                 double s2,
                                                 double h,
                                                 int q1,
                                                 int q2)
Compute the following integral

           xF d^q1      3  x        d^q2    3  x
  integral    -----   B  (--- - s1) ----- B  (--- - s2) dx
           x0 dx^q1        h        dx^q2      h


build_matrix_R_computeIntegral_BB

private double build_matrix_R_computeIntegral_BB(double x0,
                                                 double xF,
                                                 double s1,
                                                 double s2,
                                                 double h,
                                                 int n1,
                                                 int n2)
Compute the following integral
           xF   n1  x          n2  x
  integral     B  (--- - s1)  B  (--- - s2) dx
           x0       h              h


build_matrix_R_computeIntegral_xx

private double build_matrix_R_computeIntegral_xx(double x0,
                                                 double xF,
                                                 double s1,
                                                 double s2,
                                                 int q1,
                                                 int q2)

 Computation of the integral:
             xF          q1       q2
    integral       (x-s1)   (x-s2)     dx
             x0          +        +


build_Matrix_R_geteta

private void build_Matrix_R_geteta(double[][] etaq1q2,
                                   int q1,
                                   int q2,
                                   int dim,
                                   int intervals)
Build matrix R, get eta.


build_Matrix_R_getetaindex

private boolean build_Matrix_R_getetaindex(int ki1,
                                           int ki2,
                                           int intervals,
                                           int[] ip)
Build matrix R, get eta index.


buildRegularizationTemporary

private void buildRegularizationTemporary(int intervals,
                                          boolean bIsReverse)
Build regularization temporary.

Parameters:
intervals - intervals in the deformation
bIsReverse - determines the transformation direction (source-target=TRUE or target-source=FALSE)

computeAffineMatrix

private double[][] computeAffineMatrix(boolean bIsReverse)
Compute the affine matrix.

Parameters:
bIsReverse - determines the transformation direction (source-target=TRUE or target-source=FALSE)

computeAffineResidues

private void computeAffineResidues(double[][] affineMatrix,
                                   double[] dx,
                                   double[] dy,
                                   boolean bIsReverse)
Deprecated. 

Compute the affine residues for the landmarks.

NOTE: The output vectors should be already resized

Parameters:
affineMatrix - Input
dx - Output, difference in x for each landmark
dy - Output, difference in y for each landmark
bIsReverse - determines the transformation direction (source-target=TRUE or target-source=FALSE)

computeCoefficientsScale

private boolean computeCoefficientsScale(int intervals,
                                         double[] dx,
                                         double[] dy,
                                         double[][] cx,
                                         double[][] cy,
                                         boolean bIsReverse)
Compute the coefficients at this scale.

Parameters:
intervals - input, number of intervals at this scale
dx - input, x residue so far
dy - input, y residue so far
cx - output, x coefficients for splines
cy - output, y coefficients for splines
bIsReverse - determines the transformation direction (source-target=TRUE or target-source=FALSE)
Returns:
under-constrained flag

computeCoefficientsScaleWithRegularization

private boolean computeCoefficientsScaleWithRegularization(int intervals,
                                                           double[] dx,
                                                           double[] dy,
                                                           double[][] cx,
                                                           double[][] cy,
                                                           boolean bIsReverse)
Compute the coefficients scale with regularization.

Parameters:
intervals - input, number of intervals at this scale
dx - input, x residue so far
dy - input, y residue so far
cx - output, x coefficients for splines
cy - output, y coefficients for splines
bIsReverse - determines the transformation direction (source-target=TRUE or target-source=FALSE)
Returns:
under-constrained flag

computeInitialResidues

private void computeInitialResidues(double[] dx,
                                    double[] dy,
                                    boolean bIsReverse)
Deprecated. 

Compute the initial residues for the landmarks.

NOTE: The output vectors should be already resized

Parameters:
dx - output, difference in x for each landmark
dy - output, difference in y for each landmark
bIsReverse - determines the transformation direction (source-target=TRUE or target-source=FALSE)

computeDeformation

private void computeDeformation(int intervals,
                                double[][] cx,
                                double[][] cy,
                                double[][] transformation_x,
                                double[][] transformation_y,
                                boolean bIsReverse)
Compute the deformation.

Parameters:
intervals - input, number of intervals
cx - input, X B-spline coefficients
cy - input, Y B-spline coefficients
transformation_x - output, X transformation map
transformation_y - output, Y transformation map
bIsReverse - determines the transformation direction (source-target=TRUE or target-source=FALSE)

computeRotationMatrix

private double[][] computeRotationMatrix(boolean bIsReverse)
Compute the rotation matrix.

Parameters:
bIsReverse - determines the transformation direction (source-target=TRUE or target-source=FALSE)
Returns:
rotation matrix

computeScaleResidues

private void computeScaleResidues(int intervals,
                                  double[][] cx,
                                  double[][] cy,
                                  double[] dx,
                                  double[] dy,
                                  boolean bIsReverse)
Deprecated. 

Compute the scale residues.

NOTE: At the input dx and dy have the residues so far, at the output these residues are modified to account for the model at the new scale

Parameters:
intervals - input, number of intervals
cx - input, X B-spline coefficients
cy - input, Y B-spline coefficients
dx - input/output, X residues
dy - input/output, Y residues
bIsReverse - determines the transformation direction (target-source=FALSE or source-target=TRUE)

computeTotalWorkload

private void computeTotalWorkload()
This code is an excerpt from doRegistration() to compute the exact number of steps.


evaluateConsistency

private double evaluateConsistency(int intervals,
                                   double[] grad)
Deprecated. 

Calculate the geometric error between the source-target and target-source deformations (the corresponding coefficients are assumed to be at swxTargetToSource, swyTargetToSource, swxSourceToTarget and swySourceToTarget).

Parameters:
intervals - Input: Number of intervals for the deformation
grad - Output: Gradient of the function
Returns:
geometric error between the source-target and target-source deformations.

evaluateConsistency

private double evaluateConsistency(double[] c_direct,
                                   double[] c_inverse,
                                   int intervals,
                                   double[] grad)
Deprecated. 

Calculate the geometric error between the source-target and target-source deformations.

Parameters:
c_direct - Input: Direct deformation coefficients
c_inverse - Input: Inverse deformation coefficients
intervals - Input: Number of intervals for the deformation
grad - Output: Gradient of the function
Returns:
error function value

energyFunction

private double energyFunction(double[] c,
                              int intervals,
                              double[] grad,
                              boolean only_image,
                              boolean show_error)
Energy function to be minimized by the optimizer in the bidirectional case.

Parameters:
c - Input: Deformation coefficients
intervals - Input: Number of intervals for the deformation
grad - Output: Gradient of the function
only_image - Input: if true, only the image term is considered and not the regularization
show_error - Input: if true, an image is shown with the error
Returns:
value of the energy function for these deformation coefficients

evaluateSimilarity

private double evaluateSimilarity(double[] c,
                                  int intervals,
                                  double[] grad,
                                  boolean only_image,
                                  boolean show_error,
                                  boolean bIsReverse)
Deprecated. 

Evaluate the similarity between the source and the target images but also the transformation regularization and and landmarks energy term if necessary.

Parameters:
c - Input: Deformation coefficients
intervals - Input: Number of intervals for the deformation
grad - Output: Gradient of the similarity
only_image - Input: if true, only the image term is considered and not the regularization
show_error - Input: if true, an image is shown with the error
bIsReverse - Input: flag to determine the transformation direction (target-source=FALSE or source-target=TRUE)
Returns:
images similarity value

evaluatePartialEnergy

private double evaluatePartialEnergy(double[] c,
                                     int intervals,
                                     double[] grad_direct,
                                     double[] grad_inverse,
                                     boolean only_image,
                                     boolean show_error,
                                     boolean bIsReverse)
Evaluate the energy function in one direction (direct or inverse) and calculates its gradient.

Energy function:

E = w_i * E_similarity + w_l * E_landmarks + (w_r * E_rotational + w_d * E_divergence) + w_c * E_consistency

Parameters:
c - Input: Deformation coefficients
intervals - Input: Number of intervals for the deformation
grad_direct - Output: Gradient of the energy function (direct direction)
grad_inverse - Output: Gradient of the energy function (inverse direction)
only_image - Input: if true, only the image term is considered and not the regularization
show_error - Input: if true, an image is shown with the error
bIsReverse - Input: flag to determine the transformation direction (target-source=FALSE or source-target=TRUE)
Returns:
images similarity value

Marquardt_it

private void Marquardt_it(double[] x,
                          boolean[] optimize,
                          double[] gradient,
                          double[] Hessian,
                          double lambda)
In this function the system (H+lambda*Diag(H))*update=gradient is solved for update. H is the hessian of the function f, gradient is the gradient of the function f, Diag(H) is a matrix with the diagonal of H.


optimizeCoeffs

private double optimizeCoeffs(int intervals,
                              double thChangef,
                              double[][] cxTargetToSource,
                              double[][] cyTargetToSource,
                              double[][] cxSourceToTarget,
                              double[][] cySourceToTarget)
Optimize the B-spline coefficients (bidirectional method).

Parameters:
intervals - number of intervals in the deformation
thChangef -
cxTargetToSource - x- B-spline coefficients storing the target to source deformation
cyTargetToSource - y- B-spline coefficients storing the target to source deformation
cxSourceToTarget - x- B-spline coefficients storing the source to target deformation
cySourceToTarget - y- B-spline coefficients storing the source to target deformation
Returns:
energy function value

optimizeCoeffs

private double optimizeCoeffs(int intervals,
                              double thChangef,
                              double[][] cxTargetToSource,
                              double[][] cyTargetToSource)
Optimize the B-spline coefficients (unidirectional method).

Parameters:
intervals - number of intervals in the deformation
thChangef -
cxTargetToSource - x- B-spline coefficients storing the target to source deformation
cyTargetToSource - y- B-spline coefficients storing the target to source deformation
Returns:
energy function value

propagateCoeffsToNextLevel

private double[][] propagateCoeffsToNextLevel(int intervals,
                                              double[][] c,
                                              double expansionFactor)
Propagate deformation coefficients to the next level.

Parameters:
intervals - number of intervals in the deformation
c - B-spline coefficients
expansionFactor - due to the change of size in the represented image
Returns:
propagated coefficients

saveDirectTransformation

public void saveDirectTransformation()
Save source transformation. GUI mode.


saveInverseTransformation

public void saveInverseTransformation()
Save target transformation. GUI mode.


saveTransformation

private void saveTransformation(int intervals,
                                double[][] cx,
                                double[][] cy,
                                boolean bIsReverse)
Save the transformation.

Parameters:
intervals - number of intervals in the deformation
cx - x- deformation coefficients
cy - y- deformation coefficients
bIsReverse - flat to determine the transformation direction

computeDeformationGrid

private void computeDeformationGrid(int intervals,
                                    double[][] cx,
                                    double[][] cy,
                                    ij.ImageStack is,
                                    boolean bIsReverse)
Compute and draw the final deformation grid.

Parameters:
intervals - number of intervals in the deformation
cx - x- deformation coefficients
cy - y- deformation coefficients
is - image stack where we want to show the deformation grid
bIsReverse - flag to determine the transformation direction (target-source=FALSE or source-target=TRUE)

computeDeformationVectors

private void computeDeformationVectors(int intervals,
                                       double[][] cx,
                                       double[][] cy,
                                       ij.ImageStack is,
                                       boolean bIsReverse)
Compute and draw the final deformation vectors.

Parameters:
intervals - number of intervals in the deformation
cx - x- deformation coefficients
cy - y- deformation coefficients
is - image stack where we want to show the deformation vectors
bIsReverse - flag to determine the transformation direction (target-source=FALSE or source-target=TRUE)

showDirectResults

public void showDirectResults()
Show the direct transformation results(multi-thread version).


showInverseResults

public void showInverseResults()
Show the inverse transformation results (multi-thread version).


showTransformationMultiThread

private void showTransformationMultiThread(int intervals,
                                           double[][] cx,
                                           double[][] cy,
                                           boolean bIsReverse)
Show the transformation (multi-thread version).

Parameters:
intervals - number of intervals in the deformation
cx - x- deformation coefficients
cy - y- deformation coefficients
bIsReverse - flag to determine the transformation direction (target-source=FALSE or source-target=TRUE)

getDirectResults

public ij.ImagePlus getDirectResults()
Get direct results window

Returns:
direct registration results

getInverseResults

public ij.ImagePlus getInverseResults()
Get inverse results window

Returns:
inverse registration results

applyTransformationMultiThread

private ij.ImagePlus applyTransformationMultiThread(int intervals,
                                                    double[][] cx,
                                                    double[][] cy,
                                                    boolean bIsReverse)
Apply the final transformation (multi-thread version).

Parameters:
intervals - number of intervals in the deformation
cx - x- deformation coefficients
cy - y- deformation coefficients
bIsReverse - flag to determine the transformation direction (target-source=FALSE or source-target=TRUE)
Returns:
output images (depending on the output level)

showTransformation

private void showTransformation(int intervals,
                                double[][] cx,
                                double[][] cy,
                                boolean bIsReverse)
Deprecated. 

Show the transformation (calculating entire transformation tables).

Parameters:
intervals - number of intervals in the deformation
cx - x- deformation coefficients
cy - y- deformation coefficients
bIsReverse - flag to determine the transformation direction (target-source=FALSE or source-target=TRUE)

update_outputs

private void update_outputs(double[] c,
                            int intervals)
Method to update both current outputs (source-target and target-source).

Parameters:
c - B-spline coefficients
intervals - number of intervals in the deformation

update_current_output

private void update_current_output(double[] c,
                                   int intervals,
                                   boolean bIsReverse)
Method to update a current output (multi-thread).

Parameters:
c - B-spline coefficients
intervals - number of intervals in the deformation
bIsReverse - flag to decide the deformation direction (source-target, target-source)

xWeight

private double[] xWeight(double x,
                         int xIntervals,
                         boolean extended,
                         boolean bIsReverse)
Calculate the cubic B-spline x weight.

Parameters:
x - x- value
xIntervals - x- number of intervals
extended - extended flat
bIsReverse - flag to determine the transformation direction (target-source=FALSE or source-target=TRUE)
Returns:
weights

yWeight

private double[] yWeight(double y,
                         int yIntervals,
                         boolean extended,
                         boolean bIsReverse)
Calculate the cubic B-spline y weight.

Parameters:
y - y- value
yIntervals - y- number of intervals
extended - extended flat
bIsReverse - flag to determine the transformation direction (target-source=FALSE or source-target=TRUE)
Returns:
weights

evaluateSimilarityMultiThread

private double evaluateSimilarityMultiThread(double[] c,
                                             int intervals,
                                             double[] grad,
                                             boolean only_image,
                                             boolean bIsReverse)
Evaluate the similarity between the source and the target images but also the transformation regularization and and landmarks energy term if necessary. Multi-threading version.

Parameters:
c - Input: Deformation coefficients
intervals - Input: Number of intervals for the deformation
grad - Output: Gradient of the similarity
only_image - Input: if true, only the image term is considered and not the regularization
bIsReverse - Input: flag to determine the transformation direction (target-source=FALSE or source-target=TRUE)
Returns:
images similarity value

evaluateConsistencyMultiThread

private double evaluateConsistencyMultiThread(int intervals,
                                              double[] grad)
Calculate the geometric error between the source-target and target-source deformations. The corresponding coefficients are assumed to be at swxTargetToSource, swyTargetToSource, swxSourceToTarget and swySourceToTarget. Multi-thread version.

Parameters:
intervals - Input: Number of intervals for the deformation
grad - Output: Gradient of the function
Returns:
geometric error between the source-target and target-source deformations.