Class CAAMUtil
java.lang.Object
gov.nih.mipav.view.renderer.WildMagic.AAM.CAAMObject
gov.nih.mipav.view.renderer.WildMagic.AAM.CAAMUtil
This is the Java modified version of C++ active appearance model API (AAM_API). It is modified with a subset of
required functions for automatic MRI prostate segmentation.
AAM-API LICENSE - file: license.txt
This software is freely available for non-commercial use such as research and education. Please see the full
disclaimer below.
All publications describing work using this software should cite the reference given below.
Copyright (c) 2000-2003 Mikkel B. Stegmann, mbs@imm.dtu.dk
IMM, Informatics invalid input: '&' Mathematical Modelling DTU, Technical University of Denmark Richard Petersens Plads, Building 321
DK-2800 Lyngby, Denmark
http://www.imm.dtu.dk/~aam/
REFERENCES
Please use the reference below, when writing articles, reports etc. where the AAM-API has been used. A draft version
the article is available from the homepage.
I will be happy to receive pre- or reprints of such articles.
/Mikkel
------------- M. B. Stegmann, B. K. Ersboll, R. Larsen, "FAME -- A Flexible Appearance Modelling Environment", IEEE
Transactions on Medical Imaging, IEEE, 2003 (to appear) -------------
3RD PART SOFTWARE
The software is partly based on the following libraries:
- The Microsoft(tm) Vision Software Developers Kit, VisSDK - LAPACK
DISCLAIMER
This software is provided 'as-is', without any express or implied warranty. In no event will the author be held
liable for any damages arising from the use of this software.
Permission is granted to anyone to use this software for any non-commercial purpose, and to alter it, subject to the
following restrictions:
1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software.
2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original
software.
3. This notice may not be removed or altered from any source distribution.
--
No guarantees of performance accompany this software, nor is any responsibility assumed on the part of the author or
IMM.
This software is provided by Mikkel B. Stegmann and IMM ``as is'' and any express or implied warranties, including,
but not limited to, the implied warranties of merchantability and fitness for a particular purpose are disclaimed. In
no event shall IMM or Mikkel B. Stegmann be liable for any direct, indirect, incidental, special, exemplary, or
consequential damages (including, but not limited to, procurement of substitute goods or services; loss of use, data,
or profits; or business interruption) however caused and on any theory of liability, whether in contract, strict
liability, or tort (including negligence or otherwise) arising in any way out of the use of this software, even if
advised of the possibility of such damage.
$Revision: 1.4 $ $Date: 2003/04/23 14:49:15 $
Utility methods for the AAM project. This class consists of methods that are self-containing and could not logically
fit into any other AAM class.
Thus all methods are static, so remember that there is never need for an instantiation of this class.
- Author:
- Ruida Cheng
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringAddBackSlash(String path) Ensures that a string is terminated with a backslash.static voidConverts AAM-API shape files (.asf) to the ISBE .pts format.static voidCalcShapeDistances(CAAMShape optimized, CAAMShape groundTruth, double[] ptpt, double[] ptcrv, CDVector pvDists) Calculates optimization results.static booleanContainsPoint(int x, int y, ModelSimpleImage image) Check the point is inside the image or notstatic booleanCreateTest(String file) Tests if a file can be created for writing.static doubleDeg2Rad(double deg) Converts from degrees to radians.static doubleDistEuclidianAssBorder(CAAMShape s1, CAAMShape s2) Wrapper to calculate the point to curve error.static doubleDistEuclidianAssBorder(CAAMShape s1, CAAMShape s2, CDVector pvDist) Calculates the point to curve error between two shapes.static doubleCalculates the point to curve error between two shapes.static doubleDistEuclidianPoints(CAAMShape s1, CAAMShape s2) Calculates the point to point error between two shapes.static doubleDistEuclidianPoints(CDVector vX1, CDVector vY1, CDVector vX2, CDVector vY2) Calculates the point to point error between two shapes.static voidDrawLine(int[] x1, int[] y1, int[] x2, int[] y2, double[] tVal, boolean fInsideCheck, ModelSimpleImage image) Draw linesstatic voidExpands an image to have dyadic size.static booleanFileExists(String filename) Tests if a file exists.static StringFindVacantFilename(String filename_suggestion) Finds a file name that is not 'occupied'.static StringForces an extension onto a file name.static StringReturns the extension of a file name.static StringGetFilename(String filename) Returns the file name of a path+file name string.static StringReturns the path of a filename.static voidMirrorEdge(ModelSimpleImage img, ModelSimpleImage mask, int edgeWidth) Mirrors the edge of an arbitrary shape.static voidMirrorEdge(CDMatrix m, ModelSimpleImage mask, int edgeWidth) Mirrors the edge of an arbitrary shape.static voidPlotMeshIntoImage(ModelSimpleImage image, CAAMMesh mesh, double[] point_color, double[] line_color) Plots a mesh into an image.static voidPlotShapeIntoImage(ModelSimpleImage image, CAAMShape shape, double[] point_color, double[] line_color, boolean drawNormals, boolean drawArea, boolean drawPoints) Wrapper to draw shape onto imagestatic voidPlotShapeIntoImage(ModelSimpleImage image, CAAMShape shape, double[] point_color, double[] line_color, boolean drawNormals, boolean drawArea, boolean drawPoints, boolean drawLines) Draws the shape into an image with a given color.static voidPointOnAssBorder(CDVector vX1, CDVector vY1, CDVector vX2, CDVector vY2, CDVector vXBorder, CDVector vYBorder, CDVector vDist) Calculates the point to curve error between two shapes.private static voidprocessDir(String pathBS, String ext) Process directory.static doubleProjPointOnLine(double dXL1, double dYL1, double dXL2, double dYL2, double dXP, double dYP, double[] dXProj, double[] dYProj) Find the projection dProj of the point dP on the line through dL1 and dL2.static doubleRad2Deg(double rad) Convert from radians to degrees.static ModelSimpleImageReadExample(ModelImage targetImageSlice, ModelSimpleImage img, CAAMShape shape, int rfactor) Read example from target image, scale down if necessary.static ModelSimpleImageReadExample(String filename, ModelSimpleImage img, CAAMShape shape) Wrapper to read image and VOIsstatic ModelSimpleImageReadExample(String filename, ModelSimpleImage img, CAAMShape shape, int rfactor) static ModelSimpleImageReadExample_init(ModelImage targetImageSlice, ModelSimpleImage img, CAAMShape shape, int rfactor) Read example from target image, scale down if necessary.Reads a file into an array of lines.static voidRegistrationMovie(String filename, String asfPath, boolean useConvexHull, boolean writeRefShape) Writes a movie file containing all shapes from a directory warped to their mean shape.static voidRegistrationMovie(String filename, Vector<CDVector> vTexture, CAAMReferenceFrame rf) Writes a movie file containing a set of textures warped to their mean shape.static StringRemoves the extension of a file name.static voidSampleTextures(CAAMShapeCollection unalignedShapes, Vector<CDVector> vTextures, CAAMReferenceFrame outputRF, int imageReduction, boolean removeMean, boolean useTSP, boolean useConvexHull) Samples a set of texture vectors given a set of shape in absolute (i.e. image) coordinates.ScanSortDir(String path, String extension) Scans and sorts a directory for files with a specific extension.static StringSecs2Mins(double secs) Converts seconds to a MM:SS string.static booleanTests if a shape is fully inside an image.static doubleShapeOverlap(CAAMShape model, CAAMShape gt) Calculates the overlap between two shapes as specified in "Active Shape Model Segmentation With Optimal Features" Bram van Ginneken et al., IEEE TMI 21(8) Aug. 2002.static voidSwap(int[] a, int[] b) Swap valuesstatic doubleSymmetricPtCrv(CAAMShape s1, CAAMShape s2) A symmetric poin- to-curve measure, i.e.static voidConcatenates three vectors.Methods inherited from class gov.nih.mipav.view.renderer.WildMagic.AAM.CAAMObject
FromFile, ToFile
-
Field Details
-
vFilenames
File name vector
-
-
Constructor Details
-
CAAMUtil
public CAAMUtil()
-
-
Method Details
-
PlotMeshIntoImage
public static void PlotMeshIntoImage(ModelSimpleImage image, CAAMMesh mesh, double[] point_color, double[] line_color) Plots a mesh into an image.- Parameters:
image- The image in which the shape should be plotted.point_color- The point color of the mesh.line_color- The line color of the mesh.shape- The shape to be plotted.
-
PlotShapeIntoImage
public static void PlotShapeIntoImage(ModelSimpleImage image, CAAMShape shape, double[] point_color, double[] line_color, boolean drawNormals, boolean drawArea, boolean drawPoints) Wrapper to draw shape onto image- Parameters:
image- The image in which the shape should be plotted.shape- The shape to be plotted.point_color- The point color of the shape.line_color- The line color of the shape.drawNormals- If true the point normals are drawn.drawArea- If true the inside area of the shape is drawn.drawPoints- If true the points of the shape is drawn.
-
PlotShapeIntoImage
public static void PlotShapeIntoImage(ModelSimpleImage image, CAAMShape shape, double[] point_color, double[] line_color, boolean drawNormals, boolean drawArea, boolean drawPoints, boolean drawLines) Draws the shape into an image with a given color.- Parameters:
image- The image in which the shape should be plotted.shape- The shape to be plotted.point_color- The point color of the shape.line_color- The line color of the shape.drawNormals- If true the point normals are drawn.drawArea- If true the inside area of the shape is drawn.drawPoints- If true the points of the shape is drawn.drawLines- If true the lines of the shape is drawn.
-
ContainsPoint
Check the point is inside the image or not- Parameters:
x- point x coordinatey- point y coordinateimage- model image reference.- Returns:
- true inside, false outside.
-
Swap
public static void Swap(int[] a, int[] b) Swap values- Parameters:
a-b-
-
DrawLine
public static void DrawLine(int[] x1, int[] y1, int[] x2, int[] y2, double[] tVal, boolean fInsideCheck, ModelSimpleImage image) Draw lines- Parameters:
x1-y1-x2-y2-tVal-fInsideCheck-image-
-
VecCat3
Concatenates three vectors.- Parameters:
dest- Output vector.v1- First input vector.v2- Second input vector.v3- Third input vector.
-
ScanSortDir
Scans and sorts a directory for files with a specific extension.- Parameters:
path- Path to read from.extension- The file extension to search for. ex. "hips".- Returns:
- The filenames found without any path.
-
processDir
Process directory.- Parameters:
pathBS- file pathext- file extension
-
ReadExample
Wrapper to read image and VOIs- Parameters:
filename- file nameimg- imageshape- voi- Returns:
-
ReadExample
public static ModelSimpleImage ReadExample(String filename, ModelSimpleImage img, CAAMShape shape, int rfactor) - Parameters:
filename- The filename of an annotation. Ex. "horse.asf".img- Output image.shape- Output shape.rfactor- The reduction factor. Performs a scaling of the input of 1/rfactor.- Returns:
- img image
-
ReadExample
public static ModelSimpleImage ReadExample(ModelImage targetImageSlice, ModelSimpleImage img, CAAMShape shape, int rfactor) Read example from target image, scale down if necessary.- Parameters:
targetImageSlice- target image sliceimg- sample imageshape- voirfactor- subsample factor- Returns:
- image
-
ReadExample_init
public static ModelSimpleImage ReadExample_init(ModelImage targetImageSlice, ModelSimpleImage img, CAAMShape shape, int rfactor) Read example from target image, scale down if necessary.- Parameters:
targetImageSlice- target image sliceimg- sample imageshape- voirfactor- subsample factor- Returns:
- image
-
DistEuclidianPoints
Calculates the point to point error between two shapes.- Parameters:
s1- Shape 1.s2- Shape 2.- Returns:
- The average point to point error.
-
DistEuclidianAssBorder
Wrapper to calculate the point to curve error.- Parameters:
s1- shape 1s2- shape 2- Returns:
- the average point to curve error.
-
DistEuclidianAssBorder
Calculates the point to curve error between two shapes.- Parameters:
s1- Shape 1.s2- Shape 2.pvDist- Optional pointer to an output vector containing all point to curve distances (one for each landmark).- Returns:
- The average point to curve error.
-
DistEuclidianPoints
Calculates the point to point error between two shapes.- Parameters:
vX1- X-positions of shape 1.vY1- Y-positions of shape 1.vX2- X-positions of shape 2.vY2- Y-positions of shape 2.- Returns:
- The average point to point error.
-
DistEuclidianAssBorder
public static double DistEuclidianAssBorder(CDVector vX1, CDVector vY1, CDVector vX2, CDVector vY2, CDVector pvDist) Calculates the point to curve error between two shapes.- Parameters:
vX1- X-positions of shape 1.vY1- Y-positions of shape 1.vX2- X-positions of shape 2.vY2- Y-positions of shape 2.pvDist- Optional pointer to an output vector containing all point to curve distances (one for each landmark).- Returns:
- The average point to curve error.
-
PointOnAssBorder
public static void PointOnAssBorder(CDVector vX1, CDVector vY1, CDVector vX2, CDVector vY2, CDVector vXBorder, CDVector vYBorder, CDVector vDist) Calculates the point to curve error between two shapes.- Parameters:
vX1- X-positions of shape 1.vY1- Y-positions of shape 1.vX2- X-positions of shape 2.vY2- Y-positions of shape 2.vXBorder- Output x border.vYBorder- Output y border.vDist- Point to curve distance for each landmark.
-
ProjPointOnLine
public static double ProjPointOnLine(double dXL1, double dYL1, double dXL2, double dYL2, double dXP, double dYP, double[] dXProj, double[] dYProj) Find the projection dProj of the point dP on the line through dL1 and dL2. Returns the distance between dProj and dP, if the dProj lays between dL1 and dL2 otherwise DBL_MAX. dXL1,dYL1,dXL2,dYL2: points on line dXP,dYP: points to project dXProj,dYProj: projected point on the line- Returns:
- The distance.
-
RemoveExt
Removes the extension of a file name.- Parameters:
s- Input file name.- Returns:
- File name without extension.
-
GetExt
Returns the extension of a file name.- Parameters:
s- Input filename- Returns:
- The extension.
-
CreateTest
Tests if a file can be created for writing.- Parameters:
file- Input file name.- Returns:
- True, if the file could be created (and deleted again).
-
AddBackSlash
Ensures that a string is terminated with a backslash. If the already has a terminating backslash, nothing is done.- Parameters:
path- Input string.- Returns:
- Backslash-terminated output string.
-
GetPath
Returns the path of a filename.- Parameters:
fullfilename- Filename including any path.- Returns:
- The path to the filename.
-
GetFilename
Returns the file name of a path+file name string.- Parameters:
filename- Full qualified filename including path.- Returns:
- The file name including any extension, but without any path.
-
ForceExt
Forces an extension onto a file name. The method tests the extension of a filename. If the wanted extension is presented nothing is done. If not, the extension is appended.- Parameters:
filename- Input file name.ext- Wanted extension.- Returns:
- The file name including the wanted extension.
-
FileExists
Tests if a file exists.- Parameters:
filename- File name to test.- Returns:
- True if the file exists.
-
ExpandImg2DyadicSize
Expands an image to have dyadic size. The method expands an image by using zero-padding so that the resulting image has width and height that are powers of two.- Parameters:
img- Input image.out- Output dyadic image.
-
MirrorEdge
Mirrors the edge of an arbitrary shape. Mirrors the edge of an arbitrary shape mask in a matrix using poor-mans mirroring.- Parameters:
mask- Image mask defining the shape.edgeWidth- The width of the edge.img- Input matrix. Overwritten by mirrored version.
-
MirrorEdge
Mirrors the edge of an arbitrary shape. Mirrors the edge of an arbitrary shape mask in an image using poor-mans mirroring.- Parameters:
img- Input image. Overwritten by mirrored version.mask- Image mask defining the shape.edgeWidth- The width of the edge.
-
ShapeInsideImage
Tests if a shape is fully inside an image.- Parameters:
s- Input shape.img- Input image.- Returns:
- True if the shape is fully inside the image.
-
Deg2Rad
public static double Deg2Rad(double deg) Converts from degrees to radians.- Parameters:
deg- degree- Returns:
- radian
-
Rad2Deg
public static double Rad2Deg(double rad) Convert from radians to degrees.- Parameters:
rad- radian- Returns:
- degree
-
CalcShapeDistances
public static void CalcShapeDistances(CAAMShape optimized, CAAMShape groundTruth, double[] ptpt, double[] ptcrv, CDVector pvDists) Calculates optimization results.- Parameters:
optimized- Model shape.groundTruth- Ground truth shape.ptpt- Average point to point landmark error.ptcrv- Average point to curve landmark error. NOTICE: This is not a symmetric measure!
-
Secs2Mins
Converts seconds to a MM:SS string.- Parameters:
secs- Time in seconds.- Returns:
- The time in MM:SS.
-
FindVacantFilename
Finds a file name that is not 'occupied'.- Parameters:
filename_suggestion- Suggestion including extension.- Returns:
- An unused filename resembling the suggestion.
-
SampleTextures
public static void SampleTextures(CAAMShapeCollection unalignedShapes, Vector<CDVector> vTextures, CAAMReferenceFrame outputRF, int imageReduction, boolean removeMean, boolean useTSP, boolean useConvexHull) Samples a set of texture vectors given a set of shape in absolute (i.e. image) coordinates.- Parameters:
unalignedShapes- Shapes in absolute coordinates.vTextures- The set of textures.outputRF- The output reference frame generated for sampling the textures.removeMean- If true the mean from each texture vector (i.e. the DC) is removed.useTSP- Use tangent space projection to align the shapes.useConvexHull- If true the convex hull is used to determine the extent of a shape.
-
RegistrationMovie
public static void RegistrationMovie(String filename, Vector<CDVector> vTexture, CAAMReferenceFrame rf) Writes a movie file containing a set of textures warped to their mean shape. Curently diabled.- Parameters:
filename- Output movie filename.vTexture- The set of textures.rf- The reference frame used for sampling the textures.
-
RegistrationMovie
public static void RegistrationMovie(String filename, String asfPath, boolean useConvexHull, boolean writeRefShape) Writes a movie file containing all shapes from a directory warped to their mean shape.- Parameters:
filename- Output movie filename.asfPath- Path to annotation files.useConvexHull- If true the convex hull is used to determine the extent of a shape.writeRefShape- If true the reference shape corresponding to the movie file is written as "regshape.asf".
-
ASF2PTS
Converts AAM-API shape files (.asf) to the ISBE .pts format. Output is written in the directory 'pts'.- Parameters:
path- Path to .asf files.
-
SymmetricPtCrv
A symmetric poin- to-curve measure, i.e. SymmetricPtCrv(a,b) == SymmetricPtCrv( b,a );- Parameters:
s1- First shapes2- Second shape- Returns:
- The average symmetric point-to-curve error over all landmarks.
-
ShapeOverlap
Calculates the overlap between two shapes as specified in "Active Shape Model Segmentation With Optimal Features" Bram van Ginneken et al., IEEE TMI 21(8) Aug. 2002. Notice that this only makes sense for one-path closed shapes.- Parameters:
model- Model shapegt- Ground truth shape- Returns:
- The shape overlap (1 = perfect match, 0 = no overlap).
-
ReadLines
Reads a file into an array of lines.- Parameters:
filename- Name of input file.- Returns:
- A vector of text lines.
-