Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkTensorToRgbImageFilter_h
00019 #define __itkTensorToRgbImageFilter_h
00020
00021 #include "itkUnaryFunctorImageFilter.h"
00022 #include "itkRGBAPixel.h"
00023
00024 namespace itk
00025 {
00026
00027 #define __IMG_DAT_ITEM__CEIL_ZERO_ONE__(val) (val) = \
00028 ( (val) < 0 ) ? ( 0 ) : ( ( (val)>1 ) ? ( 1 ) : ( (val) ) );
00029
00033 template <typename TInputImage,
00034 typename TOutputImage=itk::Image<itk::RGBAPixel<unsigned char>,3> >
00035 class TensorToRgbImageFilter :
00036 public ImageToImageFilter<TInputImage,TOutputImage>
00037 {
00038 public:
00040 typedef TensorToRgbImageFilter Self;
00041 typedef ImageToImageFilter<TInputImage,TOutputImage>
00042 Superclass;
00043 typedef SmartPointer<Self> Pointer;
00044 typedef SmartPointer<const Self> ConstPointer;
00045
00046 typedef typename Superclass::InputImageType InputImageType;
00047 typedef typename Superclass::OutputImageType OutputImageType;
00048 typedef typename OutputImageType::PixelType OutputPixelType;
00049 typedef typename TInputImage::PixelType InputPixelType;
00050 typedef typename InputPixelType::ValueType InputValueType;
00051
00053 itkTypeMacro( TensorToRgbImageFilter, ImageToImageFilter );
00054
00056 itkNewMacro(Self);
00057
00059 void PrintSelf(std::ostream& os, Indent indent) const
00060 { this->Superclass::PrintSelf( os, indent ); }
00061
00062 #ifdef ITK_USE_CONCEPT_CHECKING
00063
00064 itkConceptMacro(InputHasNumericTraitsCheck,
00065 (Concept::HasNumericTraits<InputValueType>));
00067 #endif
00068
00069 protected:
00070 TensorToRgbImageFilter() {};
00071 virtual ~TensorToRgbImageFilter() {};
00072
00073 void GenerateData()
00074 {
00075
00076 typename InputImageType::Pointer tensorImage = static_cast< InputImageType * >( this->ProcessObject::GetInput(0) );
00077
00078 typename OutputImageType::Pointer outputImage =
00079 static_cast< OutputImageType * >(this->ProcessObject::GetOutput(0));
00080
00081 typename InputImageType::RegionType region = tensorImage->GetLargestPossibleRegion();
00082
00083 outputImage->SetSpacing( tensorImage->GetSpacing() );
00084 outputImage->SetOrigin( tensorImage->GetOrigin() );
00085 outputImage->SetDirection( tensorImage->GetDirection() );
00086 outputImage->SetRegions( tensorImage->GetLargestPossibleRegion());
00087 outputImage->Allocate();
00088
00089 typedef ImageRegionConstIterator< InputImageType > TensorImageIteratorType;
00090 TensorImageIteratorType tensorIt(tensorImage, tensorImage->GetLargestPossibleRegion());
00091
00092 typedef ImageRegionIterator< OutputImageType > OutputImageIteratorType;
00093 OutputImageIteratorType outputIt(outputImage, outputImage->GetLargestPossibleRegion());
00094
00095 tensorIt.GoToBegin();
00096 outputIt.GoToBegin();
00097
00098 while(!tensorIt.IsAtEnd() && !outputIt.IsAtEnd()){
00099
00100 InputPixelType x = tensorIt.Get();
00101
00102
00103
00104
00105 typename InputPixelType::EigenValuesArrayType eigenvalues;
00106 typename InputPixelType::EigenVectorsMatrixType eigenvectors;
00107 x.ComputeEigenAnalysis(eigenvalues, eigenvectors);
00108
00109
00110
00111
00112
00113
00114
00115
00116 const float fa = x.GetFractionalAnisotropy();
00117 float r = fabs(eigenvectors(2,0)) * fa;
00118 float g = fabs(eigenvectors(2,1)) * fa;
00119 float b = fabs(eigenvectors(2,2)) * fa;
00120
00121 float a = fa;
00122
00123 __IMG_DAT_ITEM__CEIL_ZERO_ONE__(r);
00124 __IMG_DAT_ITEM__CEIL_ZERO_ONE__(g);
00125 __IMG_DAT_ITEM__CEIL_ZERO_ONE__(b);
00126 __IMG_DAT_ITEM__CEIL_ZERO_ONE__(a);
00127
00128 OutputPixelType out;
00129 out.SetRed( r * 255.0f);
00130 out.SetGreen( g * 255.0f);
00131 out.SetBlue( b * 255.0f);
00132 out.SetAlpha( a * 255.0f);
00133
00134 outputIt.Set(out);
00135
00136 ++tensorIt;
00137 ++outputIt;
00138 }
00139
00140 }
00141
00142 private:
00143 TensorToRgbImageFilter(const Self&);
00144 void operator=(const Self&);
00145 };
00146
00147
00148
00149 }
00150
00151 #endif