Class AlgorithmRegOAR35D
- java.lang.Object
-
- java.lang.Thread
-
- gov.nih.mipav.model.algorithms.AlgorithmBase
-
- gov.nih.mipav.model.algorithms.registration.AlgorithmRegOAR35D
-
- All Implemented Interfaces:
java.awt.event.ActionListener
,java.awt.event.WindowListener
,java.lang.Runnable
,java.util.EventListener
public class AlgorithmRegOAR35D 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.
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 Classes Modifier and Type Class Description (package private) class
AlgorithmRegOAR35D.MatrixListItem
Helper class to make it easy to store the necessary information about a minimum.
-
Field Summary
Fields Modifier and Type Field Description private static int
ADJACENT
DOCUMENT ME!private boolean
allowLevel16XY
DOCUMENT ME!private boolean
allowLevel16Z
DOCUMENT ME!private boolean
allowLevel2XY
Flags are true if weighted image is not present or if weighted image subsampling occurred, false if weighted image subsampling did not occur.private boolean
allowLevel2Z
DOCUMENT ME!private boolean
allowLevel4XY
DOCUMENT ME!private boolean
allowLevel4Z
DOCUMENT ME!private boolean
allowLevel8XY
DOCUMENT ME!private boolean
allowLevel8Z
DOCUMENT ME!private AlgorithmRegOAR35D.MatrixListItem
answer
Final answer after registration.private static int
AVERAGE
DOCUMENT ME!private int
baseNumIter
Limits number of iterations in Powell optimization. maxIter in the call to Powell's will be an integer multiple of baseNumIterprivate float[]
buffer
DOCUMENT ME!private float[]
bufferA
DOCUMENT ME!private float[]
bufferIW
DOCUMENT ME!private float[]
bufferW
DOCUMENT ME!private boolean
calcCOG
If true calculate the center of gravity (mass) and use the difference to intialize the translation.private int
coarseNum
Number of passes that will be made in the coarse sampling and fine sampling.private float
coarseRate
Coarse and fine sampling parameters.private int
colorFactor
1 for black and white, 4 for color.private int
costChoice
Choice of which cost function to use.private boolean
doColor
DOCUMENT ME!private int
DOF
Maximum degrees of freedom when running the optimization.private boolean
doGraph
Produce 2 output graphs - 1 for 3 rotations and 1 for 3 translations.private boolean
doJTEM
Turns the full version of Powell's algorithm on/off.private boolean
doMultiThread
private boolean
doSubsample
if true subsample.private boolean
fastMode
If true this algorithm skips all subsample and goes directly to the level 1 optimization.private int
fineNum
Number of passes that will be made in the coarse sampling and fine sampling.private float
fineRate
Coarse and fine sampling parameters.private ModelImage
imageWeightIso
DOCUMENT ME!private ModelImage
input1
Image used to import a volume from inputImage.private ModelImage
inputImage
This is the image in which internal registration will be performed.private ModelImage
inputw_1
Image used to import a volume from inputWeight.private ModelImage
inputWeight
This gives weights for the input image - higher weights mean a greater impact in that area on the registration.private int
interp
Interpolation method used in transformations.private int
interp2
Interpolation method used in output.private float[]
iResols
The voxel resolutions of the input image.private ModelImage
isoImage
new to this version: must keep isoImage around if image needed to be transformed.private float
level1FactorXY
Multiplication factor for level 1 - will be set based on subsampling.private float
level1FactorZ
DOCUMENT ME!private float
level2FactorXY
Multiplication factor for level 2 - will be set based on subsampling.private float
level2FactorZ
DOCUMENT ME!private float
level4FactorXY
Multiplication factor for level 4 - will be set based on subsampling.private float
level4FactorZ
DOCUMENT ME!private int
maxDim
DOCUMENT ME!private int
maxIter
Limits number of iterations in Powell optimization. maxIter in the call to Powell's will be an integer multiple of baseNumIterprivate static int
minimumZForSub
DOCUMENT ME!private int
mode
DOCUMENT ME!private int
numMinima
Number of minima from level 8 to test at level 4.private ModelImage
output_1
DOCUMENT ME!private ModelImage
outsidePreReferenceVolume
DOCUMENT ME!private ModelImage
outsideReferenceVolume
DOCUMENT ME!private int
refImageNo
Indicates the first volume used as a reference volume, if mode == ADJACENT.private boolean
regToAdjImage
If true use adjacent image for registration.private boolean
resample
true if resolutions unequal, false if resolutions equal.private boolean
resampleW
true if weight image is resampled.private float[][]
rot
Arrays used for producing graphs for DOF == 6 and register to average or reference image.private float
rotateBegin
Coarse and fine sampling parameters.private float
rotateEnd
Coarse and fine sampling parameters.private ModelSimpleImage
simpleInput_1
Simple version of an image volume of the input image.private ModelSimpleImage
simpleInputSub16_1
Simple version of an image volume of the input image, subsampled by 16.private ModelSimpleImage
simpleInputSub2_1
Simple version of an image volume of the input image, subsampled by 2.private ModelSimpleImage
simpleInputSub4_1
Simple version of an image volume of the input image, subsampled by 4.private ModelSimpleImage
simpleInputSub8_1
Simple version of an image volume of the input image, subsampled by 8.private ModelSimpleImage
simpleRef_1
Simple version of input image.private ModelSimpleImage
simpleRefSub16_1
Simple version of input image, subsampled by 16.private ModelSimpleImage
simpleRefSub2_1
Simple version of input image, subsampled by 2.private ModelSimpleImage
simpleRefSub4_1
Simple version of input image, subsampled by 4.private ModelSimpleImage
simpleRefSub8_1
Simple version of input image, subsampled by 8.private ModelSimpleImage
simpleWeightI_1
DOCUMENT ME!private ModelSimpleImage
simpleWeightISub16_1
DOCUMENT ME!private ModelSimpleImage
simpleWeightISub2_1
DOCUMENT ME!private ModelSimpleImage
simpleWeightISub4_1
DOCUMENT ME!private ModelSimpleImage
simpleWeightISub8_1
DOCUMENT ME!private ModelSimpleImage
simpleWeightR_1
Simple version of weighted input image.private ModelSimpleImage
simpleWeightRSub16_1
Simple version of weighted input image, subsampled by 16.private ModelSimpleImage
simpleWeightRSub2_1
Simple version of weighted input image, subsampled by 2.private ModelSimpleImage
simpleWeightRSub4_1
Simple version of weighted input image, subsampled by 4.private ModelSimpleImage
simpleWeightRSub8_1
Simple version of weighted input image, subsampled by 8.private float[][]
trans
DOCUMENT ME!private int[]
TransMatsInumber
private boolean
useOutsideReferenceVolume
DOCUMENT ME!private TransMatrix[]
VolumesToReferenceTransformations
private boolean
weighted
Flag to determine if there are weighted images or not.private ModelImage
weightVolumeImage
DOCUMENT 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 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.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
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static WildMagic.LibFoundation.Mathematics.Vector3f
calculateCenterOfMass3D(ModelSimpleImage image, ModelSimpleImage wgtImage, boolean isColor)
Calculates the center of mass (gravity) of a 3D image.private void
copyFloatData(ModelSimpleImage srcImage, ModelSimpleImage resultImage)
DOCUMENT ME!void
disposeLocal()
Dispose of local variables that may be taking up lots of room.void
finalize()
Prepares this class for destruction.void
generateTestImages()
A test of the diffeomorphic demons is to transform a circle image to a letter C image.double
getAnswer()
TransMatrix[]
getArrayTransMatrix()
Sorts the array of transformation matricies and returns the sorted array.TransMatrix[]
getArrayTransMatrix2()
Sorts the array of transformation matricies and returns the sorted array.private java.lang.String
getConstructionInfo()
Creates 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.TransMatrix
getTransform()
ModelImage
getTransformedImage()
accessor to get the internally registered image.private void
interpolate(double x, double[] initial, double[][] tranforms, boolean scale)
Performs a bilinear interpolation on points.private void
interpolate(double x, double y, double z, double[] initial, double[][][][] tranforms, boolean scale)
Performs a trilinear interpolation on points.private java.util.Vector<AlgorithmRegOAR35D.MatrixListItem>[]
levelEight(ModelSimpleImage ref, ModelSimpleImage input)
Takes two images that have been subsampled by a factor of eight.private java.util.Vector<AlgorithmRegOAR35D.MatrixListItem>
levelFour(ModelSimpleImage ref, ModelSimpleImage input, java.util.Vector<AlgorithmRegOAR35D.MatrixListItem> minima, java.util.Vector<AlgorithmRegOAR35D.MatrixListItem> optMinima)
Takes two images that have been subsampled by a factor of four, and two vectors of minima.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.private AlgorithmRegOAR35D.MatrixListItem
levelTwo(ModelSimpleImage ref, ModelSimpleImage input, java.util.Vector<AlgorithmRegOAR35D.MatrixListItem> minima)
Takes two images that have been subsampled by a factor of 2 and a vector of minima.void
runAlgorithm()
Runs the image registration.void
setJTEM(boolean bOn)
Turns the full version of Powell's algorithm on/off.boolean
setReferenceVolume(ModelImage refVolume)
allows the user to pass in an OUTSIDE reference volume.private void
subSampleBy2(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 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.-
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
-
ADJACENT
private static final int ADJACENT
DOCUMENT ME!- See Also:
- Constant Field Values
-
AVERAGE
private static final int AVERAGE
DOCUMENT ME!- See Also:
- Constant Field Values
-
minimumZForSub
private static final int minimumZForSub
DOCUMENT ME!- See Also:
- Constant Field Values
-
allowLevel16XY
private boolean allowLevel16XY
DOCUMENT ME!
-
allowLevel16Z
private boolean allowLevel16Z
DOCUMENT ME!
-
allowLevel2XY
private boolean allowLevel2XY
Flags 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 allowLevel2Z
DOCUMENT ME!
-
allowLevel4XY
private boolean allowLevel4XY
DOCUMENT ME!
-
allowLevel4Z
private boolean allowLevel4Z
DOCUMENT ME!
-
allowLevel8XY
private boolean allowLevel8XY
DOCUMENT ME!
-
allowLevel8Z
private boolean allowLevel8Z
DOCUMENT ME!
-
answer
private AlgorithmRegOAR35D.MatrixListItem answer
Final answer after registration.
-
buffer
private float[] buffer
DOCUMENT ME!
-
bufferA
private float[] bufferA
DOCUMENT ME!
-
bufferIW
private float[] bufferIW
DOCUMENT ME!
-
bufferW
private float[] bufferW
DOCUMENT ME!
-
calcCOG
private boolean calcCOG
If 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 coarseNum
Number of passes that will be made in the coarse sampling and fine sampling.
-
fineNum
private int fineNum
Number of passes that will be made in the coarse sampling and fine sampling.
-
colorFactor
private int colorFactor
1 for black and white, 4 for color.
-
costChoice
private int costChoice
Choice of which cost function to use.
-
doColor
private boolean doColor
DOCUMENT ME!
-
VolumesToReferenceTransformations
private TransMatrix[] VolumesToReferenceTransformations
-
DOF
private int DOF
Maximum degrees of freedom when running the optimization.
-
doGraph
private boolean doGraph
Produce 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 doSubsample
if true subsample.
-
fastMode
private boolean fastMode
If 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
private ModelImage imageWeightIso
DOCUMENT ME!
-
input1
private ModelImage input1
Image used to import a volume from inputImage.
-
inputImage
private ModelImage inputImage
This is the image in which internal registration will be performed.
-
inputw_1
private ModelImage inputw_1
Image used to import a volume from inputWeight.
-
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 int interp
Interpolation method used in transformations.
-
interp2
private int interp2
Interpolation method used in output.
-
iResols
private float[] iResols
The voxel resolutions of the input image.
-
isoImage
private ModelImage isoImage
new to this version: must keep isoImage around if image needed to be transformed.
-
level1FactorXY
private float level1FactorXY
Multiplication factor for level 1 - will be set based on subsampling.
-
level1FactorZ
private float level1FactorZ
DOCUMENT ME!
-
level2FactorXY
private float level2FactorXY
Multiplication factor for level 2 - will be set based on subsampling.
-
level2FactorZ
private float level2FactorZ
DOCUMENT ME!
-
level4FactorXY
private float level4FactorXY
Multiplication factor for level 4 - will be set based on subsampling.
-
level4FactorZ
private float level4FactorZ
DOCUMENT ME!
-
maxDim
private int maxDim
DOCUMENT ME!
-
maxIter
private int maxIter
Limits number of iterations in Powell optimization. maxIter in the call to Powell's will be an integer multiple of baseNumIter
-
baseNumIter
private int baseNumIter
Limits number of iterations in Powell optimization. maxIter in the call to Powell's will be an integer multiple of baseNumIter
-
mode
private int mode
DOCUMENT ME!
-
numMinima
private int numMinima
Number of minima from level 8 to test at level 4.
-
output_1
private ModelImage output_1
DOCUMENT ME!
-
outsidePreReferenceVolume
private ModelImage outsidePreReferenceVolume
DOCUMENT ME!
-
outsideReferenceVolume
private ModelImage outsideReferenceVolume
DOCUMENT ME!
-
refImageNo
private int refImageNo
Indicates the first volume used as a reference volume, if mode == ADJACENT.
-
regToAdjImage
private boolean regToAdjImage
If 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 resample
true if resolutions unequal, false if resolutions equal.
-
resampleW
private boolean resampleW
true if weight image is resampled.
-
rot
private float[][] rot
Arrays used for producing graphs for DOF == 6 and register to average or reference image.
-
rotateBegin
private float rotateBegin
Coarse and fine sampling parameters.
-
rotateEnd
private float rotateEnd
Coarse and fine sampling parameters.
-
coarseRate
private float coarseRate
Coarse and fine sampling parameters.
-
fineRate
private float fineRate
Coarse and fine sampling parameters.
-
simpleInput_1
private ModelSimpleImage simpleInput_1
Simple version of an image volume of the input image.
-
simpleInputSub16_1
private ModelSimpleImage simpleInputSub16_1
Simple version of an image volume of the input image, subsampled by 16.
-
simpleInputSub2_1
private ModelSimpleImage simpleInputSub2_1
Simple version of an image volume of the input image, subsampled by 2.
-
simpleInputSub4_1
private ModelSimpleImage simpleInputSub4_1
Simple version of an image volume of the input image, subsampled by 4.
-
simpleInputSub8_1
private ModelSimpleImage simpleInputSub8_1
Simple version of an image volume of the input image, subsampled by 8.
-
simpleRef_1
private ModelSimpleImage simpleRef_1
Simple version of input image.
-
simpleRefSub16_1
private ModelSimpleImage simpleRefSub16_1
Simple version of input image, subsampled by 16.
-
simpleRefSub2_1
private ModelSimpleImage simpleRefSub2_1
Simple version of input image, subsampled by 2.
-
simpleRefSub4_1
private ModelSimpleImage simpleRefSub4_1
Simple version of input image, subsampled by 4.
-
simpleRefSub8_1
private ModelSimpleImage simpleRefSub8_1
Simple version of input image, subsampled by 8.
-
simpleWeightI_1
private ModelSimpleImage simpleWeightI_1
DOCUMENT ME!
-
simpleWeightISub16_1
private ModelSimpleImage simpleWeightISub16_1
DOCUMENT ME!
-
simpleWeightISub2_1
private ModelSimpleImage simpleWeightISub2_1
DOCUMENT ME!
-
simpleWeightISub4_1
private ModelSimpleImage simpleWeightISub4_1
DOCUMENT ME!
-
simpleWeightISub8_1
private ModelSimpleImage simpleWeightISub8_1
DOCUMENT ME!
-
simpleWeightR_1
private ModelSimpleImage simpleWeightR_1
Simple version of weighted input image.
-
simpleWeightRSub16_1
private ModelSimpleImage simpleWeightRSub16_1
Simple version of weighted input image, subsampled by 16.
-
simpleWeightRSub2_1
private ModelSimpleImage simpleWeightRSub2_1
Simple version of weighted input image, subsampled by 2.
-
simpleWeightRSub4_1
private ModelSimpleImage simpleWeightRSub4_1
Simple version of weighted input image, subsampled by 4.
-
simpleWeightRSub8_1
private ModelSimpleImage simpleWeightRSub8_1
Simple version of weighted input image, subsampled by 8.
-
trans
private float[][] trans
DOCUMENT ME!
-
useOutsideReferenceVolume
private boolean useOutsideReferenceVolume
DOCUMENT ME!
-
weighted
private boolean weighted
Flag to determine if there are weighted images or not.
-
weightVolumeImage
private ModelImage weightVolumeImage
DOCUMENT ME!
-
doJTEM
private boolean doJTEM
Turns 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 Detail
-
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 Detail
-
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:
finalize
in classAlgorithmBase
-
getRot
public float[][] getRot()
accessor for rot.- Returns:
- rot
-
getTrans
public float[][] getTrans()
accessor for trans.- Returns:
- trans
-
getArrayTransMatrix2
public TransMatrix[] 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
public TransMatrix[] 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
public TransMatrix getTransform()
-
getAnswer
public double getAnswer()
-
getTransformedImage
public ModelImage 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:
runAlgorithm
in classAlgorithmBase
-
generateTestImages
public void generateTestImages()
A test of the diffeomorphic demons is to transform a circle image to a letter C image.
-
setReferenceVolume
public boolean setReferenceVolume(ModelImage refVolume)
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
private void copyFloatData(ModelSimpleImage srcImage, ModelSimpleImage resultImage)
DOCUMENT ME!- Parameters:
srcImage
- DOCUMENT ME!resultImage
- DOCUMENT ME!
-
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) 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
-true
means 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
-true
means set the scale in the vector.
-
levelEight
private java.util.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 java.util.Vector<AlgorithmRegOAR35D.MatrixListItem> levelFour(ModelSimpleImage ref, ModelSimpleImage input, java.util.Vector<AlgorithmRegOAR35D.MatrixListItem> minima, java.util.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, java.util.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
private void subSampleBy2(ModelSimpleImage srcImage, ModelSimpleImage resultImage, boolean isColor)
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!
-
-