17 #ifndef __itkTensorToRgbImageFilter_h
18 #define __itkTensorToRgbImageFilter_h
20 #include "itkUnaryFunctorImageFilter.h"
21 #include "itkRGBAPixel.h"
22 #include "itkImageRegionConstIterator.h"
23 #include "itkImageRegionIterator.h"
28 #define __IMG_DAT_ITEM__CEIL_ZERO_ONE__(val) (val) = \
29 ( (val) < 0 ) ? ( 0 ) : ( ( (val)>1 ) ? ( 1 ) : ( (val) ) );
34 template <
typename TInputImage,
35 typename TOutputImage=itk::Image<itk::RGBAPixel<unsigned char>,3> >
37 public ImageToImageFilter<TInputImage,TOutputImage>
42 typedef ImageToImageFilter<TInputImage,TOutputImage>
57 itkFactorylessNewMacro(Self)
62 { this->Superclass::PrintSelf( os, indent ); }
64 #ifdef ITK_USE_CONCEPT_CHECKING
66 itkConceptMacro(InputHasNumericTraitsCheck,
67 (Concept::HasNumericTraits<InputValueType>));
78 typename InputImageType::Pointer tensorImage =
static_cast< InputImageType *
>( this->ProcessObject::GetInput(0) );
81 static_cast< OutputImageType *
>(this->ProcessObject::GetPrimaryOutput());
83 typename InputImageType::RegionType region = tensorImage->GetLargestPossibleRegion();
85 outputImage->SetSpacing( tensorImage->GetSpacing() );
86 outputImage->SetOrigin( tensorImage->GetOrigin() );
87 outputImage->SetDirection( tensorImage->GetDirection() );
88 outputImage->SetRegions( tensorImage->GetLargestPossibleRegion());
89 outputImage->Allocate();
91 typedef ImageRegionConstIterator< InputImageType > TensorImageIteratorType;
92 TensorImageIteratorType tensorIt(tensorImage, tensorImage->GetLargestPossibleRegion());
94 typedef ImageRegionIterator< OutputImageType > OutputImageIteratorType;
95 OutputImageIteratorType outputIt(outputImage, outputImage->GetLargestPossibleRegion());
100 while(!tensorIt.IsAtEnd() && !outputIt.IsAtEnd()){
102 InputPixelType x = tensorIt.Get();
107 typename InputPixelType::EigenValuesArrayType eigenvalues;
108 typename InputPixelType::EigenVectorsMatrixType eigenvectors;
109 x.ComputeEigenAnalysis(eigenvalues, eigenvectors);
118 const float fa = x.GetFractionalAnisotropy();
119 float r = fabs(eigenvectors(2,0)) * fa;
120 float g = fabs(eigenvectors(2,1)) * fa;
121 float b = fabs(eigenvectors(2,2)) * fa;
131 out.SetRed( r * 255.0f);
132 out.SetGreen( g * 255.0f);
133 out.SetBlue( b * 255.0f);
134 out.SetAlpha( a * 255.0f);
146 void operator=(
const Self&);
Superclass::OutputImageType OutputImageType
itk::SmartPointer< Self > Pointer
SmartPointer< const Self > ConstPointer
Superclass::InputImageType InputImageType
SmartPointer< Self > Pointer
virtual ~TensorToRgbImageFilter()
itk::Image< double, 3 > InputImageType
TensorToRgbImageFilter Self
ValueType
Type of the value held by a Value object.
void PrintSelf(std::ostream &os, Indent indent) const
TInputImage::PixelType InputPixelType
#define __IMG_DAT_ITEM__CEIL_ZERO_ONE__(val)
ImageToImageFilter< TInputImage, TOutputImage > Superclass
OutputImageType::PixelType OutputPixelType
InputPixelType::ValueType InputValueType