Orfeo Toolbox  3.16
itkScalarToRGBColormapImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkScalarToRGBColormapImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-05-15 12:51:14 $
7  Version: $Revision: 1.2 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkScalarToRGBColormapImageFilter_txx
18 #define __itkScalarToRGBColormapImageFilter_txx
19 
21 
22 #include "itkImageRegionIterator.h"
24 #include "itkProgressReporter.h"
25 
26 #include "itkRedColormapFunctor.h"
28 #include "itkBlueColormapFunctor.h"
29 #include "itkGreyColormapFunctor.h"
30 #include "itkHotColormapFunctor.h"
31 #include "itkCoolColormapFunctor.h"
37 #include "itkHSVColormapFunctor.h"
38 #include "itkJetColormapFunctor.h"
40 
41 namespace itk
42 {
43 
47 template <class TInputImage, class TOutputImage>
50 {
51  this->SetNumberOfRequiredInputs( 1 );
52 
53  this->m_UseInputImageExtremaForScaling = true;
54 
56  InputImagePixelType, OutputImagePixelType> DefaultColormapType;
57 
58  typename DefaultColormapType::Pointer greyColormap = DefaultColormapType::New();
59  this->SetColormap( greyColormap );
60 }
61 
65 template <class TInputImage, class TOutputImage>
66 void
69 {
70  if( this->m_UseInputImageExtremaForScaling == true )
71  {
72  ImageRegionConstIterator<InputImageType> It( this->GetInput(),
73  this->GetInput()->GetRequestedRegion() );
74 
75  InputImagePixelType minimumValue = NumericTraits<InputImagePixelType>::max();
76  InputImagePixelType maximumValue = NumericTraits<InputImagePixelType>::min();
77 
78  for( It.GoToBegin(); !It.IsAtEnd(); ++It )
79  {
80  InputImagePixelType value = It.Get();
81  if( value < minimumValue )
82  {
83  minimumValue = value;
84  }
85  if( value > maximumValue )
86  {
87  maximumValue = value;
88  }
89  }
90 
91  this->GetColormap()->SetMinimumInputValue( minimumValue );
92  this->GetColormap()->SetMaximumInputValue( maximumValue );
93  }
94 }
95 
99 template <class TInputImage, class TOutputImage>
100 void
102 ::ThreadedGenerateData( const OutputImageRegionType &outputRegionForThread,
103  int threadId )
104 {
105  InputImagePointer inputPtr = this->GetInput();
106  OutputImagePointer outputPtr = this->GetOutput();
107 
108  // Define the portion of the input to walk for this thread, using
109  // the CallCopyOutputRegionToInputRegion method allows for the input
110  // and output images to be different dimensions
111  InputImageRegionType inputRegionForThread;
112  this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
113 
114  // Define the iterators
115  ImageRegionConstIterator<TInputImage> inputIt(inputPtr, inputRegionForThread);
116  ImageRegionIterator<TOutputImage> outputIt(outputPtr, outputRegionForThread);
117 
118  ProgressReporter progress( this, threadId, outputRegionForThread.GetNumberOfPixels());
119 
120  inputIt.GoToBegin();
121  outputIt.GoToBegin();
122 
123  while( !inputIt.IsAtEnd() )
124  {
125  outputIt.Set( this->m_Colormap->operator()( inputIt.Get() ) );
126  ++inputIt;
127  ++outputIt;
128  progress.CompletedPixel(); // potential exception thrown here
129  }
130 }
131 
132 template <class TInputImage, class TOutputImage>
133 void
136 {
137  switch( map )
138  {
139  case Red:
140  {
142  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
143  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
144  this->SetColormap( colormap );
145  break;
146  }
147  case Green:
148  {
150  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
151  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
152  this->SetColormap( colormap );
153  break;
154  }
155  case Blue:
156  {
158  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
159  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
160  this->SetColormap( colormap );
161  break;
162  }
163  case Grey: default:
164  {
166  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
167  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
168  this->SetColormap( colormap );
169  break;
170  }
171  case Hot:
172  {
174  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
175  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
176  this->SetColormap( colormap );
177  break;
178  }
179  case Cool:
180  {
182  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
183  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
184  this->SetColormap( colormap );
185  break;
186  }
187  case Spring:
188  {
190  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
191  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
192  this->SetColormap( colormap );
193  break;
194  }
195  case Summer:
196  {
198  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
199  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
200  this->SetColormap( colormap );
201  break;
202  }
203  case Autumn:
204  {
206  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
207  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
208  this->SetColormap( colormap );
209  break;
210  }
211  case Winter:
212  {
214  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
215  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
216  this->SetColormap( colormap );
217  break;
218  }
219  case Copper:
220  {
222  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
223  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
224  this->SetColormap( colormap );
225  break;
226  }
227  case Jet:
228  {
230  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
231  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
232  this->SetColormap( colormap );
233  break;
234  }
235  case HSV:
236  {
238  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
239  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
240  this->SetColormap( colormap );
241  break;
242  }
243  case OverUnder:
244  {
246  InputImagePixelType, OutputImagePixelType> SpecificColormapType;
247  typename SpecificColormapType::Pointer colormap = SpecificColormapType::New();
248  this->SetColormap( colormap );
249  break;
250  }
251  }
252 
253 }
254 
255 template <class TInputImage, class TOutputImage>
256 void
258 ::PrintSelf( std::ostream& os, Indent indent ) const
259 {
260  this->Superclass::PrintSelf(os, indent);
261  os << indent << "Class Name: " << this->GetNameOfClass( ) << std::endl;
262  if( this->m_Colormap.IsNotNull() )
263  {
264  os << indent << "Colormap " << this->m_Colormap << std::endl;
265  }
266  else
267  {
268  os << indent << "Colormap is NULL " << std::endl;
269  }
270  os << indent << "Use Input Image Extrema for Scaling " << this->m_UseInputImageExtremaForScaling << std::endl;
271 }
272 
273 } // end namespace itk
274 
275 #endif

Generated at Sun Feb 3 2013 00:05:02 for Orfeo Toolbox with doxygen 1.8.1.1