Package gov.nih.mipav.model.algorithms
Class AlgorithmBrainExtractor
java.lang.Object
java.lang.Thread
gov.nih.mipav.model.algorithms.AlgorithmBase
gov.nih.mipav.model.algorithms.AlgorithmBrainExtractor
- All Implemented Interfaces:
ActionListener,WindowListener,Runnable,EventListener
A class for segmenting the brain from a 3D MRI. The algorithm is partially based on the paper:
BET: Brain Extraction Tool
Stephen M. Smith
FMRIB Technical Report TR00SMS2
Oxford Centre for Functional Magnetic Resonance Imaging of the Brain
See the document BrainExtraction.pdf for a detailed description of the algorithm as implemented in this class. A few modifications to the original algorithm were made.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classA representation of an edge for the vertex-edge-triangle table.private classAn unordered set of 'int' stored in an array.Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final booleanIf true stop processing.private floatfactor above median at which edge values are taken to zero.private float[]DOCUMENT ME!private int[]DOCUMENT ME!private booleanIf true, do not phyically segment the image but generate a paint mask.private floatFactor used in controlling the input of the tangetial component of the surface evolution.protected floatControls how much the image influences the surface evolution.private WildMagic.LibGraphics.SceneGraph.TriMeshprotected float[]Stores curvature information of the surface.protected float[]Triangle edge length.protected int[]Surface triangle connection.protected int[]The 3D MRI image stored as a 1D array.protected byte[]Brain segmenation mask.protected AlgorithmBrainExtractor.UnorderedSetInt[]Surface adjacentcy list.protected WildMagic.LibFoundation.Mathematics.Vector3f[]Surface normals.protected WildMagic.LibFoundation.Mathematics.Vector3f[]Surface tangents.protected WildMagic.LibFoundation.Mathematics.Vector3f[]Surface vertex list.protected WildMagic.LibFoundation.Mathematics.Vector3f[]Average vector.protected WildMagic.LibFoundation.Mathematics.Vector3f[]Vertex normal.private floatFactored used to adjust image influence - this is a fixed value.protected floatDOCUMENT ME!protected floatDOCUMENT ME!protected floatMean length of the vector.protected floatDOCUMENT ME!protected floatReduce the size of the 1st axis of the ellipsoid so that it fits entirely into brain.protected floatReduce the size of the 2st axis of the ellipsoid so that it fits entirely into brain.protected floatReduce the size of the 3st axis of the ellipsoid so that it fits entirely into brain.protected floatStiffness of the surface.protected floatThe size of a voxel, in voxel units.protected floatThe size of a voxel, in voxel units.protected floatThe size of a voxel, in voxel units.protected intBackgroung threshold.protected intHigh threshold.protected intDilation size used in generating boundary from the surface.protected intThe length of the vector _normal_ to the surface to sample along.protected intHistogram maximum intensity parameter.protected intHistogram median intensity parameter.protected intHistogram minimum intensity parameter.protected intThe MRI image bounds and quantity of voxels.protected intThe number of triangle in the ellipsoid.protected intThe number of vertices in the ellipsoid.protected intThe MRI image bounds and quantity of voxels.protected intThe MRI image bounds and quantity of voxels.protected intThe MRI image bounds and quantity of voxels.protected WildMagic.LibFoundation.Mathematics.Vector3finitial ellipsoid parameters.protected HashMap<AlgorithmBrainExtractor.Edge, Integer> Edge map.protected WildMagic.LibFoundation.Mathematics.Matrix3fUsed to rotate the initial mesh into the same orientation as the data.private intThe number of voxels that define the brain.protected intNumber of surface evolutions.protected intIndicated the orientation of the dataset.private booleanIf true run one iteration so that one can observe initial surface location.static final intIndicates that the image is in Sagittal or Coronal orientation.private booleanIf true, the surface representing the brain (mesh) is saved.private booleanTells whether second stage which erodes edge values exceeding median by a factor >= aboveMedian occurs.private float[]Origin of the image.private booleanIf true initialize surface as a sphere.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
ConstructorsConstructorDescriptionAlgorithmBrainExtractor(ModelImage srcImg, int orientation, boolean runOneIteration, boolean estimateSphere, WildMagic.LibFoundation.Mathematics.Vector3f centerPoint) Create an extractor for segmenting the brain from a 3D magnetic resonance image.AlgorithmBrainExtractor(ModelImage srcImg, int orientation, WildMagic.LibGraphics.SceneGraph.TriMesh initialMesh, int medianIntensity, WildMagic.LibFoundation.Mathematics.Vector3f centerPoint) Create an extractor for segmenting the brain from a 3D magnetic resonance image. -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCompute the average length of all the edges in the triangle mesh.protected voidCompute the median intensity of those voxels inside the initial ellipsoid.protected voidCompute the median intensity of those voxels inside the initial ellipsoid.protected WildMagic.LibFoundation.Mathematics.Vector3fprotected voidLet V[i] be a vertex in the triangle mesh.protected voidCompute the vertex normals of the triangle mesh.protected booleanApproximate the brain surface by an ellipsoid.protected voidApproximate the intial brain surface by an sphere.voidThe segmentation function.voidfinalize()Prepares this class for destruction.protected voidfloodFill(int iX, int iY, int iZ) Identify voxels enclosed by the brain surface by using a flood fill.protected voidgenerateEllipsoidMesh(int iSubdivisions) Tessellate a unit sphere centered at the origin.final byte[]Get the 3D image that represents the extracted brain.final floatGet the current brain selection term, as described in BrainExtraction.pdf, that is part of the image term in the surface evolution.final floatGet the 3D image that represents the extracted brain.final intGet the dilation size for dilating the voxelized brain surface obtained by rasterizing the triangle mesh.protected final intgetIndex(int iX, int iY, int iZ) A convenience function for mapping the 3D voxel position (iX,iY,iZ) to a 1D array index.protected voidgetInsideVoxels(boolean doErode) Identify all voxels that are inside or on the mesh that represents the brain surface.protected intgetIntersectX(WildMagic.LibFoundation.Mathematics.Vector3f kV0, WildMagic.LibFoundation.Mathematics.Vector3f kV1, WildMagic.LibFoundation.Mathematics.Vector3f kV2, int iY, int iZ) Compute the point of intersection between a line (0,iY,iZ)+t(1,0,0) and the triangle defined by the three input points.protected intgetIntersectY(WildMagic.LibFoundation.Mathematics.Vector3f kV0, WildMagic.LibFoundation.Mathematics.Vector3f kV1, WildMagic.LibFoundation.Mathematics.Vector3f kV2, int iX, int iZ) Compute the point of intersection between a line (iX,0,iZ)+t(0,1,0) and the triangle defined by the three input points.protected intgetIntersectZ(WildMagic.LibFoundation.Mathematics.Vector3f kV0, WildMagic.LibFoundation.Mathematics.Vector3f kV1, WildMagic.LibFoundation.Mathematics.Vector3f kV2, int iX, int iY) Compute the point of intersection between a line (iX,iY,0)+t(0,0,1) and the triangle defined by the three input points.final intGet the maximum depth, as described in BrainExtraction.pdf, that is part of the image term in the surface evolution.final floatGet the spacing along the vertex normal rays, as described in BrainExtraction.pdf, that is part of the image term in the surface evolution.final floatSet the reduction factor for estimating the initial ellipsoid, as described in BrainExtraction.pdf.final floatSet the reduction factor for estimating the initial ellipsoid, as described in BrainExtraction.pdf.final floatSet the reduction factor for estimating the initial ellipsoid, as described in BrainExtraction.pdf.final floatSet the stiffness of the mesh, as described in BrainExtraction.pdf, that is part of the surface normal term in the surface evolution.voidAnalyze the histogram of the 10-bit binned 3D MRI.voidReinitialize when secondStageErosion has been performed so that the mask will match the eroded image.voidStarts the program.protected voidsaveMesh(boolean flip) Internal support to write vertices, normals, and connectivity indices to the file.final voidsetAboveMedian(float aboveMedian) sets the aboveMedian ratio for second stage erosion Edge values >= median * aboveMedian are taken to zero.final voidsetBrainSelection(float fBrainSelection) Set the brain selection term, as described in BrainExtraction.pdf, that is part of the image term in the surface evolution.final voidsetDilationSize(int iDMax) Set the dilation size for dilating the voxelized brain surface obtained by rasterizing the triangle mesh.voidsetExtractPaint(boolean extractPaint) Sets whether to extract the brain to a paint mask instead of removing non-brain image data.final voidsetImageRatio(float ratio) Sets the number of iterations.final voidsetIterations(int nIter) Sets the number of iterations.final voidsetJustIntialEllipsoid(boolean flag) Indicates if surface evolution should be skipped.final voidsetMaxDepth(int iMaxDepth) Set the maximum depth, as described in BrainExtraction.pdf, that is part of the image term in the surface evolution.final voidsetOrientation(int orientation) Indicates the orientation of the image for use in the ellipsoid estimation.final voidsetRayDelta(float fRayDelta) Set the spacing along the vertex normal rays, as described in BrainExtraction.pdf, that is part of the image term in the surface evolution.final voidsetReductionX(float fReduction) Set the reduction factor for estimating the initial ellipsoid, as described in BrainExtraction.pdf.final voidsetReductionY(float fReduction) Set the reduction factor for estimating the initial ellipsoid, as described in BrainExtraction.pdf.final voidsetReductionZ(float fReduction) Set the reduction factor for estimating the initial ellipsoid, as described in BrainExtraction.pdf.voidsetSaveBrainMesh(boolean saveMesh) Sets whether to save a surface mesh of the extracted brain.final voidsetSecondStageErosion(boolean secondStageErosion) Sets whether or not second stage erosion occurs taking edge values exceeding median by a factor >= aboveMedian to zero.final voidsetStiffness(float fStiffness) Set the stiffness of the mesh, as described in BrainExtraction.pdf, that is part of the surface normal term in the surface evolution.final voidsetUseSphere(boolean flag) Don't try estimating ellipse as initial surface use sphere estimate.protected floatupdate2(int i) Compute the coefficient of the surface normal for the update of the mesh vertex V[i] in the SNormal[i] direction.protected floatupdate3(int i) Compute the coefficient of the vertex normal for the update of the mesh vertex V[i] in the VNormal[i] direction.protected booleanupdateCenter(WildMagic.LibFoundation.Mathematics.Vector3f Center) voidThe heart of the segmentation.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
-
SAT_COR
public static final int SAT_CORIndicates that the image is in Sagittal or Coronal orientation.- See Also:
-
imageFactor
protected float imageFactorControls how much the image influences the surface evolution. -
m_afCurvature
protected float[] m_afCurvatureStores curvature information of the surface. -
m_afLength
protected float[] m_afLengthTriangle edge length. -
m_aiConnect
protected int[] m_aiConnectSurface triangle connection. -
m_aiImage
protected int[] m_aiImageThe 3D MRI image stored as a 1D array. The mapping from (x,y,z) to 1D is: index = x + xbound*(y + ybound*z). -
m_aiMask
protected byte[] m_aiMaskBrain segmenation mask. -
m_akAdjacent
Surface adjacentcy list. -
m_akSNormal
protected WildMagic.LibFoundation.Mathematics.Vector3f[] m_akSNormalSurface normals. -
m_akSTangent
protected WildMagic.LibFoundation.Mathematics.Vector3f[] m_akSTangentSurface tangents. -
m_akVertex
protected WildMagic.LibFoundation.Mathematics.Vector3f[] m_akVertexSurface vertex list. -
m_akVMean
protected WildMagic.LibFoundation.Mathematics.Vector3f[] m_akVMeanAverage vector. -
m_akVNormal
protected WildMagic.LibFoundation.Mathematics.Vector3f[] m_akVNormalVertex normal. -
m_fEParam
protected float m_fEParamDOCUMENT ME! -
m_fFParam
protected float m_fFParamDOCUMENT ME! -
m_fMeanEdgeLength
protected float m_fMeanEdgeLengthMean length of the vector. -
m_fRayDelta
protected float m_fRayDeltaDOCUMENT ME! -
m_fReductionX
protected float m_fReductionXReduce the size of the 1st axis of the ellipsoid so that it fits entirely into brain. -
m_fReductionY
protected float m_fReductionYReduce the size of the 2st axis of the ellipsoid so that it fits entirely into brain. -
m_fReductionZ
protected float m_fReductionZReduce the size of the 3st axis of the ellipsoid so that it fits entirely into brain. -
m_fStiffness
protected float m_fStiffnessStiffness of the surface. -
m_fXDelta
protected float m_fXDeltaThe size of a voxel, in voxel units. -
m_fYDelta
protected float m_fYDeltaThe size of a voxel, in voxel units. -
m_fZDelta
protected float m_fZDeltaThe size of a voxel, in voxel units. -
m_iBackThreshold
protected int m_iBackThresholdBackgroung threshold. -
m_iBrightThreshold
protected int m_iBrightThresholdHigh threshold. -
m_iDMax
protected int m_iDMaxDilation size used in generating boundary from the surface. -
m_iMaxDepth
protected int m_iMaxDepthThe length of the vector _normal_ to the surface to sample along. -
m_iMaxThreshold
protected int m_iMaxThresholdHistogram maximum intensity parameter. -
m_iMedianIntensity
protected int m_iMedianIntensityHistogram median intensity parameter. -
m_iMinThreshold
protected int m_iMinThresholdHistogram minimum intensity parameter. -
m_iTQuantity
protected int m_iTQuantityThe number of triangle in the ellipsoid. -
m_iVQuantity
protected int m_iVQuantityThe number of vertices in the ellipsoid. -
m_iXBound
protected int m_iXBoundThe MRI image bounds and quantity of voxels. -
m_iYBound
protected int m_iYBoundThe MRI image bounds and quantity of voxels. -
m_iZBound
protected int m_iZBoundThe MRI image bounds and quantity of voxels. -
m_iQuantity
protected int m_iQuantityThe MRI image bounds and quantity of voxels. -
m_kCenter
protected WildMagic.LibFoundation.Mathematics.Vector3f m_kCenterinitial ellipsoid parameters. -
m_kEMap
Edge map. -
m_kRotate
protected WildMagic.LibFoundation.Mathematics.Matrix3f m_kRotateUsed to rotate the initial mesh into the same orientation as the data. -
nIterations
protected int nIterationsNumber of surface evolutions. -
orientationFlag
protected int orientationFlagIndicated the orientation of the dataset. Default sagittal/cornal -
abort
private final boolean abortIf true stop processing.- See Also:
-
aboveMedian
private float aboveMedianfactor above median at which edge values are taken to zero. -
box
private float[] boxDOCUMENT ME! -
direction
private int[] directionDOCUMENT ME! -
extractPaint
private boolean extractPaintIf true, do not phyically segment the image but generate a paint mask. -
fUpdate1
private float fUpdate1Factor used in controlling the input of the tangetial component of the surface evolution. -
m_fBrainSelection
private float m_fBrainSelectionFactored used to adjust image influence - this is a fixed value. -
nBrainVoxels
private int nBrainVoxelsThe number of voxels that define the brain. -
runOneIter
private boolean runOneIterIf true run one iteration so that one can observe initial surface location. -
saveBrainMesh
private boolean saveBrainMeshIf true, the surface representing the brain (mesh) is saved. -
secondStageErosion
private boolean secondStageErosionTells whether second stage which erodes edge values exceeding median by a factor >= aboveMedian occurs. -
startLocation
private float[] startLocationOrigin of the image. Upper left hand corner of the first image. -
useSphere
private boolean useSphereIf true initialize surface as a sphere. -
initialMesh
private WildMagic.LibGraphics.SceneGraph.TriMesh initialMesh
-
-
Constructor Details
-
AlgorithmBrainExtractor
public AlgorithmBrainExtractor(ModelImage srcImg, int orientation, boolean runOneIteration, boolean estimateSphere, WildMagic.LibFoundation.Mathematics.Vector3f centerPoint) Create an extractor for segmenting the brain from a 3D magnetic resonance image.- Parameters:
srcImg- The source image. Should be MR image of the brainorientation- Image orienationrunOneIteration- Run one iteration so that one can observe initial surface location.estimateSphere- Use sphere as the initial surface to be evolved.centerPoint- The center of the initial ellipsoid or sphere.
-
AlgorithmBrainExtractor
public AlgorithmBrainExtractor(ModelImage srcImg, int orientation, WildMagic.LibGraphics.SceneGraph.TriMesh initialMesh, int medianIntensity, WildMagic.LibFoundation.Mathematics.Vector3f centerPoint) Create an extractor for segmenting the brain from a 3D magnetic resonance image.- Parameters:
srcImg- The source image. Should be MR image of the brainorientation- Image orienationcenterPoint- The center of the initial ellipsoid or sphere.runOneIteration- Run one iteration so that one can observe initial surface location.estimateSphere- Use sphere as the initial surface to be evolved.
-
-
Method Details
-
extractBrain
public void extractBrain()The segmentation function. Ideally, the only work an application needs to do is create an MjBrainExtractor object and call the method extractBrain(). Various parameters managed by MjBrainExtractor may be modified, if necessary, before the call. -
finalize
public void finalize()Prepares this class for destruction.- Overrides:
finalizein classAlgorithmBase
-
getBrainMask
public final byte[] getBrainMask()Get the 3D image that represents the extracted brain. The image is ternary and has the same dimensions as the input MRI. A voxel value of 0 indicates background. A voxel value of 1 indicates brain surface. A voxel value of 2 indicates a voxel inside the brain surface.- Returns:
- the image that represents the extracted brain
-
getBrainSelection
public final float getBrainSelection()Get the current brain selection term, as described in BrainExtraction.pdf, that is part of the image term in the surface evolution. The default value is 0.5.- Returns:
- the current brain selection term
-
getBrainVolume
public final float getBrainVolume()Get the 3D image that represents the extracted brain. The image is ternary and has the same dimensions as the input MRI. A voxel value of 0 indicates background. A voxel value of 1 indicates brain surface. A voxel value of 2 indicates a voxel inside the brain surface.- Returns:
- the image that represents the extracted brain
-
getDilationSize
public final int getDilationSize()Get the dilation size for dilating the voxelized brain surface obtained by rasterizing the triangle mesh. The rasterization is designed so that the voxel surface has no holes, thereby allowing it to be flood-filled. But just in case numerical round-off errors cause a few holes, this parameter is exposed for public use. The default value is 0 (no dilation). If the value is D > 0, the dilation mask is a cube of size (2*D+1)x(2*D+1)x(2*D+1).- Returns:
- the current dilation size
-
getMaxDepth
public final int getMaxDepth()Get the maximum depth, as described in BrainExtraction.pdf, that is part of the image term in the surface evolution. The default value is 7.- Returns:
- the current maximum depth
-
getRayDelta
public final float getRayDelta()Get the spacing along the vertex normal rays, as described in BrainExtraction.pdf, that is part of the image term in the surface evolution. The default value is 1.0.- Returns:
- the current spacing
-
getReductionX
public final float getReductionX()Set the reduction factor for estimating the initial ellipsoid, as described in BrainExtraction.pdf. The default value is 0.6.- Returns:
- the current reduction factor
-
getReductionY
public final float getReductionY()Set the reduction factor for estimating the initial ellipsoid, as described in BrainExtraction.pdf. The default value is 0.4.- Returns:
- the current reduction factor
-
getReductionZ
public final float getReductionZ()Set the reduction factor for estimating the initial ellipsoid, as described in BrainExtraction.pdf. The default value is 0.6.- Returns:
- the current reduction factor
-
getStiffness
public final float getStiffness()Set the stiffness of the mesh, as described in BrainExtraction.pdf, that is part of the surface normal term in the surface evolution. The default value is 0.1.- Returns:
- the current stiffness
-
histogramAnalysis
public void histogramAnalysis()Analyze the histogram of the 10-bit binned 3D MRI. The function computes a minimum threshold, a maximum threshold, and a background threshold that are used in the image term of the surface evolution. A brightness threshold is also computed that is used for determining the initial ellipsoid that approximates the brain surface. -
reIntialize
public void reIntialize()Reinitialize when secondStageErosion has been performed so that the mask will match the eroded image. -
runAlgorithm
public void runAlgorithm()Starts the program.- Specified by:
runAlgorithmin classAlgorithmBase
-
setAboveMedian
public final void setAboveMedian(float aboveMedian) sets the aboveMedian ratio for second stage erosion Edge values >= median * aboveMedian are taken to zero.- Parameters:
aboveMedian- DOCUMENT ME!
-
setBrainSelection
public final void setBrainSelection(float fBrainSelection) Set the brain selection term, as described in BrainExtraction.pdf, that is part of the image term in the surface evolution. The default value is 0.5.- Parameters:
fBrainSelection- the new brain selection term
-
setDilationSize
public final void setDilationSize(int iDMax) Set the dilation size for dilating the voxelized brain surface obtained by rasterizing the triangle mesh. The rasterization is designed so that the voxel surface has no holes, thereby allowing it to be flood-filled. But just in case numerical round-off errors cause a few holes, this parameter is exposed for public use. The default value is 0 (no dilation). If the value is D > 0, the dilation mask is a cube of size (2*D+1)x(2*D+1)x(2*D+1).- Parameters:
iDMax- the new dilation size
-
setExtractPaint
public void setExtractPaint(boolean extractPaint) Sets whether to extract the brain to a paint mask instead of removing non-brain image data.- Parameters:
extractPaint- whether to extract the brain to a paint mask
-
setImageRatio
public final void setImageRatio(float ratio) Sets the number of iterations.- Parameters:
ratio- DOCUMENT ME!
-
setIterations
public final void setIterations(int nIter) Sets the number of iterations.- Parameters:
nIter- DOCUMENT ME!
-
setJustIntialEllipsoid
public final void setJustIntialEllipsoid(boolean flag) Indicates if surface evolution should be skipped. This is helpful when determining if the initial ellipsoid is a good estimate.- Parameters:
flag- if true skip evolution of surface
-
setMaxDepth
public final void setMaxDepth(int iMaxDepth) Set the maximum depth, as described in BrainExtraction.pdf, that is part of the image term in the surface evolution. The default value is 7.- Parameters:
iMaxDepth- the new maximum depth
-
setOrientation
public final void setOrientation(int orientation) Indicates the orientation of the image for use in the ellipsoid estimation.- Parameters:
orientation- the new image orientation
-
setRayDelta
public final void setRayDelta(float fRayDelta) Set the spacing along the vertex normal rays, as described in BrainExtraction.pdf, that is part of the image term in the surface evolution. The default value is 1.0.- Parameters:
fRayDelta- the new normal ray spacing
-
setReductionX
public final void setReductionX(float fReduction) Set the reduction factor for estimating the initial ellipsoid, as described in BrainExtraction.pdf. The default value is 0.6.- Parameters:
fReduction- the amount to reduce the axis of the ellipsoid.
-
setReductionY
public final void setReductionY(float fReduction) Set the reduction factor for estimating the initial ellipsoid, as described in BrainExtraction.pdf. The default value is 0.5.- Parameters:
fReduction- the amount to reduce the axis of the ellipsoid.
-
setReductionZ
public final void setReductionZ(float fReduction) Set the reduction factor for estimating the initial ellipsoid, as described in BrainExtraction.pdf. The default value is 0.6.- Parameters:
fReduction- the amount to reduce the axis of the ellipsoid.
-
setSaveBrainMesh
public void setSaveBrainMesh(boolean saveMesh) Sets whether to save a surface mesh of the extracted brain.- Parameters:
saveMesh- whether to save a brain surface mesh
-
setSecondStageErosion
public final void setSecondStageErosion(boolean secondStageErosion) Sets whether or not second stage erosion occurs taking edge values exceeding median by a factor >= aboveMedian to zero.- Parameters:
secondStageErosion- DOCUMENT ME!
-
setStiffness
public final void setStiffness(float fStiffness) Set the stiffness of the mesh, as described in BrainExtraction.pdf, that is part of the surface normal term in the surface evolution. The default value is 0.1.- Parameters:
fStiffness- the new stiffness
-
setUseSphere
public final void setUseSphere(boolean flag) Don't try estimating ellipse as initial surface use sphere estimate.- Parameters:
flag- if true estimate initial surface with sphere and not ellipse.
-
updateMesh
public void updateMesh()The heart of the segmentation. This function is responsible for the evolution of the triangle mesh that approximates the brain surface. The update has a tangential component, a surface normal component, and a vertex normal component for each vertex in the mesh. The first two components control the geometry of the mesh. The last component is based on the MRI data itself. See BrainExtraction.pdf for a detailed description of the update terms. -
computeMeanEdgeLength
protected void computeMeanEdgeLength()Compute the average length of all the edges in the triangle mesh. -
computeMedianIntensityInitial
protected void computeMedianIntensityInitial()Compute the median intensity of those voxels inside the initial ellipsoid. This intensity is used in the image term of the surface evolution. -
computeMedianIntensity
protected void computeMedianIntensity()Compute the median intensity of those voxels inside the initial ellipsoid. This intensity is used in the image term of the surface evolution. -
computeVertexInformation
protected void computeVertexInformation()Let V[i] be a vertex in the triangle mesh. This function computes VMean[i], the average of the immediate neighbors of V[i]. Define S[i] = VMean[i] - V[i]. The function also computes a surface normal SNormal[i], the component of S[i] in the vertex normal direction. STangent[i] = S[i] - SNormal[i] is computed as an approximation to a tangent to the surface. Finally, Curvature[i] is an approximation of the surface curvature at V[i]. -
computeVertexNormals
protected void computeVertexNormals()Compute the vertex normals of the triangle mesh. Each vertex normal is the unitized average of the non-unit triangle normals for those triangles sharing the vertex. -
computeNewCenter
protected WildMagic.LibFoundation.Mathematics.Vector3f computeNewCenter() -
estimateEllipsoid
protected boolean estimateEllipsoid()Approximate the brain surface by an ellipsoid. The approximation is based on locating all voxels of intensity larger than a brightness threshold and that are part of the upper-half of the head. The idea is that the scalp voxels in the upper-half form lie approximately on an ellipsoidal surface.
NOTE. The assumption is that the traversal from bottom to top of head is in the y-direction of the 3D image. It does not matter if the top of the head has y-values smaller/larger than those for the bottom of the head. If this assumption is not met, the image should be permuted OR this code must be modified to attempt to recognize the orientation of the head
- Returns:
- DOCUMENT ME!
-
estimateSphere
protected void estimateSphere()Approximate the intial brain surface by an sphere. Find the center of mass and approimate radius -
floodFill
protected void floodFill(int iX, int iY, int iZ) Identify voxels enclosed by the brain surface by using a flood fill. The flood fill is nonrecursive to avoid overflowing the program stack.- Parameters:
iX- the x-value of the seed point for the filliY- the y-value of the seed point for the filliZ- the z-value of the seed point for the fill
-
generateEllipsoidMesh
protected void generateEllipsoidMesh(int iSubdivisions) Tessellate a unit sphere centered at the origin. Start with an octahedron and subdivide. The final mesh is then affinely mapped to the initial ellipsoid produced by estimateEllipsoid(). The subdivision scheme is described in BrainExtraction.pdf.- Parameters:
iSubdivisions- the number of levels to subdivide the ellipsoid
-
getIndex
protected final int getIndex(int iX, int iY, int iZ) A convenience function for mapping the 3D voxel position (iX,iY,iZ) to a 1D array index. The images are stored as 1D arrays, so this function is used frequently.- Parameters:
iX- the x-value of the voxel positioniY- the y-value of the voxel positioniZ- the z-value of the voxel position- Returns:
- the 1D array index corresponding to (iX,iY,iZ)
-
getInsideVoxels
protected void getInsideVoxels(boolean doErode) Identify all voxels that are inside or on the mesh that represents the brain surface. The surface voxels are constructed by rasterizing the triangles of the mesh in 3D. The centroid of these voxels is used as a seed point for a flood fill of the region enclosed by the surface.- Parameters:
doErode- DOCUMENT ME!
-
getIntersectX
protected int getIntersectX(WildMagic.LibFoundation.Mathematics.Vector3f kV0, WildMagic.LibFoundation.Mathematics.Vector3f kV1, WildMagic.LibFoundation.Mathematics.Vector3f kV2, int iY, int iZ) Compute the point of intersection between a line (0,iY,iZ)+t(1,0,0) and the triangle defined by the three input points. All calculations are in voxel coordinates and the x-value of the intersection point is truncated to an integer.- Parameters:
kV0- a 3D vertex of the trianglekV1- a 3D vertex of the trianglekV2- a 3D vertex of the triangleiY- the y-value of the origin of the lineiZ- the z-value of the origin of the line- Returns:
- the x-value of the intersection
-
getIntersectY
protected int getIntersectY(WildMagic.LibFoundation.Mathematics.Vector3f kV0, WildMagic.LibFoundation.Mathematics.Vector3f kV1, WildMagic.LibFoundation.Mathematics.Vector3f kV2, int iX, int iZ) Compute the point of intersection between a line (iX,0,iZ)+t(0,1,0) and the triangle defined by the three input points. All calculations are in voxel coordinates and the y-value of the intersection point is truncated to an integer.- Parameters:
kV0- a 3D vertex of the trianglekV1- a 3D vertex of the trianglekV2- a 3D vertex of the triangleiX- the x-value of the origin of the lineiZ- the z-value of the origin of the line- Returns:
- the y-value of the intersection
-
getIntersectZ
protected int getIntersectZ(WildMagic.LibFoundation.Mathematics.Vector3f kV0, WildMagic.LibFoundation.Mathematics.Vector3f kV1, WildMagic.LibFoundation.Mathematics.Vector3f kV2, int iX, int iY) Compute the point of intersection between a line (iX,iY,0)+t(0,0,1) and the triangle defined by the three input points. All calculations are in voxel coordinates and the z-value of the intersection point is truncated to an integer.- Parameters:
kV0- a 3D vertex of the trianglekV1- a 3D vertex of the trianglekV2- a 3D vertex of the triangleiX- the x-value of the origin of the lineiY- the y-value of the origin of the line- Returns:
- the z-value of the intersection
-
saveMesh
Internal support to write vertices, normals, and connectivity indices to the file.- Parameters:
flip- if the y axis should be flipped - true for extract, false for from another surface- Throws:
IOException- if there is an error writing to the file
-
update2
protected float update2(int i) Compute the coefficient of the surface normal for the update of the mesh vertex V[i] in the SNormal[i] direction. See BrainExtraction.pdf for a description of the update.- Parameters:
i- the index of the vertex to update- Returns:
- the coefficient of SNormal[i] for the update
-
update3
protected float update3(int i) Compute the coefficient of the vertex normal for the update of the mesh vertex V[i] in the VNormal[i] direction. See BrainExtraction.pdf for a description of the update.- Parameters:
i- the index of the vertex to update- Returns:
- the coefficient of VNormal[i] for the update
-
updateCenter
protected boolean updateCenter(WildMagic.LibFoundation.Mathematics.Vector3f Center)
-