[Insight-users] Submission: PCA decomposition calculator
Luis Ibanez
luis.ibanez@kitware.com
Thu May 13 21:17:26 EDT 2004
Hi Zach,
Thanks for submitting this improvements to the class and its test.
They have now been commited in the repository.
Regards,
Luis
------------------------
Zachary Pincus wrote:
> Thanks,
>
> I actually fixed that error and added a more complete set of test cases
> in the code I sent out to the list yesterday; sorry if I'm a bit out of
> synch with you guys. (I also tightened up an inner loop in the
> computation.) Here is that version of the code/headers/test, which also
> now incorporates the style changes you made to the CVS code (thanks for
> that!).
>
> Zach
>
>
> ------------------------------------------------------------------------
>
> /*=========================================================================
>
> Program: Insight Segmentation & Registration Toolkit
> Module: $RCSfile: itkImagePCADecompositionCalculator.h,v $
> Language: C++
> Date: $Date: 2004/05/03 01:33:36 $
> Version: $Revision: 1.2 $
>
> Copyright (c) Insight Software Consortium. All rights reserved.
> See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
>
> This software is distributed WITHOUT ANY WARRANTY; without even
> the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
> PURPOSE. See the above copyright notices for more information.
>
> =========================================================================*/
>
> #ifndef __itkImagePCADecompositionCalculator_h
> #define __itkImagePCADecompositionCalculator_h
>
> #include "itkObject.h"
> #include "itkImagePCAShapeModelEstimator.h"
> #include "vnl/vnl_vector.h"
> #include "vnl/vnl_matrix.h"
>
> namespace itk
> {
>
> /** \class ImagePCADecompositionCalculator
> * \brief Decomposes an image into directions along basis components.
> *
> * This calculator computes the projection of an image into a subspace specified
> * by some orthonormal basis.
> * Typically, this basis will be the principal components of an image data set,
> * as calculated by an ImagePCAShapeModelEstimator. The output of the calculator
> * is a vnl_vector containing the coefficients along each dimension of the
> * provided basis set.
> * To use this calculator, first set each basis image with the SetBasisImage
> * method. In the PCA case, the basis images are the outputs of the
> * ImagePCAShapeModelEstimator (except the zeroth output, which is the average
> * image).
> * SetBasisFromModel is a convenience method to set all of this information from
> * a given ImagePCAShapeModelEstimator instance.
> *
> * This class is templated over the input image type and the type of images
> * used to describe the basis.
> *
> * \warning This method assumes that the input image consists of scalar pixel
> * types.
> *
> * \warning All images (input and basis) must be the same size.
> *
> * \author Zachary Pincus
> *
> * \ingroup Operators
> */
> template <class TInputImage,
> class TBasisImage = Image<double, ::itk::GetImageDimension<TInputImage>::ImageDimension> >
> class ITK_EXPORT ImagePCADecompositionCalculator : public Object
> {
> public:
> /** Standard class typedefs. */
> typedef ImagePCADecompositionCalculator Self;
> typedef Object Superclass;
> typedef SmartPointer<Self> Pointer;
> typedef SmartPointer<const Self> ConstPointer;
>
> /** Method for creation through the object factory. */
> itkNewMacro(Self);
>
> /** Run-time type information (and related methods). */
> itkTypeMacro(ImagePCADecompositionCalculator, Object);
>
> /** Type definitions for the input images. */
> typedef TInputImage InputImageType;
> typedef TBasisImage BasisImageType;
>
> /** Pointer types for the image. */
> typedef typename TInputImage::Pointer InputImagePointer;
> typedef typename TBasisImage::Pointer BasisImagePointer;
>
> /** Const Pointer type for the image. */
> typedef typename TInputImage::ConstPointer InputImageConstPointer;
>
> /** Basis image pixel type: this is also the type of the optput vector */
> typedef typename TBasisImage::PixelType BasisPixelType;
> /** Input Image dimension */
> itkStaticConstMacro(InputImageDimension, unsigned int,
> TInputImage::ImageDimension);
>
> /** Basis Image dimension */
> itkStaticConstMacro(BasisImageDimension, unsigned int,
> TBasisImage::ImageDimension);
>
>
> /** Vector of basis image pointers. */
> typedef std::vector< BasisImagePointer > BasisImagePointerVector;
>
> /** Type definitions for internal vectors and matrices */
> typedef vnl_matrix<BasisPixelType> BasisMatrixType;
> typedef vnl_vector<BasisPixelType> BasisVectorType;
>
> /** Set the input image. */
> itkSetConstObjectMacro(Image,InputImageType);
>
> /** Set the basis images. */
> void SetBasisImages(const BasisImagePointerVector _arg);
>
> /** Get the basis images. */
> BasisImagePointerVector& GetBasisImages(void) {return m_BasisImages;}
>
> /** Type definition of a compatible ImagePCAShapeModelEstimator */
> typedef typename ImagePCAShapeModelEstimator<TInputImage,
> TBasisImage>::Pointer ModelPointerType;
> /** Set the basis images from a ImagePCAShapeModelEstimator */
> void SetBasisFromModel(ModelPointerType model);
>
> /** Compute the PCA decomposition of the input image. */
> void Compute(void);
>
> /** Return the projection of the image. */
> itkGetMacro(Projection,BasisVectorType);
>
>
> protected:
> ImagePCADecompositionCalculator();
> virtual ~ImagePCADecompositionCalculator() {};
> void PrintSelf(std::ostream& os, Indent indent) const;
> void CalculateBasisMatrix(void);
> void CalculateImageAsVector(void);
>
> private:
> typedef typename BasisImageType::SizeType BasisSizeType;
>
> ImagePCADecompositionCalculator(const Self&); //purposely not implemented
> void operator=(const Self&); //purposely not implemented
>
> BasisVectorType m_Projection;
> BasisVectorType m_ImageAsVector;
> BasisImagePointerVector m_BasisImages;
> BasisSizeType m_Size;
> InputImageConstPointer m_Image;
> BasisMatrixType m_BasisMatrix;
> bool m_BasisMatrixCalculated;
> unsigned long m_NumPixels;
> };
>
> } // end namespace itk
>
>
> #ifndef ITK_MANUAL_INSTANTIATION
> #include "itkImagePCADecompositionCalculator.txx"
> #endif
>
> #endif
>
>
> ------------------------------------------------------------------------
>
>
>
>
> On May 4, 2004, at 5:06 AM, Lorensen, William E (Research) wrote:
>
>> Luis and Zach,
>>
>> I fixed the problems with this test yesterday. It is now passing
>> everywhere.
>> If you make changes to the code or test, please edit the current cvs
>> repository versions.
>>
>> Thanks,
>>
>> Bill
>>
>> -----Original Message-----
>> From: Luis Ibanez [mailto:luis.ibanez@kitware.com]
>> Sent: Monday, May 03, 2004 5:57 PM
>> To: Zachary Pincus
>> Cc: insight-users@itk.org
>> Subject: Re: [Insight-users] Submission: PCA decomposition calculator
>>
>>
>>
>> Hi Zach,
>>
>> Thanks for looking into this.
>>
>> Unfortunately I just tried the new test along
>> with the new .h and .txx files that you sent
>> and the test is still failing.
>>
>>
>> Here is the output I got:
>>
>> -----------------------------------------------------------------
>>
>> ImagePCADecompositionCalculator (015E6220)
>> RTTI typeinfo: class itk::ImagePCADecompositionCalculator<class
>> itk::Image<double,2>,class itk::Image<double,2> >
>> Test failed Reference Count: 1
>> Modified Time: 25
>> Debug: Off
>> Observers:
>> none
>> Projection: 0.6228 -2.9346
>> Image: 015E6008
>> The basis of projection is:
>> [-0.3853 0.5929 0.5929 -0.3853 ]
>> [-0.5929 -0.3853 -0.3853 -0.5929 ]
>> The projection of [0 2 2 0] is [-1.5412 -2.3716]
>> this should be approx [-1.5412 -2.3716]
>> The projection of [0 3 3 0] is [0.6228 -2.9346]
>> this should be approx [3.5574 -2.3119]
>>
>>
>> The project is out of the range of Matlab precomputed values
>> ***Failed
>>
>> 0% tests passed, 1 tests failed out of 1
>>
>> -----------------------------------------------------------------
>>
>>
>> Regards,
>>
>>
>> Luis
>>
>>
>>
>> ----------------------------
>> Zachary Pincus wrote:
>>
>>> OK, here is a new version of the code and the test for the PCA
>>> decomposition calculator.
>>>
>>> The test was slightly broken (my fault) which lead to all of the errors,
>>> but now that should be fixed. I've also made the testing a bit more
>>> complete.
>>>
>>> I've also tightened the code up a bit now, for what that's worth.
>>>
>>> Thanks, and I am quite impressed at how well the kitware build/test
>>> system works.
>>>
>>> Zach
>>>
>>>
>>
>>
>>
>> _______________________________________________
>> Insight-users mailing list
>> Insight-users@itk.org
>> http://www.itk.org/mailman/listinfo/insight-users
>>
More information about the Insight-users
mailing list