Difference between revisions of "NAMIC Wiki:DTI:ITK"

From NAMIC Wiki
Jump to: navigation, search
m (Update from Wiki)
m (Update from Wiki)
 
(5 intermediate revisions by the same user not shown)
Line 1: Line 1:
The DiffusionTensorPixel type derives from the itk::FixedArray<> instantiated for a fixed size of 6 elements. The rationale behind it is that we are dealing with symmetric tensors in this particular case, therefore for the sake of memory use we only store 6 components. The type however will also implement a matrix-like notation in order to provide a natural notation for tensor operations.
+
This page host a discussion on the implementation details of a Tensor class.
  
A short version of the class essentials is below, a full compilable version is at the end of this page
+
== Tensors and Traits ==
  
+
Torsten Rohlfing for SRI International Neuroscience Program proposed the following for ITK tensor processing:
template < typename TComponent = float >
 
class DiffusionTensorPixel: public FixedArray<TComponent,6>
 
{
 
public:
 
  typedef DiffusionTensorPixel  Self;
 
  typedef FixedArray<TComponent, 6> SuperClass;
 
  itkStaticConstMacro(Dimension, unsigned int, 6);
 
  itkStaticConstMacro(Length, unsigned int, 6);
 
  typedef FixedArray<TComponent, 6> BaseArray;
 
 
  /** Array of eigen-values. */
 
  typedef FixedArray<TComponent, 3> EigenValuesArray;
 
  typedef Matrix<TComponent, 3, 3>  EigenVectorsMatrix;
 
 
  /** Matrix notation, in const and non-const forms. */
 
  ValueType & operator()( unsigned int i, unsigned int j);
 
  const ValueType & operator()( unsigned int i, unsigned int j) const;
 
};
 
 
 
  
<br /> Here is the full version of the class. This code is compilable using ITK 2.0.
+
* Separate the operations which depend on the tensor size from those that do not.
 +
** The former are in tensor traits, the latter are in tensor class.
 +
* Filter classes operate on different tensor pixel type images (by templating).
 +
** The tensor classes can be more or less specialized. In particular, the filters will be able to support more general tensor classes that may be implemented later, as long as they provide the necessary interface functions for any given filter.
 +
* [[NAMIC_Wiki:DTI:ITK-SymmetricTensorPixelType:Header|itkSymmetricTensor.h]]
 +
** Contains functions that do not benefit from knowledge of the tensor size, e.g., GetVnlMatrix()
 +
* [[NAMIC_Wiki:DTI:ITK-SymmetricTensorTraits::Header|itkSymmetricTensorTraits.h]]
 +
** Operations that depend on the tensor size, e.g., eigenvalue computation.
 +
* itkTensorToFractionalAnisotropyImageFilter.{h,txx}
 +
** Example filter that operates on tensor data.
 +
** Operates on any tensor class that implements T::ComputeEigenvalues()
 +
* DiffusionTensorToFractionalAnisotropy.cxx
 +
** Example application. Reads a tensor image from a raw data file, computes the FA image, and writes the result.
  
<nowiki>
+
=== A First version of the SymmetricSecondRankTensor class committed to ITK ===
#ifndef __itkDiffusionTensorPixel_h
+
 
#define __itkDiffusionTensorPixel_h
+
Given that Tensor can have any rank, from zero (scalar), one (vector), two (matrices) to N. It seemed appropriate to specify that this particular class was representing a symmetric tensor of second rank.
+
 
// Undefine an eventual DiffusionTensorPixel macro
+
The class has been committed into ITK (May 2 2005) and it is expected to evolve in the CVS repository.
#ifdef DiffusionTensorPixel
+
 
#undef DiffusionTensorPixel
+
=== A first version of SymmetricEigenAnalysis class committed to ITK ===
#endif
+
 
+
Serves as a thread safe alternative to vnl_symmetric_eigensystem, which calls netlib C routines is not thread safe. Please use this class in any multi-threaded filters.
#include <itkIndent.h>
+
 
#include <itkFixedArray.h>
+
=== A Hessian filter uses the Symmetric second rank tensor class ===
#include <itkMatrix.h>
+
 
#include "vnl/vnl_math.h"
+
A filter for computing the Hessian of an image was also committed to ITK. This filter illustrates the first use of the SymmetricSecondRankTensor class as pixel type of an image.
 
namespace itk
 
{
 
 
/** \class DiffusionTensorPixel
 
  * \brief Represent a diffusion tensor as used in DTI images.
 
  *
 
  * This class implements a 3D symmetric tensor as it is used for representing
 
  * diffusion of water molecules in Diffusion Tensor Images.
 
  *
 
  * Since DiffusionTensorPixel is a subclass of Array, you can access its components as:
 
  *
 
  * typedef itk::DiffusionTensorPixel< float >    TensorPixelType;
 
  * TensorPixelType tensor;
 
  *
 
  *  tensor[0] = 1.233;
 
  *  tensor[1] = 1.456;
 
  *
 
  * for convenience the indexed access is also available as
 
  *
 
  *  tensor(0,0) = 1.233;
 
  *  tensor(2,0) = 1.233;
 
  *
 
  * The Tensor in principle represents a 3x3 matrix, but given that it is
 
  * always symmetric the representation can be compacted into a 6-elements
 
  * array that derives from the itk::FixedArray<T>
 
  *
 
  * \ingroup ImageObjects
 
  */
 
 
template < typename TComponent = float >
 
class DiffusionTensorPixel: public FixedArray<TComponent,6>
 
{
 
public:
 
  /** Standard class typedefs. */
 
  typedef DiffusionTensorPixel  Self;
 
  typedef FixedArray<TComponent, 6> SuperClass;
 
 
  /** Dimension of the vector space. */
 
  itkStaticConstMacro(Dimension, unsigned int, 6);
 
  itkStaticConstMacro(Length, unsigned int, 6);
 
 
  /** Convenience typedefs. */
 
  typedef FixedArray<TComponent, 6> BaseArray;
 
 
  /** Array of eigen-values. */
 
  typedef FixedArray<TComponent, 3> EigenValuesArray;
 
 
  /** Matrix of eigen-vectors. */
 
  typedef Matrix<TComponent, 3, 3> EigenVectorsMatrix;
 
 
  /**  Define the component type. */
 
  typedef TComponent ComponentType;
 
  typedef typename SuperClass::ValueType ValueType;
 
 
  /** Default constructor has nothing to do. */
 
  DiffusionTensorPixel() {this->Fill(0);}
 
  DiffusionTensorPixel (const ComponentType& r) { this->Fill(r); }
 
 
  /** Pass-through constructor for the Array base class. */
 
  DiffusionTensorPixel(const Self& r): BaseArray(r) {}
 
  DiffusionTensorPixel(const ComponentType  r[6]): BaseArray(r) {}
 
 
  /** Pass-through assignment operator for the Array base class. */
 
  Self& operator= (const Self& r);
 
  Self& operator= (const ComponentType r[6]);
 
 
  /** Aritmetic operations between pixels. Return a new DiffusionTensorPixel. */
 
  Self operator+(const Self &vec) const;
 
  Self operator-(const Self &vec) const;
 
  const Self & operator+=(const Self &vec);
 
  const Self & operator-=(const Self &vec);
 
  Self operator*(const ComponentType &f) const;
 
 
 
  /** Return the number of components. */
 
  static int GetNumberOfComponents(){ return 6;}
 
 
  /** Return the value for the Nth component. */
 
  ComponentType GetNthComponent(int c) const
 
    { return this->operator[](c); }
 
 
  /** Set the Nth component to v. */
 
  void SetNthComponent(int c, const ComponentType& v)
 
    {  this->operator[](c) = v; }
 
 
  /** Matrix notation, in const and non-const forms. */
 
  ValueType & operator()( unsigned int i, unsigned int j);
 
  const ValueType & operator()( unsigned int i, unsigned int j) const;
 
 
};
 
 
 
template< typename TComponent  >
 
ITK_EXPORT std::ostream& operator<<(std::ostream& os,
 
                                    const DiffusionTensorPixel<TComponent> & c);
 
template< typename TComponent  >
 
ITK_EXPORT std::istream& operator>>(std::istream& is,
 
                                          DiffusionTensorPixel<TComponent> & c);
 
 
} // end namespace itk
 
 
#ifndef ITK_MANUAL_INSTANTIATION
 
#include "itkDiffusionTensorPixel.txx"
 
#endif
 
 
#endif
 
</nowiki>
 

Latest revision as of 14:06, 18 December 2006

Home < NAMIC Wiki:DTI:ITK

This page host a discussion on the implementation details of a Tensor class.

Tensors and Traits

Torsten Rohlfing for SRI International Neuroscience Program proposed the following for ITK tensor processing:

  • Separate the operations which depend on the tensor size from those that do not.
    • The former are in tensor traits, the latter are in tensor class.
  • Filter classes operate on different tensor pixel type images (by templating).
    • The tensor classes can be more or less specialized. In particular, the filters will be able to support more general tensor classes that may be implemented later, as long as they provide the necessary interface functions for any given filter.
  • itkSymmetricTensor.h
    • Contains functions that do not benefit from knowledge of the tensor size, e.g., GetVnlMatrix()
  • itkSymmetricTensorTraits.h
    • Operations that depend on the tensor size, e.g., eigenvalue computation.
  • itkTensorToFractionalAnisotropyImageFilter.{h,txx}
    • Example filter that operates on tensor data.
    • Operates on any tensor class that implements T::ComputeEigenvalues()
  • DiffusionTensorToFractionalAnisotropy.cxx
    • Example application. Reads a tensor image from a raw data file, computes the FA image, and writes the result.

A First version of the SymmetricSecondRankTensor class committed to ITK

Given that Tensor can have any rank, from zero (scalar), one (vector), two (matrices) to N. It seemed appropriate to specify that this particular class was representing a symmetric tensor of second rank.

The class has been committed into ITK (May 2 2005) and it is expected to evolve in the CVS repository.

A first version of SymmetricEigenAnalysis class committed to ITK

Serves as a thread safe alternative to vnl_symmetric_eigensystem, which calls netlib C routines is not thread safe. Please use this class in any multi-threaded filters.

A Hessian filter uses the Symmetric second rank tensor class

A filter for computing the Hessian of an image was also committed to ITK. This filter illustrates the first use of the SymmetricSecondRankTensor class as pixel type of an image.