Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
itkTensorToRgbImageFilter.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef __itkTensorToRgbImageFilter_h
18 #define __itkTensorToRgbImageFilter_h
19 
20 #include "itkUnaryFunctorImageFilter.h"
21 #include "itkRGBAPixel.h"
22 #include "itkImageRegionConstIterator.h"
23 #include "itkImageRegionIterator.h"
24 
25 namespace itk
26 {
27 
28 #define __IMG_DAT_ITEM__CEIL_ZERO_ONE__(val) (val) = \
29  ( (val) < 0 ) ? ( 0 ) : ( ( (val)>1 ) ? ( 1 ) : ( (val) ) );
30 
34  template <typename TInputImage,
35  typename TOutputImage=itk::Image<itk::RGBAPixel<unsigned char>,3> >
37  public ImageToImageFilter<TInputImage,TOutputImage>
38  {
39  public:
42  typedef ImageToImageFilter<TInputImage,TOutputImage>
46 
48  typedef typename Superclass::OutputImageType OutputImageType;
52 
54  itkTypeMacro( TensorToRgbImageFilter, ImageToImageFilter );
55 
57  itkFactorylessNewMacro(Self)
58  itkCloneMacro(Self)
59 
61  void PrintSelf(std::ostream& os, Indent indent) const
62  { this->Superclass::PrintSelf( os, indent ); }
63 
64 #ifdef ITK_USE_CONCEPT_CHECKING
65 
66  itkConceptMacro(InputHasNumericTraitsCheck,
67  (Concept::HasNumericTraits<InputValueType>));
69 #endif
70 
71 protected:
74 
75  void GenerateData()
76  {
77 
78  typename InputImageType::Pointer tensorImage = static_cast< InputImageType * >( this->ProcessObject::GetInput(0) );
79 
80  typename OutputImageType::Pointer outputImage =
81  static_cast< OutputImageType * >(this->ProcessObject::GetPrimaryOutput());
82 
83  typename InputImageType::RegionType region = tensorImage->GetLargestPossibleRegion();
84 
85  outputImage->SetSpacing( tensorImage->GetSpacing() ); // Set the image spacing
86  outputImage->SetOrigin( tensorImage->GetOrigin() ); // Set the image origin
87  outputImage->SetDirection( tensorImage->GetDirection() ); // Set the image direction
88  outputImage->SetRegions( tensorImage->GetLargestPossibleRegion());
89  outputImage->Allocate();
90 
91  typedef ImageRegionConstIterator< InputImageType > TensorImageIteratorType;
92  TensorImageIteratorType tensorIt(tensorImage, tensorImage->GetLargestPossibleRegion());
93 
94  typedef ImageRegionIterator< OutputImageType > OutputImageIteratorType;
95  OutputImageIteratorType outputIt(outputImage, outputImage->GetLargestPossibleRegion());
96 
97  tensorIt.GoToBegin();
98  outputIt.GoToBegin();
99 
100  while(!tensorIt.IsAtEnd() && !outputIt.IsAtEnd()){
101 
102  InputPixelType x = tensorIt.Get();
103 
104  // eigenvalues are sorted in ascending order by default because the
105  // itk::SymmetricEigenAnalysis defaults are not touched in the tensor implementation
106 
107  typename InputPixelType::EigenValuesArrayType eigenvalues;
108  typename InputPixelType::EigenVectorsMatrixType eigenvectors;
109  x.ComputeEigenAnalysis(eigenvalues, eigenvectors);
110 
111  // int index = 2;
112  // if( (eigenvalues[0] >= eigenvalues[1])
113  // && (eigenvalues[0] >= eigenvalues[2]) )
114  // index = 0;
115  // else if(eigenvalues[1] >= eigenvalues[2])
116  // index = 1;
117 
118  const float fa = x.GetFractionalAnisotropy();
119  float r = fabs(eigenvectors(2/*index*/,0)) * fa;
120  float g = fabs(eigenvectors(2/*index*/,1)) * fa;
121  float b = fabs(eigenvectors(2/*index*/,2)) * fa;
122 // float a = (fa-(m_OpacLevel-m_OpacWindow/2.0f))/m_OpacWindow;
123  float a = fa;
124 
129 
130  OutputPixelType out;
131  out.SetRed( r * 255.0f);
132  out.SetGreen( g * 255.0f);
133  out.SetBlue( b * 255.0f);
134  out.SetAlpha( a * 255.0f);
135 
136  outputIt.Set(out);
137 
138  ++tensorIt;
139  ++outputIt;
140  }
141 
142  }
143 
144  private:
145  TensorToRgbImageFilter(const Self&); //purposely not implemented
146  void operator=(const Self&); //purposely not implemented
147  };
148 
149 
150 
151 } // end namespace itk
152 
153 #endif
Superclass::OutputImageType OutputImageType
itk::SmartPointer< Self > Pointer
STL namespace.
SmartPointer< const Self > ConstPointer
Superclass::InputImageType InputImageType
itk::Image< double, 3 > InputImageType
ValueType
Type of the value held by a Value object.
Definition: jsoncpp.h:345
void PrintSelf(std::ostream &os, Indent indent) const
TInputImage::PixelType InputPixelType
#define __IMG_DAT_ITEM__CEIL_ZERO_ONE__(val)
ImageToImageFilter< TInputImage, TOutputImage > Superclass
unsigned short PixelType
OutputImageType::PixelType OutputPixelType
InputPixelType::ValueType InputValueType