Class AlgorithmRegOAR35D
- All Implemented Interfaces:
ActionListener,WindowListener,Runnable,EventListener
Jenkinson, M. and Smith, S. (2001a).
A global optimisation method for robust affine registration of brain images.
Medical Image Analysis, 5(2):143-156.
Internal registration is performed within one 4D image.
In adjacent mode the first volume above the reference volume is registered to the reference volume, then the second volume above the reference volume is registered to the first volume above the reference volume, and so on until the last volume is registered the next to last volume. Then, the first volume below the reference volume is registered to the reference volume, the second volume below the reference volume is registered to first volume below the reference volume, and so on until the first volume is registered to the second volume. In reference mode every volume is simply registered to the reference volume. In average mode every volume is simply registered to the average of all the volumes.
Our algorithm works as follows:
1.) We find the minimum resolution of the images.
2.) We transform the images into isotropic voxels.
3.) We subsample the images by 2, 4, and 8 or 16, depending on the resolution.
Subsampling can be in x, y, and z or in only x and y. We loop thru a number of iterations equal to the number of
volumes - 1 for adjacent mode or equal to the number of volumes in average or reference mode with one volume as the
input volume and one volume as the reference volume.
For each iteration:
4.) With the volumes that were subsampled by
8 or 16, 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 9 neighbors of a point: +, =, or - 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 volumes subsampled by 4 and the vectors of minima. We measure the costs of the
minima on the new volumes 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 by 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 volumes subsampled by 2. We measure the costs of the minima at the new volumes. We
optimize the best minimum with 7 degrees of freedom, then 9, then 12. If the user has limited the degrees of freedom
to 6, there will only be one optimization run, with 6 degrees of freedom. The function returns the best minimum after
optimization.
13.) We call levelOne with the un-subsampled volumes. At levelOne, one optimization run is performed, with the
maximum allowable degrees of freedom, as specified by the user (the max is 12).
14.) The best answer is returned from levelOne. The inverse of the matrix from this answer is used to register the
input volume to the reference volume. The registered input volume data is imported into inputImage.
Only subsample if 16 or more z slices are present, so that the number of z slices will not be reduced below 8.
- Author:
- Matthew McAuliffe, Neva Cherniavsky, Benjamin Link - Added code to use less memory. (April 2003)
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescription(package private) classHelper class to make it easy to store the necessary information about a minimum.Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final intDOCUMENT ME!private booleanDOCUMENT ME!private booleanDOCUMENT ME!private booleanFlags are true if weighted image is not present or if weighted image subsampling occurred, false if weighted image subsampling did not occur.private booleanDOCUMENT ME!private booleanDOCUMENT ME!private booleanDOCUMENT ME!private booleanDOCUMENT ME!private booleanDOCUMENT ME!Final answer after registration.private static final intDOCUMENT ME!private intLimits number of iterations in Powell optimization. maxIter in the call to Powell's will be an integer multiple of baseNumIterprivate float[]DOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private float[]DOCUMENT ME!private booleanIf true calculate the center of gravity (mass) and use the difference to intialize the translation.private intNumber of passes that will be made in the coarse sampling and fine sampling.private floatCoarse and fine sampling parameters.private int1 for black and white, 4 for color.private intChoice of which cost function to use.private booleanDOCUMENT ME!private intMaximum degrees of freedom when running the optimization.private booleanProduce 2 output graphs - 1 for 3 rotations and 1 for 3 translations.private booleanTurns the full version of Powell's algorithm on/off.private booleanprivate booleanif true subsample.private booleanIf true this algorithm skips all subsample and goes directly to the level 1 optimization.private intNumber of passes that will be made in the coarse sampling and fine sampling.private floatCoarse and fine sampling parameters.private ModelImageDOCUMENT ME!private ModelImageImage used to import a volume from inputImage.private ModelImageThis is the image in which internal registration will be performed.private ModelImageImage used to import a volume from inputWeight.private ModelImageThis gives weights for the input image - higher weights mean a greater impact in that area on the registration.private intInterpolation method used in transformations.private intInterpolation method used in output.private float[]The voxel resolutions of the input image.private ModelImagenew to this version: must keep isoImage around if image needed to be transformed.private floatMultiplication factor for level 1 - will be set based on subsampling.private floatDOCUMENT ME!private floatMultiplication factor for level 2 - will be set based on subsampling.private floatDOCUMENT ME!private floatMultiplication factor for level 4 - will be set based on subsampling.private floatDOCUMENT ME!private intDOCUMENT ME!private intLimits number of iterations in Powell optimization. maxIter in the call to Powell's will be an integer multiple of baseNumIterprivate static final intDOCUMENT ME!private intDOCUMENT ME!private intNumber of minima from level 8 to test at level 4.private ModelImageDOCUMENT ME!private ModelImageDOCUMENT ME!private ModelImageDOCUMENT ME!private intIndicates the first volume used as a reference volume, if mode == ADJACENT.private booleanIf true use adjacent image for registration.private booleantrue if resolutions unequal, false if resolutions equal.private booleantrue if weight image is resampled.private float[][]Arrays used for producing graphs for DOF == 6 and register to average or reference image.private floatCoarse and fine sampling parameters.private floatCoarse and fine sampling parameters.private ModelSimpleImageSimple version of an image volume of the input image.private ModelSimpleImageSimple version of an image volume of the input image, subsampled by 16.private ModelSimpleImageSimple version of an image volume of the input image, subsampled by 2.private ModelSimpleImageSimple version of an image volume of the input image, subsampled by 4.private ModelSimpleImageSimple version of an image volume of the input image, subsampled by 8.private ModelSimpleImageSimple version of input image.private ModelSimpleImageSimple version of input image, subsampled by 16.private ModelSimpleImageSimple version of input image, subsampled by 2.private ModelSimpleImageSimple version of input image, subsampled by 4.private ModelSimpleImageSimple version of input image, subsampled by 8.private ModelSimpleImageDOCUMENT ME!private ModelSimpleImageDOCUMENT ME!private ModelSimpleImageDOCUMENT ME!private ModelSimpleImageDOCUMENT ME!private ModelSimpleImageDOCUMENT ME!private ModelSimpleImageSimple version of weighted input image.private ModelSimpleImageSimple version of weighted input image, subsampled by 16.private ModelSimpleImageSimple version of weighted input image, subsampled by 2.private ModelSimpleImageSimple version of weighted input image, subsampled by 4.private ModelSimpleImageSimple version of weighted input image, subsampled by 8.private float[][]DOCUMENT ME!private int[]private booleanDOCUMENT ME!private TransMatrix[]private booleanFlag to determine if there are weighted images or not.private ModelImageDOCUMENT 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, threadStoppedFields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
ConstructorsConstructorDescriptionAlgorithmRegOAR35D(ModelImage _image, int _costChoice, int _DOF, int _interp, int _interp2, int mode, int refImageNum, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doGraph, boolean doSubsample, boolean fastMode, int _baseNumIter, int _numMinima) Creates new automatic internal registration algorithm and sets necessary variables.AlgorithmRegOAR35D(ModelImage _image, ModelImage _inputWeight, int _costChoice, int _DOF, int _interp, int _interp2, int mode, int refImageNum, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doGraph, boolean doSubsample, boolean fastMode, int _baseNumIter, int _numMinima) Creates new automatic internal registration algorithm and sets necessary variables. -
Method Summary
Modifier and TypeMethodDescriptionstatic WildMagic.LibFoundation.Mathematics.Vector3fcalculateCenterOfMass3D(ModelSimpleImage image, ModelSimpleImage wgtImage, boolean isColor) Calculates the center of mass (gravity) of a 3D image.private voidcopyFloatData(ModelSimpleImage srcImage, ModelSimpleImage resultImage) DOCUMENT ME!voidDispose of local variables that may be taking up lots of room.voidfinalize()Prepares this class for destruction.voidA test of the diffeomorphic demons is to transform a circle image to a letter C image.doubleSorts the array of transformation matricies and returns the sorted array.Sorts the array of transformation matricies and returns the sorted array.private StringCreates a string with the parameters that the image was constructed with.float[][]getRot()accessor for rot.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) and the level of subsampling (1, 2, 4, 8).float[][]getTrans()accessor for trans.accessor to get the internally registered image.private voidinterpolate(double x, double[] initial, double[][] tranforms, boolean scale) Performs a bilinear interpolation on points.private voidinterpolate(double x, double y, double z, double[] initial, double[][][][] tranforms, boolean scale) Performs a trilinear interpolation on points.private Vector<AlgorithmRegOAR35D.MatrixListItem>[]levelEight(ModelSimpleImage ref, ModelSimpleImage input) Takes two images that have been subsampled by a factor of eight.private Vector<AlgorithmRegOAR35D.MatrixListItem> levelFour(ModelSimpleImage ref, ModelSimpleImage input, Vector<AlgorithmRegOAR35D.MatrixListItem> minima, Vector<AlgorithmRegOAR35D.MatrixListItem> optMinima) Takes two images that have been subsampled by a factor of four, and two vectors of minima.levelOne(ModelSimpleImage ref, ModelSimpleImage input, AlgorithmRegOAR35D.MatrixListItem item, int maxIter) Takes the two images, no subsampling, and the best minimum so far.levelTwo(ModelSimpleImage ref, ModelSimpleImage input, Vector<AlgorithmRegOAR35D.MatrixListItem> minima) Takes two images that have been subsampled by a factor of 2 and a vector of minima.voidRuns the image registration.voidsetJTEM(boolean bOn) Turns the full version of Powell's algorithm on/off.booleansetReferenceVolume(ModelImage refVolume) allows the user to pass in an OUTSIDE reference volume.private voidsubSampleBy2(ModelSimpleImage srcImage, ModelSimpleImage resultImage, boolean isColor) Takes a simple image and subsamples it by 2, interpolating so that the new values are averages.private static ModelSimpleImagesubSampleBy2XY(ModelSimpleImage srcImage, ModelSimpleImage resultImage, boolean isColor) Takes a simple image and subsamples XY by 2, interpolating so that the new XY 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, windowOpenedMethods 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, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, resume, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, suspend, threadId, toString, yield
-
Field Details
-
ADJACENT
private static final int ADJACENTDOCUMENT ME!- See Also:
-
AVERAGE
private static final int AVERAGEDOCUMENT ME!- See Also:
-
minimumZForSub
private static final int minimumZForSubDOCUMENT ME!- See Also:
-
allowLevel16XY
private boolean allowLevel16XYDOCUMENT ME! -
allowLevel16Z
private boolean allowLevel16ZDOCUMENT ME! -
allowLevel2XY
private boolean allowLevel2XYFlags are true if weighted image is not present or if weighted image subsampling occurred, false if weighted image subsampling did not occur. -
allowLevel2Z
private boolean allowLevel2ZDOCUMENT ME! -
allowLevel4XY
private boolean allowLevel4XYDOCUMENT ME! -
allowLevel4Z
private boolean allowLevel4ZDOCUMENT ME! -
allowLevel8XY
private boolean allowLevel8XYDOCUMENT ME! -
allowLevel8Z
private boolean allowLevel8ZDOCUMENT ME! -
answer
Final answer after registration. -
buffer
private float[] bufferDOCUMENT ME! -
bufferA
private float[] bufferADOCUMENT ME! -
bufferIW
private float[] bufferIWDOCUMENT ME! -
bufferW
private float[] bufferWDOCUMENT ME! -
calcCOG
private boolean calcCOGIf true calculate the center of gravity (mass) and use the difference to intialize the translation. If false, images are pretty much aligned and don't calculate COG. -
coarseNum
private int coarseNumNumber of passes that will be made in the coarse sampling and fine sampling. -
fineNum
private int fineNumNumber of passes that will be made in the coarse sampling and fine sampling. -
colorFactor
private int colorFactor1 for black and white, 4 for color. -
costChoice
private int costChoiceChoice of which cost function to use. -
doColor
private boolean doColorDOCUMENT ME! -
VolumesToReferenceTransformations
-
DOF
private int DOFMaximum degrees of freedom when running the optimization. -
doGraph
private boolean doGraphProduce 2 output graphs - 1 for 3 rotations and 1 for 3 translations. Only can be used for DOF == 6 and register to average or reference volume -
doSubsample
private boolean doSubsampleif true subsample. -
fastMode
private boolean fastModeIf true this algorithm skips all subsample and goes directly to the level 1 optimization. This assumes that images are fairly well aligned to begin with and therefore no sophisticated search is needed. -
imageWeightIso
DOCUMENT ME! -
input1
Image used to import a volume from inputImage. -
inputImage
This is the image in which internal registration will be performed. -
inputw_1
Image used to import a volume from inputWeight. -
inputWeight
This gives weights for the input image - higher weights mean a greater impact in that area on the registration. -
interp
private int interpInterpolation method used in transformations. -
interp2
private int interp2Interpolation method used in output. -
iResols
private float[] iResolsThe voxel resolutions of the input image. -
isoImage
new to this version: must keep isoImage around if image needed to be transformed. -
level1FactorXY
private float level1FactorXYMultiplication factor for level 1 - will be set based on subsampling. -
level1FactorZ
private float level1FactorZDOCUMENT ME! -
level2FactorXY
private float level2FactorXYMultiplication factor for level 2 - will be set based on subsampling. -
level2FactorZ
private float level2FactorZDOCUMENT ME! -
level4FactorXY
private float level4FactorXYMultiplication factor for level 4 - will be set based on subsampling. -
level4FactorZ
private float level4FactorZDOCUMENT ME! -
maxDim
private int maxDimDOCUMENT ME! -
maxIter
private int maxIterLimits number of iterations in Powell optimization. maxIter in the call to Powell's will be an integer multiple of baseNumIter -
baseNumIter
private int baseNumIterLimits number of iterations in Powell optimization. maxIter in the call to Powell's will be an integer multiple of baseNumIter -
mode
private int modeDOCUMENT ME! -
numMinima
private int numMinimaNumber of minima from level 8 to test at level 4. -
output_1
DOCUMENT ME! -
outsidePreReferenceVolume
DOCUMENT ME! -
outsideReferenceVolume
DOCUMENT ME! -
refImageNo
private int refImageNoIndicates the first volume used as a reference volume, if mode == ADJACENT. -
regToAdjImage
private boolean regToAdjImageIf true use adjacent image for registration. If false use the average volume or use the image volume reference number to indicate the image volume to register all images to. -
resample
private boolean resampletrue if resolutions unequal, false if resolutions equal. -
resampleW
private boolean resampleWtrue if weight image is resampled. -
rot
private float[][] rotArrays used for producing graphs for DOF == 6 and register to average or reference image. -
rotateBegin
private float rotateBeginCoarse and fine sampling parameters. -
rotateEnd
private float rotateEndCoarse and fine sampling parameters. -
coarseRate
private float coarseRateCoarse and fine sampling parameters. -
fineRate
private float fineRateCoarse and fine sampling parameters. -
simpleInput_1
Simple version of an image volume of the input image. -
simpleInputSub16_1
Simple version of an image volume of the input image, subsampled by 16. -
simpleInputSub2_1
Simple version of an image volume of the input image, subsampled by 2. -
simpleInputSub4_1
Simple version of an image volume of the input image, subsampled by 4. -
simpleInputSub8_1
Simple version of an image volume of the input image, subsampled by 8. -
simpleRef_1
Simple version of input image. -
simpleRefSub16_1
Simple version of input image, subsampled by 16. -
simpleRefSub2_1
Simple version of input image, subsampled by 2. -
simpleRefSub4_1
Simple version of input image, subsampled by 4. -
simpleRefSub8_1
Simple version of input image, subsampled by 8. -
simpleWeightI_1
DOCUMENT ME! -
simpleWeightISub16_1
DOCUMENT ME! -
simpleWeightISub2_1
DOCUMENT ME! -
simpleWeightISub4_1
DOCUMENT ME! -
simpleWeightISub8_1
DOCUMENT ME! -
simpleWeightR_1
Simple version of weighted input image. -
simpleWeightRSub16_1
Simple version of weighted input image, subsampled by 16. -
simpleWeightRSub2_1
Simple version of weighted input image, subsampled by 2. -
simpleWeightRSub4_1
Simple version of weighted input image, subsampled by 4. -
simpleWeightRSub8_1
Simple version of weighted input image, subsampled by 8. -
trans
private float[][] transDOCUMENT ME! -
useOutsideReferenceVolume
private boolean useOutsideReferenceVolumeDOCUMENT ME! -
weighted
private boolean weightedFlag to determine if there are weighted images or not. -
weightVolumeImage
DOCUMENT ME! -
doJTEM
private boolean doJTEMTurns the full version of Powell's algorithm on/off. When off the JTEM line minimization used. -
doMultiThread
private boolean doMultiThread -
TransMatsInumber
private int[] TransMatsInumber
-
-
Constructor Details
-
AlgorithmRegOAR35D
public AlgorithmRegOAR35D(ModelImage _image, int _costChoice, int _DOF, int _interp, int _interp2, int mode, int refImageNum, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doGraph, boolean doSubsample, boolean fastMode, int _baseNumIter, int _numMinima) Creates new automatic internal registration algorithm and sets necessary variables.- Parameters:
_image- Input image_costChoice- Choice of cost functions, like correlation ratio or mutual information._DOF- Degrees of freedom for registration_interp- Interpolation method used in transformations._interp2- Interpolation method used in outputmode- 1 = adjacent, 2 = average, 3 = referencerefImageNum- If mode == REFERENCE, the volume all other volumes are registered to. If mode == ADJACENT, the first volume used as a reference._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).doGraph- If true produce 2 output graphs - one for 3 rotations and one for 3 translationsdoSubsample- If true subsamplefastMode- If true skip subsample and go directly to level 1 optimization_baseNumIter- Limits the number of iterations of Powell's algorithm. maxIter in the call to Powell's will be an integer multiple of baseNumIter_numMinima- Number of minima from level 8 to test at level 4
-
AlgorithmRegOAR35D
public AlgorithmRegOAR35D(ModelImage _image, ModelImage _inputWeight, int _costChoice, int _DOF, int _interp, int _interp2, int mode, int refImageNum, float _rotateBegin, float _rotateEnd, float _coarseRate, float _fineRate, boolean doGraph, boolean doSubsample, boolean fastMode, int _baseNumIter, int _numMinima) Creates new automatic internal registration algorithm and sets necessary variables.- Parameters:
_image- Input image_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- DOCUMENT ME!_interp- Interpolation method used in transformations._interp2- Interpolation method used in outputmode- 1 = adjacent, 2 = average, 3 = averagerefImageNum- If mode == REFERENCE, the volume all other volumes are registered to. If mode == ADJACENT, the first volume used as a reference._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).doGraph- If true produce 2 output graphs - 1 for 3 rotations and one for 3 translationsdoSubsample- If true subsamplefastMode- If true skip subsample and go directly to level 1 optimization_baseNumIter- Limits the number of iterations of Powell's algorithm. maxIter in the call to Powell's will be an integer multiple of baseNumIter_numMinima- Number of minima from level 8 to test at level 4
-
-
Method Details
-
setJTEM
public void setJTEM(boolean bOn) Turns the full version of Powell's algorithm on/off.- Parameters:
bOn-
-
calculateCenterOfMass3D
public static WildMagic.LibFoundation.Mathematics.Vector3f calculateCenterOfMass3D(ModelSimpleImage image, ModelSimpleImage wgtImage, boolean isColor) Calculates the center of mass (gravity) of a 3D 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 and z axis goes into the screen. (i.e. the right hand rule). One could simply multiply by voxel resolutions.- Parameters:
image- the center of mass will be calculated from this image datawgtImage- DOCUMENT ME!isColor- DOCUMENT ME!- Returns:
- the center of mass as a 3D 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
-
getRot
public float[][] getRot()accessor for rot.- Returns:
- rot
-
getTrans
public float[][] getTrans()accessor for trans.- Returns:
- trans
-
getArrayTransMatrix2
Sorts the array of transformation matricies and returns the sorted array. If the sub-volumes are sorted to a sub-volume within the 4D image, then the matrix for the reference volume is the identity matrix.- Returns:
- Array of TransMatrix, one for each sub-volume in the 4D image.
-
getArrayTransMatrix
Sorts the array of transformation matricies and returns the sorted array. If the sub-volumes are sorted to a sub-volume within the 4D image, then the matrix for the reference volume is the identity matrix.- Returns:
- Array of TransMatrix, one for each sub-volume in the 4D image.
-
getTransform
-
getAnswer
public double getAnswer() -
getTransformedImage
accessor to get the internally registered image.- Returns:
- inputImage
-
runAlgorithm
public void runAlgorithm()Runs the image registration. If the resolutions are unequal, the image is transformed into isotropic pixels. The resolutions of the two images after the xyz isotropic transformation will be the same in the x, y, and z dimensions. That resolution will equal the minimum resolution. If the image is weighted, the weight image is transformed into isotropic pixels in the same manner as the original. Then the image is subsampled by 2, 4, and 8 or 16. If the image is too small it will not be subsampled down to the smallest level; if it is too big, it will be subsampled to 8 or 16. The same is done with the weight image if necessary. The program loops thru levelEight, levelFour, levelTwo, and levelOne with one volume as the reference volume and one volume as the input volume. The function levelEight is called with the volumes subsampled by 8 or 16; it returns two vectors with minima. Then the function levelFour is called with volumes subsampled by 4 and the two vectors; it returns one vector of minima. The function levelTwo is called with volumes 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 is used to register the input volume to the reference volume. The registered input volume data is imported into inputImage.- Specified by:
runAlgorithmin classAlgorithmBase
-
generateTestImages
public void generateTestImages()A test of the diffeomorphic demons is to transform a circle image to a letter C image. -
setReferenceVolume
allows the user to pass in an OUTSIDE reference volume.- Parameters:
refVolume- 3-Dim image for reference- Returns:
- DOCUMENT ME!
-
subSampleBy2XY
private static ModelSimpleImage subSampleBy2XY(ModelSimpleImage srcImage, ModelSimpleImage resultImage, boolean isColor) Takes a simple image and subsamples XY by 2, interpolating so that the new XY values are averages.- Parameters:
srcImage- Image to subsample.resultImage- DOCUMENT ME!isColor- DOCUMENT ME!- Returns:
- Subsampled image.
-
copyFloatData
DOCUMENT ME!- Parameters:
srcImage- DOCUMENT ME!resultImage- DOCUMENT ME!
-
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) and the level of subsampling (1, 2, 4, 8).- 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 AlgorithmPowell 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.
-
interpolate
private void interpolate(double x, double y, double z, double[] initial, double[][][][] tranforms, boolean scale) Performs a trilinear interpolation on points. Takes 3 initial points, a vector of values to set, and an array in which to look at neighbors of those points. Sets the appropriate values in the vector. Does not set scale if the scale parameter isfalse.- Parameters:
x- X rotation initial index into array.y- Y rotation initial index into array.z- Z rotation initial index into array.initial- Vector to set; if scale istrue, set three translations and a scale. Otherwise just set translations.tranforms- DOCUMENT ME!scale-truemeans set the scale in the vector.
-
levelEight
private Vector<AlgorithmRegOAR35D.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, -30, -30), (-30, -30, -15), (-30, -30, 0), etc. In this case there would be a total of 125 calls to the optimization method. 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 8 neighbors of a point: +, =, or - one fine sample in each of the three directions. 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 rotations as well as translations and global scale. (Previously had not optimized over rotations.) 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
private Vector<AlgorithmRegOAR35D.MatrixListItem> levelFour(ModelSimpleImage ref, ModelSimpleImage input, Vector<AlgorithmRegOAR35D.MatrixListItem> minima, Vector<AlgorithmRegOAR35D.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 rotations in each dimension by zero and plus-minus fineDelta. If it's not a rigid transformation, perturbs the scales 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
private AlgorithmRegOAR35D.MatrixListItem levelOne(ModelSimpleImage ref, ModelSimpleImage input, AlgorithmRegOAR35D.MatrixListItem item, int maxIter) 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 12). Returns the best minimum.- Parameters:
ref- Reference image.input- Input image.item- Best minimum so far.maxIter- DOCUMENT ME!- Returns:
- Best minimum after optimization.
-
levelTwo
private AlgorithmRegOAR35D.MatrixListItem levelTwo(ModelSimpleImage ref, ModelSimpleImage input, Vector<AlgorithmRegOAR35D.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 7 degrees of freedom, then 9, then 12. If the user has limited the degrees of freedom to 6, there will only be one optimization run, with 6 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.
-
subSampleBy2
Takes a simple image and subsamples it by 2, interpolating so that the new values are averages.- Parameters:
srcImage- Image to subsample.resultImage- DOCUMENT ME!isColor- DOCUMENT ME!
-