Orfeo Toolbox  4.0
otbPrintableImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12  Some parts of this code are derived from ITK. See ITKCopyright.txt
13  for details.
14 
15 
16  This software is distributed WITHOUT ANY WARRANTY; without even
17  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
18  PURPOSE. See the above copyright notices for more information.
19 
20 =========================================================================*/
21 #ifndef __otbPrintableImageFilter_txx
22 #define __otbPrintableImageFilter_txx
23 
25 
26 namespace otb
27 {
28 
29 template <class TInputImage, class TMaskImage>
32 {
33 
34  m_Rescaler = VectorRescalerType::New();
35  m_Extractor = ChannelExtractorType::New();
36 
37  m_Rescaler->SetInput(m_Extractor->GetOutput());
38  m_MaskFilter = FunctorFilterType::New();
39 
40  m_ChannelList = ChannelsType(3, 2);
41  m_ChannelList[1] = 3;
42  m_ChannelList[2] = 4;
43  m_ObjectColor.SetSize(3);
44  m_ObjectColor.Fill(255);
45  m_UseMask = false;
46  m_BackgroundMaskValue = 0;
47 }
48 
49 template <class TInputImage, class TMaskImage>
50 void
52 ::SetChannel(unsigned int channel)
53 {
54  m_ChannelList.push_back(channel);
55  m_Extractor->SetChannel(channel);
56  this->Modified();
57 }
58 
59 template <class TInputImage, class TMaskImage>
63 {
64  return m_ChannelList;
65 }
66 
67 template <class TInputImage, class TMaskImage>
68 void
71 {
72  this->itk::ProcessObject::SetNthInput(1, const_cast<MaskImageType *>(mask));
73  m_UseMask = true;
74 }
75 
76 template <class TInputImage, class TMaskImage>
80 {
81  if (this->GetNumberOfInputs() < 2)
82  {
83  return 0;
84  }
85  return static_cast<MaskImageType *>(this->itk::ProcessObject::GetInput(1));
86 }
87 
88 template <class TInputImage, class TMaskImage>
89 void
92 {
93  // Call to the superclass implementation
94  Superclass::GenerateOutputInformation();
95 
96  typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
97  outputPtr->SetNumberOfComponentsPerPixel(3);
98 }
99 
100 template <class TInputImage, class TMaskImage>
101 void
104 {
105  if (m_Extractor->GetNbChannels() == 0 && m_ChannelList.size() > 3)
106  {
107  itkExceptionMacro(<< "Invalid channel list (must be three channels instead of " << m_ChannelList.size());
108  }
109  if (m_Extractor->GetNbChannels() == 0 && m_Extractor->GetNbChannels() > 3)
110  {
111  itkExceptionMacro(<< "Invalid channel list (must be three channels instead of " << m_Extractor->GetNbChannels());
112  }
113  if (m_ObjectColor.GetSize() != 3)
114  {
115  itkExceptionMacro(<< "Invalid m_ObjectColor pixel size");
116  }
117 
118  if (m_UseMask == true)
119  {
120  MaskImagePointerType inputMaskPtr = this->GetInputMask();
121  typename InputImageType::ConstPointer inputPtr = this->GetInput();
122 
123  if (!inputMaskPtr)
124  {
125  itkExceptionMacro(<< "No mask detected");
126  }
127  if (inputMaskPtr->GetLargestPossibleRegion().GetSize() != inputPtr->GetLargestPossibleRegion().GetSize())
128  {
129  itkExceptionMacro(
130  << "Input size (" << inputPtr->GetLargestPossibleRegion().GetSize() << ") and Mask size (" <<
131  inputMaskPtr->GetLargestPossibleRegion().GetSize() << ") must be the same");
132  }
133  }
134 }
135 
136 /*
137  * If no mask used, just rescale the input between 0 and 255.
138  * Else, sur M%askFunctor.
139  */
140 template <class TInputImage, class TMaskImage>
141 void
144 {
145  this->BeforeGenerateData();
146 
147  // let this loop to be compliant with previous version of the class where m_ChannelList didn't exist...
148  if (m_Extractor->GetNbChannels() == 0)
149  {
150  for (unsigned int i = 0; i < m_ChannelList.size(); ++i)
151  m_Extractor->SetChannel(m_ChannelList[i]);
152  }
153 
154  m_Extractor->SetInput(this->GetInput());
155  m_Extractor->UpdateOutputInformation();
156 
157  typename TInputImage::PixelType minimum, maximum;
158  minimum.SetSize(m_Extractor->GetNbChannels());
159  maximum.SetSize(m_Extractor->GetNbChannels());
160  minimum.Fill(0);
161  maximum.Fill(255);
162 
163  m_Rescaler->SetOutputMinimum(minimum);
164  m_Rescaler->SetOutputMaximum(maximum);
165  m_Rescaler->SetClampThreshold(0.01);
166 
167  if (m_UseMask == false)
168  {
169  m_Rescaler->GraftOutput(this->GetOutput());
170  m_Rescaler->Update();
171  this->GraftOutput(m_Rescaler->GetOutput());
172  }
173  else
174  {
175  m_MaskFilter->SetInput1(m_Rescaler->GetOutput());
176  m_MaskFilter->SetInput2(this->GetInputMask());
177  m_MaskFilter->GraftOutput(this->GetOutput());
178  m_MaskFilter->Update();
179  this->GraftOutput(m_MaskFilter->GetOutput());
180  }
181 
182 }
183 
184 template <class TInputImage, class TMaskImage>
185 void
187 ::PrintSelf(std::ostream& os, itk::Indent indent) const
188 {
189  Superclass::PrintSelf(os, indent);
190 }
191 
192 } // end namespace otb
193 
194 #endif

Generated at Sat Mar 8 2014 16:13:37 for Orfeo Toolbox with doxygen 1.8.3.1