Class CDVector
- java.lang.Object
-
- gov.nih.mipav.view.renderer.WildMagic.AAM.CVisDVector
-
- gov.nih.mipav.view.renderer.WildMagic.AAM.CDVector
-
- Direct Known Subclasses:
CAAMShape
public class CDVector extends CVisDVector
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 $ Copyright (c) 1999-2001 by Informatics & Mathmatical Modelling, Section for Image Analysis IMM, Informatics & Mathmatical Modelling Technical University of Denmark Richard Petersens Plads Building 321 DK-2800 Lyngby, Denmark http://www.imm.dtu.dk/~diva/ Original author: Rune Fisker Current author: Mikkel B. Stegmann - mbs@imm.dtu.dk Contributions: Lars Pedersen - lap@imm.dtu.dk, Henrik Aanaes - haa@imm.dtu.dk, + several other peoples at IMM. Vector operations for AAM model.- Author:
- Ruida Cheng
-
-
Field Summary
Fields Modifier and Type Field Description static intRAND_MAX-
Fields inherited from class gov.nih.mipav.view.renderer.WildMagic.AAM.CVisDVector
m_data, m_fExternalStorage, m_length
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static int__dbl_cmp_asc(double[] arg1, double[] arg2)static compare functions for the Sort() functionstatic int__dbl_cmp_des(double[] arg1, double[] arg2)voidAbs()Takes the absolute valueof each element.voidAlignTo(CDVector v)voidAlignTo(CDVector v, double[] pA, double[] pB)Linear alignment of this vector to another vector using the L2 norm.CDVectorassign(double value)Assignment operator.CDVectorassign(double[] value)Assignment operator.CDVectorassign(CDVector vIn)Assignment operator.CDVectorassign(CVisDVector vIn)Assignment operator.doubleAutoCorrelation(int lag)Calculates the autocorrelation of the vector with a given lag (default lag is 1).voidCeil()Takes ceil() of each element.voidClamp(double min, double max)Clamps the vector to [min,max].voidCrossProduct(CDVector v1, CDVector v2)Forms the cross product of two vectors and store the result in this.voidElementDivide(CDVector vector)Divide two vectors element-wise.voidElementMultiply(CDVector vector)Multiplies two vectors element-wise.voidEq(double B, CDVector C)Equal - compares a vector and a double.voidEq(CDVector B, CDVector C)Equal - compares a vector and a vector.voidFloor()Takes floor() of each element.voidFromFile(java.io.DataInputStream fh)Reads a vector from disk in binary format.voidFromFile(java.lang.String sFilename)Reads a vector from disk in binary format.voidGe(double B, CDVector C)Greater Than or Equal - compares a double and a vector.voidGe(CDVector B, CDVector C)Greater Than or Equal - compares a vector and a vector.voidGt(double B, CDVector C)Greater Than - compares a double and a vector.voidGt(CDVector B, CDVector C)Greater Than - compares a vector and a vector.voidLe(double B, CDVector C)Less Than or Equal - compares a double and a vector.voidLe(CDVector B, CDVector C)Less Than or Equal - compares a vector and a vector.voidLinspace(double x1, double x2, int n)Generates a vector of linearly equally spaced points between x1 and x2 (inclusive).voidLog()Takes the natural logarithm of each element.voidLt(double B, CDVector C)Less Than - compares a double and a vector.voidLt(CDVector B, CDVector C)Less Than - compares a vector and a vector.doubleMax()Finds the maximum element in the vector.doubleMean()Calculates the mean value of the vector.doubleMedian()Calculates the median.doubleMin()Finds the minimum element in the vector.doubleMin(int[] iPos)Finds the minimum element in the vector and its position.voidNe(double B, CDVector C)Not Equal - compares a double and a vector.voidNe(CDVector B, CDVector C)Not Equal - compares a vector and a vector.doubleNorm1()Calculates the one-norm (L1) of the vector.doubleNorm2()Calculates the two-norm (L2) of the vector.voidNormalize2()Normalizes the vector to unit length, using the 2-norm.doubleNormInf()Calculates the infinity-norm (Linf) of the vector.voidPow(double dP)Takes the power 'dP' of each element.(package private) doublequick_select(double[] arr, int n)voidRand()Uniformly distributed random numbers.voidRand(int st, int end)Uniformly distributed integer random numbers.CDVectorRange(int st, int end)Returns a sub range of a vector.voidReverse()Reverses the vector.voidRound()Takes round() of each element.voidShuffle()Shuffles (randomizes) the vector.doubleSkewness()Calculates the skewness the vector.voidSort()voidSort(boolean ascending)Sorts the vector in either ascending (default) or descending order.voidSqr()Squares each element.voidSqrt()Takes the square root of each element.doubleStd()Calculates the standard deviation the vector.doubleSum()Calculates the sum of the vector.voidToFile(java.io.DataOutputStream fh)Writes the vector to disk in binary format.voidToFile(java.lang.String sFilename)Writes the vector to disk in binary format.voidToMatlab(java.lang.String sFilename, java.lang.String sName, java.lang.String sComment, boolean fAppend)Writes the vector to disk in MatLab (.m) format.voidToMatrix(int nRows, int nCols, CDMatrix m, boolean rowWise)Converts this vector to a matrix, either by row (default) or column.java.lang.StringToString(boolean fNewline)Returns a string representing the vector.CDVectorTrim(double percentage)Removes the extreme 'percentage' part of the vector.doubleTrimmedMean(double percentage)Calculates the trimmed mean.doubleTrimmedStd(double percentage)Calculates the trimmed standard deviation.doubleTrimmedVar(double percentage)Calculates the trimmed variance.doubleVar()doubleVar(double[] pMean)Calculates the variance the vector.CDVectorVecCat(CDVector v)Concatenates a vector to the end of this vector.-
Methods inherited from class gov.nih.mipav.view.renderer.WildMagic.AAM.CVisDVector
add, add_into, dispose, div, div_into, EqDiff, EqProd, EqSum, equals, FreeBuffer, get, Length, less_than, mult, mult, mult_into, neg, not_equals, Resize, Resize, Resize, set, SetSize, SetSize, sub, sub_into, VisCrossProduct, VisCrossProduct
-
-
-
-
Constructor Detail
-
CDVector
public CDVector()
constructor
-
CDVector
public CDVector(int length)
-
CDVector
public CDVector(int length, double[] storage)
-
CDVector
public CDVector(CDVector vec)
-
CDVector
public CDVector(CVisDVector vec)
-
-
Method Detail
-
assign
public CDVector assign(CVisDVector vIn)
Assignment operator.- Overrides:
assignin classCVisDVector- Parameters:
vIn- Input vector.- Returns:
- This.
-
assign
public CDVector assign(CDVector vIn)
Assignment operator.- Parameters:
vIn- Input vector.- Returns:
- This.
-
assign
public CDVector assign(double value)
Assignment operator. Sets all element to the input value.- Overrides:
assignin classCVisDVector- Parameters:
vIn- Input double.- Returns:
- This.
-
assign
public CDVector assign(double[] value)
Assignment operator.- Parameters:
value-- Returns:
- this
-
Max
public double Max()
Finds the maximum element in the vector.- Returns:
- The maximum value of the elements.
-
Min
public double Min()
Finds the minimum element in the vector.- Returns:
- The minimum value of the elements.
-
Min
public double Min(int[] iPos)
Finds the minimum element in the vector and its position.- Returns:
- The minimum value of the elements and its position.
-
Mean
public double Mean()
Calculates the mean value of the vector.- Returns:
- The mean value.
-
Skewness
public double Skewness()
Calculates the skewness the vector.- Returns:
- The skewness.
-
Std
public double Std()
Calculates the standard deviation the vector.- Returns:
- The skewness.
-
Sum
public double Sum()
Calculates the sum of the vector.- Returns:
- The sum.
-
Var
public double Var()
-
Var
public double Var(double[] pMean)
Calculates the variance the vector.- Parameters:
pMean- Optional pointer, where the mean is returned.- Returns:
- The variance.
-
__dbl_cmp_asc
public static int __dbl_cmp_asc(double[] arg1, double[] arg2)static compare functions for the Sort() function
-
__dbl_cmp_des
public static int __dbl_cmp_des(double[] arg1, double[] arg2)
-
Sort
public void Sort()
-
Sort
public void Sort(boolean ascending)
Sorts the vector in either ascending (default) or descending order. Implemented using the standard array sort().- Parameters:
ascending- If true (default) the vector is sorted in ascending order. If false its sorted in descending order.
-
Sqr
public void Sqr()
Squares each element.
-
Sqrt
public void Sqrt()
Takes the square root of each element.
-
Pow
public void Pow(double dP)
Takes the power 'dP' of each element.- Parameters:
dP- The exponent.
-
ElementMultiply
public void ElementMultiply(CDVector vector)
Multiplies two vectors element-wise. Corresponding MatLab operator ".*".- Parameters:
vector- The input vector to multiply this vector with.
-
ElementDivide
public void ElementDivide(CDVector vector)
Divide two vectors element-wise. Corresponding MatLab operator "./".- Parameters:
vector- The input vector to divide this vector with.
-
ToString
public java.lang.String ToString(boolean fNewline)
Returns a string representing the vector.- Parameters:
fNewline- If true, the string is terminated with a new line.- Returns:
- The output string.
-
Norm1
public double Norm1()
Calculates the one-norm (L1) of the vector. Also known as the city block metric. L1(v) = |x_1| + |x_2| .. + |x_n|- Returns:
- The L1 norm.
-
Norm2
public double Norm2()
Calculates the two-norm (L2) of the vector. Also known as the Euclidean length. L2(v) = sqrt( x_1^2 + x_2^2 .. + x_n^2 )- Overrides:
Norm2in classCVisDVector- Returns:
- The L2 norm.
-
NormInf
public double NormInf()
Calculates the infinity-norm (Linf) of the vector. Also known as the Chebyshev Norm. Linf(v) = max( |x_1|, |x_2| ... , |x_n| )- Returns:
- The L2 norm.
-
Normalize2
public void Normalize2()
Normalizes the vector to unit length, using the 2-norm.
-
ToMatlab
public void ToMatlab(java.lang.String sFilename, java.lang.String sName, java.lang.String sComment, boolean fAppend)Writes the vector to disk in MatLab (.m) format. To read the vector into MatLab write e.g. 'my_vector.m' at the MatLab prompt. Notice that this should be used for storage a (really) large vectors, 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'.
-
ToFile
public void ToFile(java.lang.String sFilename)
Writes the vector to disk in binary format. Use 'readbin.m' to load such a file into MatLab (placed in the diva/matlab dir).- Parameters:
sFilename- Output file name.
-
FromFile
public void FromFile(java.lang.String sFilename)
Reads a vector from disk in binary format.- Parameters:
sFilename- Input file name.
-
ToFile
public void ToFile(java.io.DataOutputStream fh)
Writes the vector to disk in binary format. Use 'readbin.m' to load such a file into MatLab (placed in the diva/matlab dir).- Parameters:
fh- Open file handle (opened using fopen())
-
FromFile
public void FromFile(java.io.DataInputStream fh)
Reads a vector from disk in binary format.- Parameters:
fh- Open file handle (opened using fopen())
-
Eq
public void Eq(double B, CDVector C)Equal - compares a vector and a double. Compares of a vector and a double and returns the result as a binary vector i.e.: C(i) = 1 if A(i) == B C(i) = 0 else Corresponding MatLab function EQ()- Parameters:
B- Input double.C- Output result vector.
-
Eq
public void Eq(CDVector B, CDVector C)
Equal - compares a vector and a vector. Compares of a vector and a vector and returns the result as a binary matrix i.e.: C(i) = 1 if A(i) == B C(i) = 0 else Corresponding MatLab function EQ()- Parameters:
B- Input vector.C- Output result vector.
-
Ne
public void Ne(double B, CDVector C)Not Equal - compares a double and a vector. Compares of a double and a vector and returns the result as a binary matrix i.e.: C(i) = 1 if A(i) != B C(i) = 0 else Corresponding MatLab function NE()- Parameters:
B- Input double.C- Output result vector.
-
Ne
public void Ne(CDVector B, CDVector C)
Not Equal - compares a vector and a vector. Compares of a vector and a vector and returns the result as a binary matrix i.e.: C(i) = 1 if A(i) != B C(i) = 0 else Corresponding MatLab function NE()- Parameters:
B- Input vector.C- Output result vector.
-
Lt
public void Lt(double B, CDVector C)Less Than - compares a double and a vector. Compares of a double and a vector and returns the result as a binary matrix i.e.: C(i) = 1 if A(i) < B C(i) = 0 else Corresponding MatLab function LT()- Parameters:
B- Input double.C- Output result vector.
-
Lt
public void Lt(CDVector B, CDVector C)
Less Than - compares a vector and a vector. Compares of a vector and a vector and returns the result as a binary matrix i.e.: C(i) = 1 if A(i) < B C(i) = 0 else Corresponding MatLab function LT()- Parameters:
B- Input vector.C- Output result vector.
-
Le
public void Le(double B, CDVector C)Less Than or Equal - compares a double and a vector. Compares of a double and a vector and returns the result as a binary matrix i.e.: C(i) = 1 if A(i) <= B C(i) = 0 else Corresponding MatLab function LE()- Parameters:
B- Input double.C- Output result vector.
-
Le
public void Le(CDVector B, CDVector C)
Less Than or Equal - compares a vector and a vector. Compares of a vector and a vector and returns the result as a binary matrix i.e.: C(i) = 1 if A(i) <= B C(i) = 0 else Corresponding MatLab function LE()- Parameters:
B- Input vector.C- Output result vector.
-
Gt
public void Gt(double B, CDVector C)Greater Than - compares a double and a vector. Compares of a double and a vector and returns the result as a binary matrix i.e.: C(i) = 1 if A(i) > B C(i) = 0 else Corresponding MatLab function GT()- Parameters:
B- Input vector.C- Output result vector.
-
Gt
public void Gt(CDVector B, CDVector C)
Greater Than - compares a vector and a vector. Compares of a vector and a vector and returns the result as a binary matrix i.e.: C(i) = 1 if A(i) > B C(i) = 0 else Corresponding MatLab function GT()- Parameters:
B- Input vector.C- Output result vector.
-
Ge
public void Ge(double B, CDVector C)Greater Than or Equal - compares a double and a vector. Compares of a double and a vector and returns the result as a binary matrix i.e.: C(i) = 1 if A(i) >= B C(i) = 0 else Corresponding MatLab function GE()- Parameters:
B- Input double.C- Output result vector.
-
Ge
public void Ge(CDVector B, CDVector C)
Greater Than or Equal - compares a vector and a vector. Compares of a vector and a vector and returns the result as a binary matrix i.e.: C(i) = 1 if A(i) >= B C(i) = 0 else Corresponding MatLab function GE()- Parameters:
B- Input vector.C- Output result vector.
-
Log
public void Log()
Takes the natural logarithm of each element.
-
Abs
public void Abs()
Takes the absolute valueof each element.
-
Reverse
public void Reverse()
Reverses the vector.
-
Rand
public void Rand()
Uniformly distributed random numbers. Inserts uniformly distributed random numbers in the range [0;1].
-
Rand
public void Rand(int st, int end)Uniformly distributed integer random numbers. Inserts uniformly distributed integer random numbers in the range [st;end].
-
CrossProduct
public void CrossProduct(CDVector v1, CDVector v2)
Forms the cross product of two vectors and store the result in this. If the vector does have the correct size, it will be resized.- Parameters:
v1- Input vector.v2- Input vector.
-
Ceil
public void Ceil()
Takes ceil() of each element.
-
Floor
public void Floor()
Takes floor() of each element.
-
Round
public void Round()
Takes round() of each element.
-
Linspace
public void Linspace(double x1, double x2, int n)Generates a vector of linearly equally spaced points between x1 and x2 (inclusive).- Parameters:
x1- Starting point.x2- Ending point.n- Number of points.
-
Range
public CDVector Range(int st, int end)
Returns a sub range of a vector.- Parameters:
st- Starting posistion.end- End postion.- Returns:
- A sub range in a vector.
-
ToMatrix
public void ToMatrix(int nRows, int nCols, CDMatrix m, boolean rowWise)Converts this vector to a matrix, either by row (default) or column.- Parameters:
nRows- Number of rows in the matrix.nCols- Number of cols in the matrix.m- Output matrix.rowWise- If true (default) vector data is extracted into rows. If false vector data is extracted into cols.
-
VecCat
public CDVector VecCat(CDVector v)
Concatenates a vector to the end of this vector.- Parameters:
v- Input vector.- Returns:
- Concatenated vector.
-
Clamp
public void Clamp(double min, double max)Clamps the vector to [min,max].- Parameters:
min- Minumim value.max- Maximum value.
-
AlignTo
public void AlignTo(CDVector v)
-
AlignTo
public void AlignTo(CDVector v, double[] pA, double[] pB)
Linear alignment of this vector to another vector using the L2 norm.- Parameters:
v- Vector that this vector is being least squares fitted to.a- Optional pointer to store the resulting transformation in.b- Optional pointer to store the resulting transformation in.
-
AutoCorrelation
public double AutoCorrelation(int lag)
Calculates the autocorrelation of the vector with a given lag (default lag is 1).- Parameters:
lag- The lag.- Returns:
- The autocorrelation.
-
Shuffle
public void Shuffle()
Shuffles (randomizes) the vector.
-
quick_select
double quick_select(double[] arr, int n)
-
Median
public double Median()
Calculates the median.- Returns:
- The median.
-
Trim
public CDVector Trim(double percentage)
Removes the extreme 'percentage' part of the vector. E.g. v.Trim( .10 ) removes the 5% of the lower tail and 5% of the upper tail. By convention Trim( 1. ) returns the median.- Parameters:
percentage- The amount of data to strip from the vector.- Returns:
- A trimmed version of the vector.
-
TrimmedMean
public double TrimmedMean(double percentage)
Calculates the trimmed mean. Removes the extreme 'percentage' part of the vector and calculates the mean of the remaining data.- Parameters:
percentage- The amount of data to strip from the vector.- Returns:
- The trimmed mean.
-
TrimmedVar
public double TrimmedVar(double percentage)
Calculates the trimmed variance. Removes the extreme 'percentage' part of the vector and calculates the variance of the remaining data.- Parameters:
percentage- The amount of data to strip from the vector.- Returns:
- The trimmed mean.
-
TrimmedStd
public double TrimmedStd(double percentage)
Calculates the trimmed standard deviation. Removes the extreme 'percentage' part of the vector and calculates the standard deviation of the remaining data.- Parameters:
percentage- The amount of data to strip from the vector.- Returns:
- The trimmed mean.
-
-