Class AlgorithmRegELSUNCOAR2D
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.registration.AlgorithmRegELSUNCOAR2D
-
- All Implemented Interfaces:
java.awt.event.ActionListener,java.awt.event.WindowListener,java.lang.Runnable,java.util.EventListener
public class AlgorithmRegELSUNCOAR2D extends AlgorithmBase
This is an automatic registration method based on FLIRT. FLIRT stands for FMRIB's Linear Image Registration Tool. For more information on FLIRT, visit their homepage at http://www.fmrib.ox.ac.uk/fsl/flirt/. Their main paper is:Jenkinson, M. and Smith, S. (2001a).
A global optimisation method for robust affine registration of brain images.
Medical Image Analysis, 5(2):143-156.
Our algorithm works as follows:
1.) We find the minimum resolution of the images and blur them if neccessary.
2.) We transform the images into isotropic voxels.
3.) We subsample the images by 2, 4, and 8, depending on the resolution.
4.) With the images that were subsampled by 8, we call levelEight. This function will use the coarse sampling rate and optimize translations and global scale at the given rotation. So for example, if the coarse sampling range were -30 to 30 at every 15 degrees, we would optimize at rotations of -30, -15, 0, 15, 30.
5.) Still in levelEight, we now measure the cost at the fine sampling rate. We interpolate the translations and global scale to come up with a good guess as to what the optimized translation would be at that point.
6.) We take the top 20% of the points and optimize them.
7.) We now have a large multi-array of costs. 20% of those have been optimized and placed back into their original position in the multi-array. We look at the 2 neighbors of a point: + and - one fine sample. If our point has a cost greater than any of these, it is not a minima. Otherwise it is. We save it in a vector of minima.
8.) We optimize the minima over rotation as well as translations and global scale. (Previously we had not optimized over rotation.) We return two vectors, one containing the minima before optimization, one containing the minima after optimization.
9.) We now call levelFour with the images subsampled by 4 and the vectors of minima. We measure the costs of the minima on the new images and sort them. We take the top numMinima in each vector (pre-optimization and post-optimization) and optimize them. We put them all into one vector.
10.) We perturb the rotation by zero and plus-minus fineDelta. If it's not a rigid transformation, we then perturb the global scaling by factors of 0.8, 0.9, 1.0, 1.1, and 1.2.
11.) We optimize the perturbations. We return a vector of the perturbed, optimized minima.
12.) We now call levelTwo with the images subsampled by 2. We measure the costs of the minima at the new images. We optimize the best minimum with 4 degrees of freedom, then 5, then 6. If the user has limited the degrees of freedom to 3, there will only be one optimization run, with 3 degrees of freedom. The function returns the best minimum after optimization.
13.) We call levelOne with the un-subsampled images. At levelOne, one optimization run is performed, with the maximum allowable degrees of freedom, as specified by the user (the max is 6).
14.) The best answer is returned from levelOne. The matrix from this answer is saved in a file and also accessed by the dialog that called this algorithm.
Note that when 6 degrees of freedom is used the rotation is set equal to 0 because diffX sets (0,2), diffY sets (1,2), scaleX sets (0,0), scaleY sets (1,1), skewX sets (0,1), and skewY sets (1,0) so all 6 elements are set.
- Author:
- Neva Cherniavsky, Matthew McAuliffe
-
-
Field Summary
Fields Modifier and Type Field Description private booleanallowLevel16DOCUMENT ME!private booleanallowLevel2DOCUMENT ME!private booleanallowLevel4DOCUMENT ME!private booleanallowLevel8DOCUMENT ME!private MatrixListItemanswerFinal answer after registration.private intbaseNumIterthese numbers hard coded for constructors that don't include them.private ModelImageblurredInputBlurred input image.private ModelImageblurredRefBlurred reference image.private intcoarseNumNumber of passes that will be made in the coarse sampling and fine sampling.private floatcoarseRateCoarse and fine sampling parameters.private AlgorithmCostFunctions2Dcostprivate intcostChoiceChoice of which cost function to use.private booleandoColorDOCUMENT ME!private intDOFMaximum degrees of freedom when running the optimization.private booleandoJTEMprivate booleandoMultiThreadprivate booleandoSubsampleIf true subsample.private intfineNumNumber of passes that will be made in the coarse sampling and fine sampling.private floatfineRateCoarse and fine sampling parameters.private ModelImageimageInputIsoIsotropic input image.private ModelImageimageRefIsoIsotropic reference image.private ModelImageimageWeightInputIsoIsotropic weighted input image.private ModelImageimageWeightRefIsoIsotropic weighted reference image.private ModelImageinputImageThis image is to registered to the reference image.private ModelImageinputWeightThis gives weights for the input image - higher weights mean a greater impact in that area on the registration.private intinterpInterpolation method.private floatlevel1FactorMultiplication factor for level 1 - will be set based on subsampling.private floatlevel2FactorMultiplication factor for level 2 - will be set based on subsampling.private floatlevel4FactorMultiplication factor for level 4 - will be set based on subsampling.private booleanm_bBruteForceIf true, calculate the brute-force solution:.private floatm_fRotationRangeThe range of rotations to try in brute-force mode:.private floatm_fXScaleRangeThe range of scales in x to try in brute-force mode:.private floatm_fYScaleRangeThe range of scales in y to try in brute-force mode:.private intm_iScaleStepsThe number of steps to divide scale ranges:.private intm_iTranslationRangeThe range of x,y translations to try in brute-force mode:.private ImageRegistrationGPUm_kGPUCostprivate intmaxDimDOCUMENT ME!private intmaxIterLimits number of iterations in ELSUNC optimization. maxIter in the call to ELSUNC will be an integer multiple of baseNumIterprivate intnumMinimaNumber of minima from level 8 to test at level 4.private java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f>optimalPathThe optimal path.private static WildMagic.LibFoundation.Mathematics.Vector3f[]originalPathprivate java.util.Vector<java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f>>[]pathsUsed to store all paths for levelEigth, levelFour, levelTwo and levelOne.private ModelImagerefImageThe inputImage will be registered to this reference image.private ModelImagerefWeightThis gives weights for the reference image - higher weights mean a greater impact in that area on the registration.private booleanresampleInputDOCUMENT ME!private booleanresampleRefDOCUMENT ME!private float[]resInputThe voxel resolutions of the image to be registered to the reference image.private float[]resRefThe voxel resolutions of the reference image.private booleanrigidFlagFlag used to indicate if the registration is rigid (rotation and translation only; DOF = 3.private floatrotateBeginCoarse and fine sampling parameters.private floatrotateEndCoarse and fine sampling parameters.private intsearchAlgorithmprivate ModelSimpleImagesimpleInputSimple version of input image.private ModelSimpleImagesimpleInputSub2Simple version of input image, subsampled by 2.private ModelSimpleImagesimpleInputSub4Simple version of input image, subsampled by 4.private ModelSimpleImagesimpleInputSub8Simple version of input image, subsampled by 8.private ModelSimpleImagesimpleRefSimple version of reference image.private ModelSimpleImagesimpleRefSub2Simple version of reference image, subsampled by 2.private ModelSimpleImagesimpleRefSub4Simple version of reference image, subsampled by 4.private ModelSimpleImagesimpleRefSub8Simple version of reference image, subsampled by 8.private ModelSimpleImagesimpleWeightInputSimple version of weighted input image.private ModelSimpleImagesimpleWeightInputSub2Simple version of weighted input image, subsampled by 2.private ModelSimpleImagesimpleWeightInputSub4Simple version of weighted input image, subsampled by 4.private ModelSimpleImagesimpleWeightInputSub8Simple version of weighted input image, subsampled by 8.private ModelSimpleImagesimpleWeightRefSimple version of weighted reference image.private ModelSimpleImagesimpleWeightRefSub2Simple version of weighted reference image, subsampled by 2.private ModelSimpleImagesimpleWeightRefSub4Simple version of weighted reference image, subsampled by 4.private ModelSimpleImagesimpleWeightRefSub8Simple version of weighted reference image, subsampled by 8.private AlgorithmTransformtransformTransformation algorithm for creating an isotropic reference image.private AlgorithmTransformtransform2Transformation algorithm for creating an isotropic input image.private booleanweightedFlag to determine if there are weighted images or not.private intweightedInputPixelsDOCUMENT ME!private intweightedInputPixelsSub2DOCUMENT ME!private intweightedInputPixelsSub4DOCUMENT ME!private intweightedInputPixelsSub8DOCUMENT ME!private intweightedRefPixelsDOCUMENT ME!private intweightedRefPixelsSub2DOCUMENT ME!private intweightedRefPixelsSub4DOCUMENT ME!private intweightedRefPixelsSub8DOCUMENT 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 AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, boolean doMultiThread, int searchAlgorithm)Creates new automatic linear registration algorithm and sets necessary variables.AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, boolean doMultiThread, int _baseNumIter, int _numMinima, int searchAlgorithm)Creates new automatic linear registration algorithm and sets necessary variables.AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, int searchAlgorithm)Creates new automatic linear registration algorithm and sets necessary variables.AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, int _baseNumIter, int _numMinima, int searchAlgorithm)Creates new automatic linear registration algorithm and sets necessary variables.AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, ModelImage _refWeight, ModelImage _inputWeight, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, boolean doMultiThread, int searchAlgorithm)Creates new automatic linear registration algorithm and sets necessary variables.AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, ModelImage _refWeight, ModelImage _inputWeight, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, boolean doMultiThread, int _baseNumIter, int _numMinima, int searchAlgorithm)Creates new automatic linear registration algorithm and sets necessary variables.AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, ModelImage _refWeight, ModelImage _inputWeight, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, int searchAlgorithm)Creates new automatic linear registration algorithm and sets necessary variables.AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, ModelImage _refWeight, ModelImage _inputWeight, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, int _baseNumIter, int _numMinima, int searchAlgorithm)Creates new automatic linear registration algorithm and sets necessary variables.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidalgorithmBruteForce()Compute the brute-force solution.WildMagic.LibFoundation.Mathematics.Vector2fcalculateCenterOfMass2D(ModelSimpleImage image, ModelSimpleImage wgtImage, boolean isColor)Calculates the center of mass (gravity) of a 2D image.private voidcreateTerrain()voiddisposeLocal()Dispose of local variables that may be taking up lots of room.voiddrawLine(int xdim, int ydim, int zdim, float[] image, float value, java.util.Vector<Point3D> path)voidfinalize()Prepares this class for destruction.java.util.Vector<Point3D>findPointsOfLine(java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f> realPath)private java.lang.StringgetConstructionInfo()Creates a string with the parameters that the image was constructed with.doublegetCost()floatgetLevel1Factor()floatgetLevel2Factor()floatgetLevel4Factor()intgetMaxDim()doublegetRotation()private double[]getTolerance(int DOF)Gets the tolerance vector based on the degrees of freedom (the length of the tolerance is the degrees of freedom).TransMatrixgetTransform()Accessor that returns the matrix calculated in this algorithm.private intindexOf(java.util.Vector<java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f>> aPaths, WildMagic.LibFoundation.Mathematics.Vector3f tp3d)private voidinterpolate(double x, double[] initial, double[][] tranforms, boolean scale)Performs a bilinear interpolation on points.java.util.Vector<MatrixListItem>[]levelEight(ModelSimpleImage ref, ModelSimpleImage input)Takes two images that have been subsampled by a factor of eight.java.util.Vector<MatrixListItem>levelFour(ModelSimpleImage ref, ModelSimpleImage input, java.util.Vector<MatrixListItem> minima, java.util.Vector<MatrixListItem> optMinima)Takes two images that have been subsampled by a factor of four, and two vectors of minima.MatrixListItemlevelOne(ModelSimpleImage ref, ModelSimpleImage input, MatrixListItem item)Takes the two images, no subsampling, and the best minimum so far.private MatrixListItemlevelOne2D(ModelSimpleImage ref, ModelSimpleImage input)Only used for translations only = 2 degrees of freedom levelEight, levelFour, and levelTwo are skipped Takes the two images, no subsampling.private MatrixListItemlevelOne2DRotation(ModelSimpleImage ref, ModelSimpleImage input)Only used for rotations only = 1 degrees of freedom levelEight, levelFour, and levelTwo are skipped Takes the two images, no subsampling.MatrixListItemlevelTwo(ModelSimpleImage ref, ModelSimpleImage input, java.util.Vector<MatrixListItem> minima)Takes two images that have been subsampled by a factor of 2 and a vector of minima.floatline(float a, float b, int x, float y)voidmidpointLine(WildMagic.LibFoundation.Mathematics.Vector3f p0, WildMagic.LibFoundation.Mathematics.Vector3f p1, java.util.Vector<Point3D> imagePath)java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f>param2Coordinates(double startX, double endX, double stepX, double startY, double endY, double stepY, double startZ, double endZ, double stepZ, java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f> path)voidprint(MatrixListItem item, java.lang.String message)voidprint(java.util.Vector data, java.lang.String message)voidrunAlgorithm()Runs the image registration.private voidsearchOptimalPath()voidsetBruteForce(boolean bOn, float fRotationRange, float fXScaleRange, float fYScaleRange, int iScaleSteps, int iTranslationRange)setBruteForce.voidsetJTEM(boolean bOn)voidsetLevel1Factor(float level1Factor)voidsetLevel2Factor(float level2Factor)voidsetLevel4Factor(float level4Factor)voidsetMaxDim(int maxDim)private static ModelSimpleImagesubsampleBy2(ModelSimpleImage srcImage, boolean isColor)Takes a simple image and subsamples it by 2, interpolating so that the new values are averages.-
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
-
allowLevel16
private boolean allowLevel16
DOCUMENT ME!
-
allowLevel2
private boolean allowLevel2
DOCUMENT ME!
-
allowLevel4
private boolean allowLevel4
DOCUMENT ME!
-
allowLevel8
private boolean allowLevel8
DOCUMENT ME!
-
answer
private MatrixListItem answer
Final answer after registration.
-
baseNumIter
private int baseNumIter
these numbers hard coded for constructors that don't include them.
-
blurredInput
private ModelImage blurredInput
Blurred input image.
-
blurredRef
private ModelImage blurredRef
Blurred reference image.
-
coarseNum
private final int coarseNum
Number of passes that will be made in the coarse sampling and fine sampling.
-
fineNum
private final int fineNum
Number of passes that will be made in the coarse sampling and fine sampling.
-
costChoice
private int costChoice
Choice of which cost function to use.
-
doColor
private boolean doColor
DOCUMENT ME!
-
DOF
private int DOF
Maximum degrees of freedom when running the optimization.
-
doSubsample
private final boolean doSubsample
If true subsample.
-
doJTEM
private boolean doJTEM
-
doMultiThread
private boolean doMultiThread
-
searchAlgorithm
private int searchAlgorithm
-
imageInputIso
private ModelImage imageInputIso
Isotropic input image.
-
imageRefIso
private ModelImage imageRefIso
Isotropic reference image.
-
imageWeightInputIso
private ModelImage imageWeightInputIso
Isotropic weighted input image.
-
imageWeightRefIso
private ModelImage imageWeightRefIso
Isotropic weighted reference image.
-
inputImage
private ModelImage inputImage
This image is to registered to the reference image.
-
inputWeight
private ModelImage inputWeight
This gives weights for the input image - higher weights mean a greater impact in that area on the registration.
-
interp
private final int interp
Interpolation method.
-
level1Factor
private float level1Factor
Multiplication factor for level 1 - will be set based on subsampling.
-
level2Factor
private float level2Factor
Multiplication factor for level 2 - will be set based on subsampling.
-
level4Factor
private float level4Factor
Multiplication factor for level 4 - will be set based on subsampling.
-
m_bBruteForce
private boolean m_bBruteForce
If true, calculate the brute-force solution:.
-
m_fRotationRange
private float m_fRotationRange
The range of rotations to try in brute-force mode:.
-
m_fXScaleRange
private float m_fXScaleRange
The range of scales in x to try in brute-force mode:.
-
m_fYScaleRange
private float m_fYScaleRange
The range of scales in y to try in brute-force mode:.
-
m_iScaleSteps
private int m_iScaleSteps
The number of steps to divide scale ranges:.
-
m_iTranslationRange
private int m_iTranslationRange
The range of x,y translations to try in brute-force mode:.
-
maxDim
private int maxDim
DOCUMENT ME!
-
maxIter
private int maxIter
Limits number of iterations in ELSUNC optimization. maxIter in the call to ELSUNC will be an integer multiple of baseNumIter
-
numMinima
private int numMinima
Number of minima from level 8 to test at level 4.
-
refImage
private ModelImage refImage
The inputImage will be registered to this reference image.
-
refWeight
private ModelImage refWeight
This gives weights for the reference image - higher weights mean a greater impact in that area on the registration.
-
resampleInput
private boolean resampleInput
DOCUMENT ME!
-
resampleRef
private boolean resampleRef
DOCUMENT ME!
-
resInput
private final float[] resInput
The voxel resolutions of the image to be registered to the reference image.
-
resRef
private final float[] resRef
The voxel resolutions of the reference image.
-
rigidFlag
private boolean rigidFlag
Flag used to indicate if the registration is rigid (rotation and translation only; DOF = 3.
-
rotateBegin
private final float rotateBegin
Coarse and fine sampling parameters.
-
rotateEnd
private final float rotateEnd
Coarse and fine sampling parameters.
-
coarseRate
private final float coarseRate
Coarse and fine sampling parameters.
-
fineRate
private final float fineRate
Coarse and fine sampling parameters.
-
simpleInput
private ModelSimpleImage simpleInput
Simple version of input image.
-
simpleInputSub2
private ModelSimpleImage simpleInputSub2
Simple version of input image, subsampled by 2.
-
simpleInputSub4
private ModelSimpleImage simpleInputSub4
Simple version of input image, subsampled by 4.
-
simpleInputSub8
private ModelSimpleImage simpleInputSub8
Simple version of input image, subsampled by 8.
-
simpleRef
private ModelSimpleImage simpleRef
Simple version of reference image.
-
simpleRefSub2
private ModelSimpleImage simpleRefSub2
Simple version of reference image, subsampled by 2.
-
simpleRefSub4
private ModelSimpleImage simpleRefSub4
Simple version of reference image, subsampled by 4.
-
simpleRefSub8
private ModelSimpleImage simpleRefSub8
Simple version of reference image, subsampled by 8.
-
simpleWeightInput
private ModelSimpleImage simpleWeightInput
Simple version of weighted input image.
-
simpleWeightInputSub2
private ModelSimpleImage simpleWeightInputSub2
Simple version of weighted input image, subsampled by 2.
-
simpleWeightInputSub4
private ModelSimpleImage simpleWeightInputSub4
Simple version of weighted input image, subsampled by 4.
-
simpleWeightInputSub8
private ModelSimpleImage simpleWeightInputSub8
Simple version of weighted input image, subsampled by 8.
-
simpleWeightRef
private ModelSimpleImage simpleWeightRef
Simple version of weighted reference image.
-
simpleWeightRefSub2
private ModelSimpleImage simpleWeightRefSub2
Simple version of weighted reference image, subsampled by 2.
-
simpleWeightRefSub4
private ModelSimpleImage simpleWeightRefSub4
Simple version of weighted reference image, subsampled by 4.
-
simpleWeightRefSub8
private ModelSimpleImage simpleWeightRefSub8
Simple version of weighted reference image, subsampled by 8.
-
transform
private AlgorithmTransform transform
Transformation algorithm for creating an isotropic reference image.
-
transform2
private AlgorithmTransform transform2
Transformation algorithm for creating an isotropic input image.
-
weighted
private boolean weighted
Flag to determine if there are weighted images or not.
-
weightedInputPixels
private int weightedInputPixels
DOCUMENT ME!
-
weightedInputPixelsSub2
private int weightedInputPixelsSub2
DOCUMENT ME!
-
weightedInputPixelsSub4
private int weightedInputPixelsSub4
DOCUMENT ME!
-
weightedInputPixelsSub8
private int weightedInputPixelsSub8
DOCUMENT ME!
-
weightedRefPixels
private int weightedRefPixels
DOCUMENT ME!
-
weightedRefPixelsSub2
private int weightedRefPixelsSub2
DOCUMENT ME!
-
weightedRefPixelsSub4
private int weightedRefPixelsSub4
DOCUMENT ME!
-
weightedRefPixelsSub8
private int weightedRefPixelsSub8
DOCUMENT ME!
-
cost
private AlgorithmCostFunctions2D cost
-
m_kGPUCost
private ImageRegistrationGPU m_kGPUCost
-
paths
private final java.util.Vector<java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f>>[] paths
Used to store all paths for levelEigth, levelFour, levelTwo and levelOne.
-
optimalPath
private java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f> optimalPath
The optimal path.
-
originalPath
private static final WildMagic.LibFoundation.Mathematics.Vector3f[] originalPath
-
-
Constructor Detail
-
AlgorithmRegELSUNCOAR2D
public AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, boolean doMultiThread, int searchAlgorithm)
Creates new automatic linear registration algorithm and sets necessary variables.- Parameters:
_imageA- Reference image (register input image to reference image)._imageB- Input image (register input image to reference image)._costChoice- Choice of cost functions, like correlation ratio or mutual information._DOF- Degrees of freedom for registration_interp- Interpolation method used in transformations._rotateBegin- Beginning of coarse sampling range (i.e., -60 degrees)._rotateEnd- End of coarse sampling range (i.e., 60 degrees)._coarseRate- Point at which coarse samples should be taken (i.e., every 45 degrees)._fineRate- Point at which fine samples should be taken (i.e., every 15 degrees).doSubsample- If true subsampledoMultiThread-searchAlgorithm- ESLUNC, LEVENBERG_MARQUARDT, or NL2SOL.Constructor without weighting and without advanced settings (num iter).
-
AlgorithmRegELSUNCOAR2D
public AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, int searchAlgorithm)
Creates new automatic linear registration algorithm and sets necessary variables.- Parameters:
_imageA- Reference image (register input image to reference image)._imageB- Input image (register input image to reference image)._costChoice- Choice of cost functions, like correlation ratio or mutual information._DOF- Degrees of freedom for registration_interp- Interpolation method used in transformations._rotateBegin- Beginning of coarse sampling range (i.e., -60 degrees)._rotateEnd- End of coarse sampling range (i.e., 60 degrees)._coarseRate- Point at which coarse samples should be taken (i.e., every 45 degrees)._fineRate- Point at which fine samples should be taken (i.e., every 15 degrees).doSubsample- If true subsamplesearchAlgorithm- ESLUNC, LEVENBERG_MARQUARDT, or NL2SOL.Constructor without weighting and without advanced settings (num iter).
-
AlgorithmRegELSUNCOAR2D
public AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, ModelImage _refWeight, ModelImage _inputWeight, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, boolean doMultiThread, int searchAlgorithm)
Creates new automatic linear registration algorithm and sets necessary variables.- Parameters:
_imageA- Reference image (register input image to reference image)._imageB- Input image (register input image to reference image)._refWeight- Reference weighted image, used to give certain areas of the image greater impact on the registration._inputWeight- Input weighted image, used to give certain areas of the image greater impact on the registration._costChoice- Choice of cost functions, like correlation ratio or mutual information._DOF- Degrees of freedom for registration_interp- Interpolation method used in transformations._rotateBegin- Beginning of coarse sampling range (i.e., -60 degrees)._rotateEnd- End of coarse sampling range (i.e., 60 degrees)._coarseRate- Point at which coarse samples should be taken (i.e., every 45 degrees)._fineRate- Point at which fine samples should be taken (i.e., every 15 degrees).doSubsample- If true subsampledoMultiThread-searchAlgorithm- ESLUNC, LEVENBERG_MARQUARDT, or NL2SOL.Constructor with weighting and without advanced settings (num iter).
-
AlgorithmRegELSUNCOAR2D
public AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, ModelImage _refWeight, ModelImage _inputWeight, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, int searchAlgorithm)
Creates new automatic linear registration algorithm and sets necessary variables.- Parameters:
_imageA- Reference image (register input image to reference image)._imageB- Input image (register input image to reference image)._refWeight- Reference weighted image, used to give certain areas of the image greater impact on the registration._inputWeight- Input weighted image, used to give certain areas of the image greater impact on the registration._costChoice- Choice of cost functions, like correlation ratio or mutual information._DOF- Degrees of freedom for registration_interp- Interpolation method used in transformations._rotateBegin- Beginning of coarse sampling range (i.e., -60 degrees)._rotateEnd- End of coarse sampling range (i.e., 60 degrees)._coarseRate- Point at which coarse samples should be taken (i.e., every 45 degrees)._fineRate- Point at which fine samples should be taken (i.e., every 15 degrees).doSubsample- If true subsamplesearchAlgorithm- ESLUNC, LEVENBERG_MARQUARDT, or NL2SOL.Constructor with weighting and without advanced settings (num iter).
-
AlgorithmRegELSUNCOAR2D
public AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, boolean doMultiThread, int _baseNumIter, int _numMinima, int searchAlgorithm)
Creates new automatic linear registration algorithm and sets necessary variables.- Parameters:
_imageA- Reference image (register input image to reference image)._imageB- Input image (register input image to reference image)._costChoice- Choice of cost functions, like correlation ratio or mutual information._DOF- Degrees of freedom for registration_interp- Interpolation method used in transformations._rotateBegin- Beginning of coarse sampling range (i.e., -60 degrees)._rotateEnd- End of coarse sampling range (i.e., 60 degrees)._coarseRate- Point at which coarse samples should be taken (i.e., every 45 degrees)._fineRate- Point at which fine samples should be taken (i.e., every 15 degrees).doSubsample- If true subsampledoMultiThread-_baseNumIter- Limits the number of iterations of ELSUNC algorithm. maxIter in the call to ELSUNC will be an integer multiple of baseNumIter_numMinima- Number of minima from level 8 to test at level 4searchAlgorithm- ESLUNC, LEVENBERG_MARQUARDT, or NL2SOL.Constructor without weighting and with advanced settings (num iter) set.
-
AlgorithmRegELSUNCOAR2D
public AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, int _baseNumIter, int _numMinima, int searchAlgorithm)
Creates new automatic linear registration algorithm and sets necessary variables.- Parameters:
_imageA- Reference image (register input image to reference image)._imageB- Input image (register input image to reference image)._costChoice- Choice of cost functions, like correlation ratio or mutual information._DOF- Degrees of freedom for registration_interp- Interpolation method used in transformations._rotateBegin- Beginning of coarse sampling range (i.e., -60 degrees)._rotateEnd- End of coarse sampling range (i.e., 60 degrees)._coarseRate- Point at which coarse samples should be taken (i.e., every 45 degrees)._fineRate- Point at which fine samples should be taken (i.e., every 15 degrees).doSubsample- If true subsampledoMultiThread-_baseNumIter- Limits the number of iterations of ELSUNC algorithm. maxIter in the call to ELSUNC will be an integer multiple of baseNumIter_numMinima- Number of minima from level 8 to test at level 4searchAlgorithm- ESLUNC, LEVENBERG_MARQUARDT, or NL2SOL.Constructor without weighting and with advanced settings (num iter) set.
-
AlgorithmRegELSUNCOAR2D
public AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, ModelImage _refWeight, ModelImage _inputWeight, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, boolean doMultiThread, int _baseNumIter, int _numMinima, int searchAlgorithm)
Creates new automatic linear registration algorithm and sets necessary variables.- Parameters:
_imageA- Reference image (register input image to reference image)._imageB- Input image (register input image to reference image)._refWeight- Reference weighted image, used to give certain areas of the image greater impact on the registration._inputWeight- Input weighted image, used to give certain areas of the image greater impact on the registration._costChoice- Choice of cost functions, like correlation ratio or mutual information._DOF- Degrees of freedom for registration_interp- Interpolation method used in transformations._rotateBegin- Beginning of coarse sampling range (i.e., -60 degrees)._rotateEnd- End of coarse sampling range (i.e., 60 degrees)._coarseRate- Point at which coarse samples should be taken (i.e., every 45 degrees)._fineRate- Point at which fine samples should be taken (i.e., every 15 degrees).doSubsample- If true subsampledoMultiThread-_baseNumIter- Limits the number of iterations of ELSUNC algorithm. maxIter in the call to ELSUNC will be an integer multiple of baseNumIter_numMinima- Number of minima from level 8 to test at level 4searchAlgorithm- ESLUNC, LEVENBERG_MARQUARDT, or NL2SOL.Constructor with weighting and with advanced settings (num iter) set.
-
AlgorithmRegELSUNCOAR2D
public AlgorithmRegELSUNCOAR2D(ModelImage _imageA, ModelImage _imageB, ModelImage _refWeight, ModelImage _inputWeight, int _costChoice, int _DOF, int _interp, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doSubsample, int _baseNumIter, int _numMinima, int searchAlgorithm)
Creates new automatic linear registration algorithm and sets necessary variables.- Parameters:
_imageA- Reference image (register input image to reference image)._imageB- Input image (register input image to reference image)._refWeight- Reference weighted image, used to give certain areas of the image greater impact on the registration._inputWeight- Input weighted image, used to give certain areas of the image greater impact on the registration._costChoice- Choice of cost functions, like correlation ratio or mutual information._DOF- Degrees of freedom for registration_interp- Interpolation method used in transformations._rotateBegin- Beginning of coarse sampling range (i.e., -60 degrees)._rotateEnd- End of coarse sampling range (i.e., 60 degrees)._coarseRate- Point at which coarse samples should be taken (i.e., every 45 degrees)._fineRate- Point at which fine samples should be taken (i.e., every 15 degrees).doSubsample- If true subsampledoMultiThread-_baseNumIter- Limits the number of iterations of ELSUNC algorithm. maxIter in the call to ELSUNC will be an integer multiple of baseNumIter_numMinima- Number of minima from level 8 to test at level 4searchAlgorithm- ESLUNC, LEVENBERG_MARQUARDT, or NL2SOL.Constructor with weighting and with advanced settings (num iter) set.
-
-
Method Detail
-
calculateCenterOfMass2D
public WildMagic.LibFoundation.Mathematics.Vector2f calculateCenterOfMass2D(ModelSimpleImage image, ModelSimpleImage wgtImage, boolean isColor)
Calculates the center of mass (gravity) of a 2D image. In image space where the upper left hand corner of the image is 0,0. The x axis goes left to right, y axis goes top to bottom. (i.e. the right hand rule). One could simply multiply by voxel resolutions.- Parameters:
image- DOCUMENT ME!wgtImage- DOCUMENT ME!isColor- DOCUMENT ME!- Returns:
- the center of mass as a 2D point
-
disposeLocal
public void disposeLocal()
Dispose of local variables that may be taking up lots of room.
-
finalize
public void finalize()
Prepares this class for destruction.- Overrides:
finalizein classAlgorithmBase
-
getTransform
public TransMatrix getTransform()
Accessor that returns the matrix calculated in this algorithm.- Returns:
- Matrix found at the end of algorithm.
-
drawLine
public void drawLine(int xdim, int ydim, int zdim, float[] image, float value, java.util.Vector<Point3D> path)
-
param2Coordinates
public java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f> param2Coordinates(double startX, double endX, double stepX, double startY, double endY, double stepY, double startZ, double endZ, double stepZ, java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f> path)
-
findPointsOfLine
public java.util.Vector<Point3D> findPointsOfLine(java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f> realPath)
-
midpointLine
public void midpointLine(WildMagic.LibFoundation.Mathematics.Vector3f p0, WildMagic.LibFoundation.Mathematics.Vector3f p1, java.util.Vector<Point3D> imagePath)
-
line
public float line(float a, float b, int x, float y)
-
runAlgorithm
public void runAlgorithm()
Runs the image registration. Blurs the images based on what their minimum resolutions are. The reference image is blurred if one of the input image resolutions is 50% or more bigger than the corresponding resolution in the reference image; likewise, the input image is blurred if one of the reference image resolutions is 50% or more bigger than the corresponding resolution in the input image. Thus, it is unlikely, though not impossible, that both images will be blurred. The images are then transformed into isotropic voxels. The resolutions of the two images after the isotropic transformation will be the same in all dimensions. That resolution will equal the minimum of the minimums of each image's resolutions: Min( Min (resolutions of ref image, resolutions of input image) ). If the images are weighted, the weight images are blurred and transformed into isotropic voxels in the same manner as the originals. Then the images are subsampled by 2, 4, and 8. If the images are too small they will not be subsampled down to the smallest level; if they are too big, they will be subsampled to 16. The same is done with the weight images if necessary. The function levelEight is called with the images subsampled by 8; it returns two vectors with minima. Then the function levelFour is called with images subsampled by 4 and the two vectors; it returns one vector of minima. The function levelTwo is called with images subsampled by 2 and the vector; it returns an "answer" in the form of a MatrixListItem, which is a convenient way of storing the point, the matrix, and the cost of the minimum. Then the function levelOne is called with the minimum; it returns a final "answer", or minimum, which will then be accessed by the dialog that called this algorithm.- Specified by:
runAlgorithmin classAlgorithmBase
-
getCost
public double getCost()
-
getRotation
public double getRotation()
-
createTerrain
private void createTerrain()
-
searchOptimalPath
private void searchOptimalPath()
-
indexOf
private int indexOf(java.util.Vector<java.util.Vector<WildMagic.LibFoundation.Mathematics.Vector3f>> aPaths, WildMagic.LibFoundation.Mathematics.Vector3f tp3d)
-
print
public void print(java.util.Vector data, java.lang.String message)
-
print
public void print(MatrixListItem item, java.lang.String message)
-
setBruteForce
public void setBruteForce(boolean bOn, float fRotationRange, float fXScaleRange, float fYScaleRange, int iScaleSteps, int iTranslationRange)setBruteForce. Tells the algorithm to do a brute-force optimization, where it will iterate of the the input rotation, xscale, yscale, and translation ranges calculating the cost function at each point and returing the minimum. No optimization with the brute-force approach.- Parameters:
bOn- DOCUMENT ME!fRotationRange- DOCUMENT ME!fXScaleRange- DOCUMENT ME!fYScaleRange- DOCUMENT ME!iScaleSteps- DOCUMENT ME!iTranslationRange- DOCUMENT ME!
-
setJTEM
public void setJTEM(boolean bOn)
-
subsampleBy2
private static ModelSimpleImage subsampleBy2(ModelSimpleImage srcImage, boolean isColor)
Takes a simple image and subsamples it by 2, interpolating so that the new values are averages.- Parameters:
srcImage- Image to subsample.isColor- DOCUMENT ME!- Returns:
- Subsampled image.
-
algorithmBruteForce
private void algorithmBruteForce()
Compute the brute-force solution. Iterates over a range of angles, scales and translations, calculating the cost function for each new position, returning the one with minimum cost:
-
getConstructionInfo
private java.lang.String getConstructionInfo()
Creates a string with the parameters that the image was constructed with.- Returns:
- Construction info.
-
getTolerance
private double[] getTolerance(int DOF)
Gets the tolerance vector based on the degrees of freedom (the length of the tolerance is the degrees of freedom).- Parameters:
DOF- Degrees of freedom, will be length of vector.- Returns:
- New tolerance vector to send to optimization.
Based on FLIRT paper: let n=pixel dimension (in one dimension) R=brain radius, here assumed to be half of field-of-view Translation tolerance = n/2 Rotation tolerance = (180/PI)*n/(2R) (converted to degrees because AlgorithmELSUNC works in degrees) Scaling tolerance = n/(2R) Skewing tolerance = n/(2R)
-
interpolate
private void interpolate(double x, double[] initial, double[][] tranforms, boolean scale)Performs a bilinear interpolation on points. Takes an initial point, a vector of values to set, and an array in which to look at neighbors of that point. Sets the appropriate values in the vector. Does not set scale if the scale parameter isfalse.- Parameters:
x- Initial index into array.initial- Vector to set; if scale istrue, set two translations and a scale. Otherwise just set translations.tranforms- DOCUMENT ME!scale-truemeans set the scale in the vector.
-
levelEight
public java.util.Vector<MatrixListItem>[] levelEight(ModelSimpleImage ref, ModelSimpleImage input)
Takes two images that have been subsampled by a factor of eight. Sets up the cost function with the images and the weighted images, if necessary. Uses the coarse sampling rate and optimizes translations and global scale at the given rotation. So for example, if the coarse sampling range were -30 to 30 at every 15 degrees, we would optimize at rotations of -30, -15, 0, 15, 30. Measures the cost at the fine sampling rate. Interpolates the translations and global scale to come up with a good guess as to what the optimized translation would be at that point. Takes the top 20% of the points and optimizes them. Now have a large multi-array of costs. 20% of those have been optimized and placed back into their original position in the multi-array. Looks at the 2 neighbors of a point: + and - one fine sample. If the point has a cost greater than any of these, it is not a minima. Otherwise it is. Saves it in a vector of minima. Optimizes the minima over rotation as well as translations and global scale. (Previously had not optimized over rotation.) Returns two vectors, one containing the minima before optimization, one containing the minima after optimization.- Parameters:
ref- Subsampled by 8 reference image.input- Subsampled by 8 input image.- Returns:
- List of preoptimized and optimized points.
-
levelFour
public java.util.Vector<MatrixListItem> levelFour(ModelSimpleImage ref, ModelSimpleImage input, java.util.Vector<MatrixListItem> minima, java.util.Vector<MatrixListItem> optMinima)
Takes two images that have been subsampled by a factor of four, and two vectors of minima. Sets up the cost function with the images and the weighted images, if necessary. Adds the level4Factor determined during subsampling. Measures the costs of the minima on the images and sort them. Takes the top three in each vector (pre-optimization and post-optimization) and optimizes them. Puts them all into one vector. Perturbs the rotation by zero and plus-minus fineDelta. If it's not a rigid transformation, perturbs the global scaling by factors of 0.8, 0.9, 1.0, 1.1, and 1.2. Optimize the perturbations. Returns a vector of the perturbed, optimized minima.- Parameters:
ref- Reference image, subsampled by 4.input- Input image, subsampled by 4.minima- Preoptimized minima.optMinima- Optimized minima.- Returns:
- A vector of perturbed, optimized minima.
-
levelOne
public MatrixListItem levelOne(ModelSimpleImage ref, ModelSimpleImage input, MatrixListItem item)
Takes the two images, no subsampling, and the best minimum so far. Sets up the cost function with the images and the weighted images, if necessary. Adds the level1Factor determined during subsampling. Performs one optimization run, with the maximum allowable degrees of freedom as specified by the user (the max is 7). Returns the best minimum.- Parameters:
ref- Reference image.input- Input image.item- Best minimum so far.- Returns:
- Best minimum after optimization.
-
levelOne2D
private MatrixListItem levelOne2D(ModelSimpleImage ref, ModelSimpleImage input)
Only used for translations only = 2 degrees of freedom levelEight, levelFour, and levelTwo are skipped Takes the two images, no subsampling. Sets up the cost function with the images and the weighted images, Performs one optimization run, with 2 degrees of freedom Returns the best minimum.- Parameters:
ref- Reference image.input- Input image.- Returns:
- Best minimum after optimization.
-
levelOne2DRotation
private MatrixListItem levelOne2DRotation(ModelSimpleImage ref, ModelSimpleImage input)
Only used for rotations only = 1 degrees of freedom levelEight, levelFour, and levelTwo are skipped Takes the two images, no subsampling. Sets up the cost function with the images and the weighted images, Performs one optimization run, with 2 degrees of freedom Returns the best minimum.- Parameters:
ref- Reference image.input- Input image.- Returns:
- Best minimum after optimization.
-
levelTwo
public MatrixListItem levelTwo(ModelSimpleImage ref, ModelSimpleImage input, java.util.Vector<MatrixListItem> minima)
Takes two images that have been subsampled by a factor of 2 and a vector of minima. Sets up the cost function with the images and the weighted images, if necessary. Adds the level2Factor determined during subsampling. Measures the costs of the minima at the images. Optimizes the best minimum with 4 degrees of freedom, then 5, then 7. If the user has limited the degrees of freedom to 3, there will only be one optimization run, with 3 degrees of freedom. Returns the best minimum after optimization.- Parameters:
ref- Reference image, subsampled by 2.input- Input image, subsampled by 2.minima- Minima.- Returns:
- The optimized minimum.
-
getLevel1Factor
public float getLevel1Factor()
-
setLevel1Factor
public void setLevel1Factor(float level1Factor)
-
getLevel2Factor
public float getLevel2Factor()
-
setLevel2Factor
public void setLevel2Factor(float level2Factor)
-
getLevel4Factor
public float getLevel4Factor()
-
setLevel4Factor
public void setLevel4Factor(float level4Factor)
-
getMaxDim
public int getMaxDim()
-
setMaxDim
public void setMaxDim(int maxDim)
-
-