Class CDMatrix
- java.lang.Object
-
- gov.nih.mipav.view.renderer.WildMagic.AAM.CVisDMatrix
-
- gov.nih.mipav.view.renderer.WildMagic.AAM.CDMatrix
-
public class CDMatrix extends CVisDMatrix
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 & 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 $ Base matrix operations within AAM model.- Author:
- Ruida Cheng
-
-
Field Summary
Fields Modifier and Type Field Description static int
RAND_MAX
-
Fields inherited from class gov.nih.mipav.view.renderer.WildMagic.AAM.CVisDMatrix
eftData, eftDims, eftEnd, eftName, FieldType, m_data, m_fExternalStorage, m_nCols, m_nRows, s_fVerboseOutput
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CDMatrix
assign(double value)
Assignment operator (double).CDMatrix
assign(double[][] value)
Assignment operatorCDMatrix
assign(CDMatrix mat)
Assignment operator (CDMatrix).CDMatrix
assign(CVisDMatrix mat)
Assignment operator (CVisDMatrix).void
Col(int i, CDVector vCol)
Return the i-th column of the matrix.void
CombVert(CVisDMatrix Top, CVisDMatrix Bottom)
Composes the matrix of Top and Bottom (on top of each other).double
Det()
Calculates the determinant of a square matrix up to the 3rd order.void
Diag(CDVector vec)
Make the matrix a diagonal matrix containing 'vec'.void
ElementDivide(CDMatrix matrix)
Element-wise matrix division.void
ElementMultiply(CDMatrix matrix)
Element-wise matrix multiply.void
Eq(double B, CDMatrix C)
Element wise equal to.void
Eq(CDMatrix B, CDMatrix C)
Element wise equal to.void
Eye()
Converts the matrix in the identity matrix - i.e. zeros all-over except the ones in the diagonal.void
FlipLR()
FlipLR modifies the matrix with row preserved and columns flipped in the left/right direction.void
FlipUD()
Flip matrix in up/down direction.void
FromFile(java.io.DataInputStream fh)
Reads a matrix from disk in binary format (from the current position of the file pointer), as written from ToFile().void
FromFile(java.lang.String sFilename)
Reads a matrix from disk in binary format, as written from ToFile().void
Ge(double B, CDMatrix C)
Element wise greater than or equal.void
Ge(CDMatrix B, CDMatrix C)
Element wise greater than or equal.void
Gt(double B, CDMatrix C)
Element wise greater than.void
Gt(CDMatrix B, CDMatrix C)
Element wise greater than.void
Kron(CDMatrix mX, CDMatrix mY)
Forms the Kronecker tensor product of two matrices.void
Le(double B, CDMatrix C)
Element wise less than or equal.void
Le(CDMatrix B, CDMatrix C)
Element wise less than or equal.void
Log()
Takes the natural logarithm (base e=2.71..) of each matrix element.void
Lt(double B, CDMatrix C)
Element wise less than.void
Lt(CDMatrix B, CDMatrix C)
Element wise less than.double
Mean()
Calcs the mean value of the matrix.void
MeanCol(CDVector vMean)
Calc the mean of each column into a vector.void
Ne(double B, CDMatrix C)
Element wise not equal to.void
Ne(CDMatrix B, CDMatrix C)
Element wise not equal to.void
OneWayANOVA(double[] dZ, int[] nDFModel, int[] nDFError)
One-way analysis of variance (ANOVA).void
OuterProduct(CDVector v1, CDVector v2)
Forms the outer product of two vectors and store the result in this.void
Rand()
Uniformly distributed random numbers.void
Row(int i, CDVector vRow)
Return the i-th row of the matrix.void
Sqr()
Takes the power of two of each element.void
Sqrt()
Takes the square root of each element.double
Std()
Calc the standard diviation of the matrix.void
StdCol(CDVector vStd)
Calc the standard deviation of each column into a vector.double
Sum()
Calc the total sum of the matrix.void
SumCol(CDVector vSum)
Calc the sum of each column into a vector.void
ToFile(java.io.DataOutputStream fh)
Writes the matrix to disk in binary format.void
ToFile(java.lang.String sFilename)
Writes the matrix to disk in binary format.void
ToMatlab(java.lang.String sFilename, java.lang.String sName, java.lang.String sComment, boolean fAppend)
Writes the matrix to disk in MatLab (.m) format.java.lang.String
ToString()
Returns a string representing the matrix.void
ToVector(CDVector v, boolean rowWise)
Converts this matrix to a vector, either by row (default) or column.double
Trace()
Calculates the trace - i.e. the sum of diagonal elements.void
TriL(CDMatrix matrix, int K)
Extract lower triangular part of matrix.void
TriU(CDMatrix matrix, int K)
Extract upper triangular part of matrix.void
TTest(int iCol1, int iCol2, double[] dZ, int[] nDF)
Student's T-test.double
Var()
Calc the variance of the matrix.void
VarCol(CDVector vVar)
Calc the variance of each column into a vector.-
Methods inherited from class gov.nih.mipav.view.renderer.WildMagic.AAM.CVisDMatrix
add, add_into, Column, Determinant, Determinant, Dgelss, Dgesv, Dgesvd, Dgetrf, dispose, div, div_into, Dposv, Dsyev, EqDiff, EqProd, EqSum, equals, FreeBuffer, Invert, Inverted, IsSymmetric, lessThan, mult, mult, mult, mult_into, mult_into, NCols, neg, not_equals, NRows, Resize, Resize, Row, SetColumn, SetRow, SetSize, SetSize, sub, sub_into, Submatrix, Submatrix, Submatrix, Transpose, Transposed, VisCrossProduct, VisCrossProduct, VisDMatrixLeastSquares, VisDMatrixLeastSquares, VisDMatrixLeastSquares, VisDMatrixLeastSquares, VisDMatrixLLS, VisDMatrixSolve, VisDMatrixSolve, VisDMatrixSolveSPD, VisDMatrixSolveSPD, VisDMatrixSqrtInverse, VisDMatrixSqrtInverse, VisDMatrixSVD, VisDMatrixSVD, VisDMatrixSymmetricEigen, VisGaussJordanSolveDMatrix, VisOuterProduct
-
-
-
-
Constructor Detail
-
CDMatrix
public CDMatrix()
Constructors
-
CDMatrix
public CDMatrix(int rows, int cols)
-
CDMatrix
public CDMatrix(int rows, int cols, double[][] storage)
-
CDMatrix
public CDMatrix(CDMatrix mat)
-
CDMatrix
public CDMatrix(CVisDMatrix mat)
-
-
Method Detail
-
assign
public CDMatrix assign(CVisDMatrix mat)
Assignment operator (CVisDMatrix).- Overrides:
assign
in classCVisDMatrix
- Parameters:
mat
- Input matrix.- Returns:
- This.
-
assign
public CDMatrix assign(CDMatrix mat)
Assignment operator (CDMatrix).- Parameters:
mat
- Input matrix.- Returns:
- This.
-
assign
public CDMatrix assign(double value)
Assignment operator (double). Set all values equal to 'value'.- Overrides:
assign
in classCVisDMatrix
- Parameters:
value
- Input double.- Returns:
- This.
-
assign
public CDMatrix assign(double[][] value)
Assignment operator- Parameters:
value
- double matrix- Returns:
- this.
-
SumCol
public void SumCol(CDVector vSum)
Calc the sum of each column into a vector. The vector will be resized if it doesn't have the right length.- Parameters:
vSum
- Output vector.
-
MeanCol
public void MeanCol(CDVector vMean)
Calc the mean of each column into a vector. The vector will be resized if it doesn't have the right length.- Parameters:
vMean
- Output vector.
-
VarCol
public void VarCol(CDVector vVar)
Calc the variance of each column into a vector. The vector will be resized if it doesn't have the right length.- Parameters:
vVar
- Output vector.
-
StdCol
public void StdCol(CDVector vStd)
Calc the standard deviation of each column into a vector. The vector will be resized if it doesn't have the right length.- Parameters:
vStd
- Output vector.
-
Sum
public double Sum()
Calc the total sum of the matrix.- Returns:
- The sum.
-
Mean
public double Mean()
Calcs the mean value of the matrix.- Returns:
- The mean value.
-
Var
public double Var()
Calc the variance of the matrix.- Returns:
- The variance value.
-
Std
public double Std()
Calc the standard diviation of the matrix.- Returns:
- The standard diviation value.
-
OneWayANOVA
public void OneWayANOVA(double[] dZ, int[] nDFModel, int[] nDFError)
One-way analysis of variance (ANOVA). Determination of the fluctuations observed in a sample, and their dependencies in the form of a one-way analysis of variance (ANOVA).- Parameters:
dZ
-nDFModel
-nDFError
-
-
TTest
public void TTest(int iCol1, int iCol2, double[] dZ, int[] nDF)
Student's T-test.- Parameters:
iCol1
-iCol2
-dZ
-nDF
-
-
Row
public void Row(int i, CDVector vRow)
Return the i-th row of the matrix. The vector will be resized if it doesn't have the right length. Notice that due to the row major nature of matrices, row read/writes are *much* faster than col read/writes. Alternatively, one could use the more costly CVisDVector CVisDMatrix::Row(int r) method. To set the i-th row use: void CVisDMatrix::SetRow(int r, const CVisDVector &v)- Parameters:
i
- The row number.vRow
- Output vector;
-
Col
public void Col(int i, CDVector vCol)
Return the i-th column of the matrix. The vector will be resized if it doesn't have the right length.- Parameters:
i
- The column number.vCol
- Output vector;
-
Diag
public void Diag(CDVector vec)
Make the matrix a diagonal matrix containing 'vec'. This function transforms the matrix into a diagonal matrix, with the values of 'vec' in the diagonal.- Parameters:
vec
- Vector to place in the diagonal.
-
ToString
public java.lang.String ToString()
Returns a string representing the matrix.- Returns:
- A string.
-
CombVert
public void CombVert(CVisDMatrix Top, CVisDMatrix Bottom)
Composes the matrix of Top and Bottom (on top of each other).- Parameters:
Top
- Matrix to be placed in the top of this matrix.Bottom
- Matrix to be placed in the bottom of this matrix.
-
ToMatlab
public void ToMatlab(java.lang.String sFilename, java.lang.String sName, java.lang.String sComment, boolean fAppend)
Writes the matrix to disk in MatLab (.m) format. To read the matrix into MatLab write e.g. 'my_matrix.m' at the MatLab prompt. Notice that this should be used for storage a (really) large matrices, due to the computational and i/o overhead induced by the simple MatLab text format. Also, remember that MatLab can't read (.m) files with lines longer than 4096 bytes. If no communication with MatLab is needed, but merely to/from disk functionality within a DIVA program, it is suggested to use the fast binary i/o methods ToFile() and FromFile().- Parameters:
sFilename
- Output file name. Should have the extension '.m'.sName
- Name of destination matlab variable.sComment
- Optional comment inside the file.fAppend
- If true, the vector is appended to the file 'sFilename'.
-
Sqrt
public void Sqrt()
Takes the square root of each element.
-
Sqr
public void Sqr()
Takes the power of two of each element.
-
ElementMultiply
public void ElementMultiply(CDMatrix matrix)
Element-wise matrix multiply. Multiply each element in the matrix with the corresponding element of the input matrix.
-
ElementDivide
public void ElementDivide(CDMatrix matrix)
Element-wise matrix division. Divide each element in the matrix with the corresponding element of the input matrix.
-
ToFile
public void ToFile(java.lang.String sFilename)
Writes the matrix to disk in binary format. The dimensions are saved as two doubles (!!?) (rows,cols) in the start.- Parameters:
sFilename
- Input file name.
-
ToFile
public void ToFile(java.io.DataOutputStream fh)
Writes the matrix to disk in binary format. The dimensions are saved as two doubles (!!?) (rows,cols) in the start. The matrix is written to the binary file 'fh' at the current position of the file pointer.- Parameters:
fh
- Open file handle.
-
FromFile
public void FromFile(java.lang.String sFilename)
Reads a matrix from disk in binary format, as written from ToFile(). The matrix is resizew if it doesn't fit the disk matrix.- Parameters:
sFilename
- Input file name.
-
FromFile
public void FromFile(java.io.DataInputStream fh)
Reads a matrix from disk in binary format (from the current position of the file pointer), as written from ToFile(). The matrix is resized if it doesn't fit the disk matrix.- Parameters:
fh
- Open file handle.
-
Kron
public void Kron(CDMatrix mX, CDMatrix mY)
Forms the Kronecker tensor product of two matrices. The result is placed in this.
-
Eye
public void Eye()
Converts the matrix in the identity matrix - i.e. zeros all-over except the ones in the diagonal.
-
TriU
public void TriU(CDMatrix matrix, int K)
Extract upper triangular part of matrix. Extracts the elements on and above the K-th diagonal. K = 0 is the main diagonal, K > 0 is above the main diagonal and K < 0 is below the main diagonal.
-
TriL
public void TriL(CDMatrix matrix, int K)
Extract lower triangular part of matrix. Extracts the elements on and below the K-th diagonal. K = 0 is the main diagonal, K > 0 is above the main diagonal and K < 0 is below the main diagonal.
-
Eq
public void Eq(double B, CDMatrix C)
Element wise equal to. Comparison of a matrix and a double. Compares each element in this matrix (A) with double B. Result matrix C has elements with values 1 or 0. C(i,j) = 1 if A(i,j) == B C(i,j) = 0 else
-
Eq
public void Eq(CDMatrix B, CDMatrix C)
Element wise equal to. Comparison of two matrices. Compares each element in this matrix (A) with corresponding element in B. Result matrix C has elements with values 1 or 0. C(i,j) = 1 if A(i,j) == B(i,j) C(i,j) = 0 else
-
Ne
public void Ne(double B, CDMatrix C)
Element wise not equal to. Comparison of a matrix and a double. Compares each element in this matrix (A) with double B. Result matrix C has elements with values 1 or 0. C(i,j) = 1 if A(i,j) != B C(i,j) = 0 else
-
Ne
public void Ne(CDMatrix B, CDMatrix C)
Element wise not equal to. Comparison of two matrices. Compares each element in this matrix (A) with corresponding element in B. Result matrix C has elements with values 1 or 0. C(i,j) = 1 if A(i,j) != B(i,j) C(i,j) = 0 else
-
Lt
public void Lt(double B, CDMatrix C)
Element wise less than. Comparison of a matrix and a double. Compares each element in this matrix (A) with double B. Result matrix C has elements with values 1 or 0. C(i,j) = 1 if A(i,j) < B C(i,j) = 0 else
-
Lt
public void Lt(CDMatrix B, CDMatrix C)
Element wise less than. Comparison of two matrices. Compares each element in this matrix (A) with corresponding element in B. Result matrix C has elements with values 1 or 0. C(i,j) = 1 if A(i,j) < B(i,j) C(i,j) = 0 else
-
Le
public void Le(double B, CDMatrix C)
Element wise less than or equal. Comparison of a matrix and a double. Compares each element in this matrix (A) with double B. Result matrix C has elements with values 1 or 0. C(i,j) = 1 if A(i,j) <= B C(i,j) = 0 else
-
Le
public void Le(CDMatrix B, CDMatrix C)
Element wise less than or equal. Comparison of two matrices. Compares each element in this matrix (A) with corresponding element in B. Result matrix C has elements with values 1 or 0. C(i,j) = 1 if A(i,j) <= B(i,j) C(i,j) = 0 else
-
Gt
public void Gt(double B, CDMatrix C)
Element wise greater than. Comparison of a matrix and a double. Compares each element in this matrix (A) with double B. Result matrix C has elements with values 1 or 0. C(i,j) = 1 if A(i,j) > B C(i,j) = 0 else
-
Gt
public void Gt(CDMatrix B, CDMatrix C)
Element wise greater than. Comparison of two matrices. Compares each element in this matrix (A) with corresponding element in B. Result matrix C has elements with values 1 or 0. C(i,j) = 1 if A(i,j) > B(i,j) C(i,j) = 0 else
-
Ge
public void Ge(double B, CDMatrix C)
Element wise greater than or equal. Comparison of a matrix and a double. Compares each element in this matrix (A) with double B. Result matrix C has elements with values 1 or 0. C(i,j) = 1 if A(i,j) >= B C(i,j) = 0 else
-
Ge
public void Ge(CDMatrix B, CDMatrix C)
Element wise greater than or equal. Comparison of two matrices. Compares each element in this matrix (A) with corresponding element in B. Result matrix C has elements with values 1 or 0. C(i,j) = 1 if A(i,j) <= B(i,j) C(i,j) = 0 else
-
Log
public void Log()
Takes the natural logarithm (base e=2.71..) of each matrix element.
-
FlipLR
public void FlipLR()
FlipLR modifies the matrix with row preserved and columns flipped in the left/right direction.
-
FlipUD
public void FlipUD()
Flip matrix in up/down direction. FlipUD(X) modifies the matrix with columns preserved and rows flipped in the up/down direction.
-
Rand
public void Rand()
Uniformly distributed random numbers. Inserts uniformly distributed random numbers in the range [0;1].
-
OuterProduct
public void OuterProduct(CDVector v1, CDVector v2)
Forms the outer product of two vectors and store the result in this. If the matrix does have the correct size, it will be resized.- Parameters:
v1
- Input vector.v2
- Input vector.
-
Det
public double Det()
Calculates the determinant of a square matrix up to the 3rd order.- Returns:
- The determinant.
-
Trace
public double Trace()
Calculates the trace - i.e. the sum of diagonal elements.- Returns:
- The trace.
-
ToVector
public void ToVector(CDVector v, boolean rowWise)
Converts this matrix to a vector, either by row (default) or column.- Parameters:
v
- Output vectorrowWise
- If true (default) matrix data is extracted row-wise. If false matrix data is extracted column-wise.
-
-