Class BSplineRegistration2Df
- java.lang.Object
-
- gov.nih.mipav.model.algorithms.registration.BSplineRegistrationBasef
-
- gov.nih.mipav.model.algorithms.registration.BSplineRegistration2Df
-
public class BSplineRegistration2Df extends BSplineRegistrationBasef
This class is used to register a 2D source image to a 2D target image. The images do not have to have the same dimensions, but they must both contain single-channel data. The resulting registered source image has the same dimensions as the input target image. A 2D B-Spline is used to map the coordinates of the registered image to coordinates of the input source image. A separate B-Spline basis is setup for each axis given the number of control points and the degree of the basis functions to use. Each B-Spline is uniform open with control points spaced equally for each dimension. Bilinear interpolation is used to determine which input source image value(s) to assign to the resulting registered source image. The "error" measure between the input target image and the current registered source image is the sum of squared differences, where the root mean squared error is also computed. Control points are moved one at a time by means of gradient descent minimization in order to minimize the error. The gradient is approximated at each control point by means of finite differences. Control points are restricted from moving outside the polygon formed by its 8 neighboring control points.
-
-
Field Summary
Fields Modifier and Type Field Description protected int
m_iNumSamplesSrcX
DOCUMENT ME!protected int
m_iNumSamplesSrcY
DOCUMENT ME!protected int
m_iNumSamplesTrgX
Number of samples in source and target images.protected BSplineLattice2Df
m_kBSpline2D
DOCUMENT ME!protected WildMagic.LibFoundation.Curves.BSplineBasisDiscretef
m_kBSplineBasisX
2D B-Spline basis definitions.protected WildMagic.LibFoundation.Curves.BSplineBasisDiscretef
m_kBSplineBasisY
DOCUMENT ME!(package private) static int[]
m_scControlPointPolygonX
Defines the relative offset in control point indices to the 8 neighboring control points which form a bounding polygon.(package private) static int[]
m_scControlPointPolygonY
DOCUMENT ME!-
Fields inherited from class gov.nih.mipav.model.algorithms.registration.BSplineRegistrationBasef
m_iNumSamplesTrg, m_kImageSrc, m_kImageTrg, m_kRegMeasure, nthreads
-
-
Constructor Summary
Constructors Constructor Description BSplineRegistration2Df(ModelSimpleImage kImageSrc, ModelSimpleImage kImageTrg, WildMagic.LibFoundation.Curves.BSplineBasisf kBasisX, WildMagic.LibFoundation.Curves.BSplineBasisf kBasisY, RegistrationMeasure kRegMeasure)
Create instance to be used for registration.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ModelSimpleImage
createImageDeformation()
Generate an image which contains the deformation value at each sample in the target image as it relates to how the source image is transformed as a result of the registration.ModelSimpleImage
createImageDisplacement()
Generate an image which contains the magnitude of the displacement vector at each sample in the target image as it relates to how the source image is transformed as a result of the registration.ModelSimpleImage[]
createImageSourceMap()
Generate an image the size of the target image in which each sample contains the 2D interpolated point coordinates in the source image which "maps" or is registered with the corresponding point in the target image.BSplineRegistration2Df
createSameMapping(ModelSimpleImage kImageTrg)
Create a new registration with the same mapping as this one and which uses the same source image and the same BSpline basis degree and number of control points.BSplineRegistration2Df
createSameMapping(ModelSimpleImage kImageTrg, WildMagic.LibFoundation.Curves.BSplineBasisf kBasisX, WildMagic.LibFoundation.Curves.BSplineBasisf kBasisY)
Create a new registration with the same mapping as this one and which uses the same source image and a possibly resampled target image, however, this time the BSpline basis degree and/or the number of control points may be different.void
finalize()
Cleanup memory.protected float
getControlPointMaxMoveDist(int iControlX, int iControlY, WildMagic.LibFoundation.Mathematics.Vector2f kRayDirection, float fMaxDesiredDist)
Compute the maximum distance the control point can be moved in the specified direction while keeping the control point relative to its 8 neighboring control points such that "folding" does not occur.protected void
getErrorDeriv(int iControlX, int iControlY, WildMagic.LibFoundation.Mathematics.Vector2f kDeriv)
Computes the derivative of the error function at a control point by approximating with finite differences where the control point is moved small amounts in each orthgonal direction.BSplineLattice2Df
getLattice()
Return access to the 2D discretized B-Spline internally created given the size of tbe input target image, and the specified number of control points and degree of basis function for each B-Spline basis axis.void
minimizeControlPoint(int iControlX, int iControlY, int iMaxSteps, float fStepSize)
Move the specified control point using a gradient descent approach to minimize the error.float
moveControlPoint(int iControlX, int iControlY, WildMagic.LibFoundation.Mathematics.Vector2f kPoint)
Move the control point from its current location to the requested location.protected void
updateControlPointSamples(int iControlX, int iControlY)
Update the registered source image and the computed error as a result of making changes to a single control point.protected void
updateSamples(int iMinX, int iMaxX, int iMinY, int iMaxY)
Update the registered source image and the computed error but only for the specified range of samples.-
Methods inherited from class gov.nih.mipav.model.algorithms.registration.BSplineRegistrationBasef
createIdentityMapControlPoints, getError, getImageSource, getImageTarget
-
-
-
-
Field Detail
-
m_scControlPointPolygonX
static final int[] m_scControlPointPolygonX
Defines the relative offset in control point indices to the 8 neighboring control points which form a bounding polygon. The ordering is counterclockwise.
-
m_scControlPointPolygonY
static final int[] m_scControlPointPolygonY
DOCUMENT ME!
-
m_iNumSamplesSrcX
protected int m_iNumSamplesSrcX
DOCUMENT ME!
-
m_iNumSamplesSrcY
protected int m_iNumSamplesSrcY
DOCUMENT ME!
-
m_iNumSamplesTrgX
protected int m_iNumSamplesTrgX
Number of samples in source and target images.
-
m_kBSpline2D
protected BSplineLattice2Df m_kBSpline2D
DOCUMENT ME!
-
m_kBSplineBasisX
protected WildMagic.LibFoundation.Curves.BSplineBasisDiscretef m_kBSplineBasisX
2D B-Spline basis definitions.
-
m_kBSplineBasisY
protected WildMagic.LibFoundation.Curves.BSplineBasisDiscretef m_kBSplineBasisY
DOCUMENT ME!
-
-
Constructor Detail
-
BSplineRegistration2Df
public BSplineRegistration2Df(ModelSimpleImage kImageSrc, ModelSimpleImage kImageTrg, WildMagic.LibFoundation.Curves.BSplineBasisf kBasisX, WildMagic.LibFoundation.Curves.BSplineBasisf kBasisY, RegistrationMeasure kRegMeasure)
Create instance to be used for registration. Upon construction, the initial state of the registered source image is computed along with the error in comparing it to the reference target image.- Parameters:
kImageSrc
- ModelSimpleImage Input source image which contains properties and data values. Must have either 2 or 3 dimensions where the number of dimensions matches that of the target image.kImageTrg
- ModelSimpleImage Input target image which contains properties and data values. Must have either 2 or 3 dimensions where the number of dimensions matches that of the source image.kBasisX
- BSplineBasisf B-spline basis for X axis which contains the B-spline degree and number of control points.kBasisY
- BSplineBasisf B-spline basis for Y axis which contains the B-spline degree and number of control points.kRegMeasure
- RegistrationMeasure Defines the cost measure for comparing the target image with the registered source image.
-
-
Method Detail
-
createImageDeformation
public ModelSimpleImage createImageDeformation()
Generate an image which contains the deformation value at each sample in the target image as it relates to how the source image is transformed as a result of the registration. The image of interpolated source image coordinates for each target image sample is generated and from that the Jacobian is generated at each sample using finite differences. The deformation value is then the determinant of the Jacobian.- Returns:
- ModelSimpleImage New instance which contains the properties and data for the deformation image. This image has the same dimensions as and corresponds to the sample in the target image.
-
createImageDisplacement
public ModelSimpleImage createImageDisplacement()
Generate an image which contains the magnitude of the displacement vector at each sample in the target image as it relates to how the source image is transformed as a result of the registration. The image of interpolated source image coordinates for each target image sample is generated and the displacement is computed from the source image coordinates for the identity registration transformation.- Returns:
- ModelSimpleImage New instance which contains the properties and data for the deformation image. This image has the same dimensions as and corresponds to the sample in the target image.
-
createImageSourceMap
public ModelSimpleImage[] createImageSourceMap()
Generate an image the size of the target image in which each sample contains the 2D interpolated point coordinates in the source image which "maps" or is registered with the corresponding point in the target image.- Returns:
- ModelSimpleImage[] Array of two ModelSimpleImage instances. The first one contains the x coordinate and the second contains the y coordinate for the map. Each image has the same dimensions which are that of the target image.
-
createSameMapping
public BSplineRegistration2Df createSameMapping(ModelSimpleImage kImageTrg)
Create a new registration with the same mapping as this one and which uses the same source image and the same BSpline basis degree and number of control points. The only thing that changes is that the discrete [0,1] interval is resampled.- Parameters:
kImageTrg
- ModelSimpleImage Resampled target image.- Returns:
- BSplineRegistration2Df New registration of the same source image referenced to the resampled target image.
-
createSameMapping
public BSplineRegistration2Df createSameMapping(ModelSimpleImage kImageTrg, WildMagic.LibFoundation.Curves.BSplineBasisf kBasisX, WildMagic.LibFoundation.Curves.BSplineBasisf kBasisY)
Create a new registration with the same mapping as this one and which uses the same source image and a possibly resampled target image, however, this time the BSpline basis degree and/or the number of control points may be different.- Parameters:
kImageTrg
- ModelSimpleImage Possibly resampled target image.kBasisX
- BSplineBasisf B-spline basis for X axis which contains the B-spline degree and number of control points.kBasisY
- BSplineBasisf B-spline basis for Y axis which contains the B-spline degree and number of control points.- Returns:
- BSplineRegistration2Df New registration of the same source image referenced to the resampled target image.
-
finalize
public void finalize() throws java.lang.Throwable
Cleanup memory.- Overrides:
finalize
in classBSplineRegistrationBasef
- Throws:
java.lang.Throwable
- DOCUMENT ME!
-
getLattice
public BSplineLattice2Df getLattice()
Return access to the 2D discretized B-Spline internally created given the size of tbe input target image, and the specified number of control points and degree of basis function for each B-Spline basis axis.- Returns:
- BSplineLattice2Df Access to 2D discretized B-Spline.
-
minimizeControlPoint
public void minimizeControlPoint(int iControlX, int iControlY, int iMaxSteps, float fStepSize)
Move the specified control point using a gradient descent approach to minimize the error. The gradient descent minimization is performed by sampling the error function at specified intervals. A maximum number of samples is specified, but sampling always terminates when the bounding polygon formed by the 8 neighboring control points is reached.- Parameters:
iControlX
- int Identifies the control point in the 2D lattice.iControlY
- int Identifies the control point in the 2D lattice.iMaxSteps
- int Maximum number of samples of the error function by moving the control point in the direction of the negative gradient.fStepSize
- float Spacing between the samples of the error function by moving the control point in the direction of the negative gradient.
-
moveControlPoint
public float moveControlPoint(int iControlX, int iControlY, WildMagic.LibFoundation.Mathematics.Vector2f kPoint)
Move the control point from its current location to the requested location. The requested location must be inside the polygon formed by its 8 neighboring control points. If not, then a line segment is created between the current and requested locations and the point where this line segment intersects the bounding polygon is found. This point is offset a little along the line segment so that it is just inside the bounding polygon, and this point is taken as the new location for the specified control point.- Parameters:
iControlX
- int Identifies the control point in the 2D lattice.iControlY
- int Identifies the control point in the 2D lattice.kPoint
- Point2f Requested new coordinates for the specified control point.- Returns:
- float The distance between the updated control point position and its position before being modified.
-
getControlPointMaxMoveDist
protected float getControlPointMaxMoveDist(int iControlX, int iControlY, WildMagic.LibFoundation.Mathematics.Vector2f kRayDirection, float fMaxDesiredDist)
Compute the maximum distance the control point can be moved in the specified direction while keeping the control point relative to its 8 neighboring control points such that "folding" does not occur.- Parameters:
iControlX
- int Identifies the control point in the 2D lattice.iControlY
- int Identifies the control point in the 2D lattice.kRayDirection
- Vector2f Direction from the current control point location for finding the distance to the bounding polygon.fMaxDesiredDist
- float Maximum distance along the ray direction that should be considered. At most, the code would consider moving the control point.- Returns:
- float Computed distance.
-
getErrorDeriv
protected void getErrorDeriv(int iControlX, int iControlY, WildMagic.LibFoundation.Mathematics.Vector2f kDeriv)
Computes the derivative of the error function at a control point by approximating with finite differences where the control point is moved small amounts in each orthgonal direction.- Parameters:
iControlX
- int Identifies the control point in the 2D lattice.iControlY
- int Identifies the control point in the 2D lattice.kDeriv
- Vector2f Vector to be filled with the derivative computed along each axis.
-
updateControlPointSamples
protected void updateControlPointSamples(int iControlX, int iControlY)
Update the registered source image and the computed error as a result of making changes to a single control point. This is the local control aspect of the B-Spline which means only those image samples which are affected by the control point need to be updated.- Parameters:
iControlX
- int Identifies the control point in the 2D lattice.iControlY
- int Identifies the control point in the 2D lattice.
-
updateSamples
protected void updateSamples(int iMinX, int iMaxX, int iMinY, int iMaxY)
Update the registered source image and the computed error but only for the specified range of samples.- Parameters:
iMinX
- int Minimum X axis sample index.iMaxX
- int Maximum X axis sample index.iMinY
- int Minimum Y axis sample index.iMaxY
- int Maximum Y axis sample index.
-
-