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 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 $ Copyright (c) 1999-2001 by Informatics invalid input: '&' Mathmatical Modelling, Section for Image Analysis IMM, Informatics invalid input: '&' 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 int
     

    Fields inherited from class gov.nih.mipav.view.renderer.WildMagic.AAM.CVisDVector

    m_data, m_fExternalStorage, m_length
  • Constructor Summary

    Constructors
    Constructor
    Description
    constructor
    CDVector(int length)
     
    CDVector(int length, double[] storage)
     
     
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static int
    __dbl_cmp_asc(double[] arg1, double[] arg2)
    static compare functions for the Sort() function
    static int
    __dbl_cmp_des(double[] arg1, double[] arg2)
     
    void
    Abs()
    Takes the absolute valueof each element.
    void
     
    void
    AlignTo(CDVector v, double[] pA, double[] pB)
    Linear alignment of this vector to another vector using the L2 norm.
    assign(double value)
    Assignment operator.
    assign(double[] value)
    Assignment operator.
    Assignment operator.
    Assignment operator.
    double
    AutoCorrelation(int lag)
    Calculates the autocorrelation of the vector with a given lag (default lag is 1).
    void
    Takes ceil() of each element.
    void
    Clamp(double min, double max)
    Clamps the vector to [min,max].
    void
    Forms the cross product of two vectors and store the result in this.
    void
    Divide two vectors element-wise.
    void
    Multiplies two vectors element-wise.
    void
    Eq(double B, CDVector C)
    Equal - compares a vector and a double.
    void
    Equal - compares a vector and a vector.
    void
    Takes floor() of each element.
    void
    Reads a vector from disk in binary format.
    void
    FromFile(String sFilename)
    Reads a vector from disk in binary format.
    void
    Ge(double B, CDVector C)
    Greater Than or Equal - compares a double and a vector.
    void
    Greater Than or Equal - compares a vector and a vector.
    void
    Gt(double B, CDVector C)
    Greater Than - compares a double and a vector.
    void
    Greater Than - compares a vector and a vector.
    void
    Le(double B, CDVector C)
    Less Than or Equal - compares a double and a vector.
    void
    Less Than or Equal - compares a vector and a vector.
    void
    Linspace(double x1, double x2, int n)
    Generates a vector of linearly equally spaced points between x1 and x2 (inclusive).
    void
    Log()
    Takes the natural logarithm of each element.
    void
    Lt(double B, CDVector C)
    Less Than - compares a double and a vector.
    void
    Less Than - compares a vector and a vector.
    double
    Max()
    Finds the maximum element in the vector.
    double
    Calculates the mean value of the vector.
    double
    Calculates the median.
    double
    Min()
    Finds the minimum element in the vector.
    double
    Min(int[] iPos)
    Finds the minimum element in the vector and its position.
    void
    Ne(double B, CDVector C)
    Not Equal - compares a double and a vector.
    void
    Not Equal - compares a vector and a vector.
    double
    Calculates the one-norm (L1) of the vector.
    double
    Calculates the two-norm (L2) of the vector.
    void
    Normalizes the vector to unit length, using the 2-norm.
    double
    Calculates the infinity-norm (Linf) of the vector.
    void
    Pow(double dP)
    Takes the power 'dP' of each element.
    (package private) double
    quick_select(double[] arr, int n)
     
    void
    Uniformly distributed random numbers.
    void
    Rand(int st, int end)
    Uniformly distributed integer random numbers.
    Range(int st, int end)
    Returns a sub range of a vector.
    void
    Reverses the vector.
    void
    Takes round() of each element.
    void
    Shuffles (randomizes) the vector.
    double
    Calculates the skewness the vector.
    void
     
    void
    Sort(boolean ascending)
    Sorts the vector in either ascending (default) or descending order.
    void
    Sqr()
    Squares each element.
    void
    Takes the square root of each element.
    double
    Std()
    Calculates the standard deviation the vector.
    double
    Sum()
    Calculates the sum of the vector.
    void
    Writes the vector to disk in binary format.
    void
    ToFile(String sFilename)
    Writes the vector to disk in binary format.
    void
    ToMatlab(String sFilename, String sName, String sComment, boolean fAppend)
    Writes the vector to disk in MatLab (.m) format.
    void
    ToMatrix(int nRows, int nCols, CDMatrix m, boolean rowWise)
    Converts this vector to a matrix, either by row (default) or column.
    ToString(boolean fNewline)
    Returns a string representing the vector.
    Trim(double percentage)
    Removes the extreme 'percentage' part of the vector.
    double
    TrimmedMean(double percentage)
    Calculates the trimmed mean.
    double
    TrimmedStd(double percentage)
    Calculates the trimmed standard deviation.
    double
    TrimmedVar(double percentage)
    Calculates the trimmed variance.
    double
    Var()
     
    double
    Var(double[] pMean)
    Calculates the variance the vector.
    Concatenates a vector to the end of this vector.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • RAND_MAX

      public static int RAND_MAX
  • Constructor Details

    • 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 Details

    • assign

      public CDVector assign(CVisDVector vIn)
      Assignment operator.
      Overrides:
      assign in class CVisDVector
      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:
      assign in class CVisDVector
      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 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:
      Norm2 in class CVisDVector
      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(String sFilename, String sName, 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(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(String sFilename)
      Reads a vector from disk in binary format.
      Parameters:
      sFilename - Input file name.
    • ToFile

      public void ToFile(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(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) invalid input: '<' 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) invalid input: '<' 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) invalid input: '<'= 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) invalid input: '<'= 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.