22 #ifndef otbPrintableImageFilter_hxx
23 #define otbPrintableImageFilter_hxx
30 template <
class TInputImage,
class TMaskImage>
34 m_Rescaler = VectorRescalerType::New();
35 m_Extractor = ChannelExtractorType::New();
37 m_Rescaler->SetInput(m_Extractor->GetOutput());
38 m_MaskFilter = FunctorFilterType::New();
43 m_ObjectColor.SetSize(3);
44 m_ObjectColor.Fill(255);
46 m_BackgroundMaskValue = 0;
49 template <
class TInputImage,
class TMaskImage>
52 m_ChannelList.push_back(channel);
53 m_Extractor->SetChannel(channel);
57 template <
class TInputImage,
class TMaskImage>
63 template <
class TInputImage,
class TMaskImage>
66 this->itk::ProcessObject::SetNthInput(1,
const_cast<MaskImageType*
>(mask));
70 template <
class TInputImage,
class TMaskImage>
73 if (this->GetNumberOfInputs() < 2)
77 return static_cast<MaskImageType*
>(this->itk::ProcessObject::GetInput(1));
80 template <
class TInputImage,
class TMaskImage>
84 Superclass::GenerateOutputInformation();
86 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
87 outputPtr->SetNumberOfComponentsPerPixel(3);
90 template <
class TInputImage,
class TMaskImage>
93 if (m_Extractor->GetNbChannels() == 0 && m_ChannelList.size() > 3)
95 itkExceptionMacro(<<
"Invalid channel list (must be three channels instead of " << m_ChannelList.size());
97 if (m_Extractor->GetNbChannels() == 0 && m_Extractor->GetNbChannels() > 3)
99 itkExceptionMacro(<<
"Invalid channel list (must be three channels instead of " << m_Extractor->GetNbChannels());
101 if (m_ObjectColor.GetSize() != 3)
103 itkExceptionMacro(<<
"Invalid m_ObjectColor pixel size");
106 if (m_UseMask ==
true)
109 typename InputImageType::ConstPointer inputPtr = this->GetInput();
113 itkExceptionMacro(<<
"No mask detected");
115 if (inputMaskPtr->GetLargestPossibleRegion().GetSize() != inputPtr->GetLargestPossibleRegion().GetSize())
117 itkExceptionMacro(<<
"Input size (" << inputPtr->GetLargestPossibleRegion().GetSize() <<
") and Mask size ("
118 << inputMaskPtr->GetLargestPossibleRegion().GetSize() <<
") must be the same");
127 template <
class TInputImage,
class TMaskImage>
130 this->BeforeGenerateData();
133 if (m_Extractor->GetNbChannels() == 0)
135 for (
unsigned int i = 0; i < m_ChannelList.size(); ++i)
136 m_Extractor->SetChannel(m_ChannelList[i]);
139 m_Extractor->SetInput(this->GetInput());
140 m_Extractor->UpdateOutputInformation();
142 typename TInputImage::PixelType minimum, maximum;
143 minimum.SetSize(m_Extractor->GetNbChannels());
144 maximum.SetSize(m_Extractor->GetNbChannels());
148 m_Rescaler->SetOutputMinimum(minimum);
149 m_Rescaler->SetOutputMaximum(maximum);
150 m_Rescaler->SetClampThreshold(0.01);
152 if (m_UseMask ==
false)
154 m_Rescaler->GraftOutput(this->GetOutput());
155 m_Rescaler->Update();
156 this->GraftOutput(m_Rescaler->GetOutput());
160 m_MaskFilter->SetInput1(m_Rescaler->GetOutput());
161 m_MaskFilter->SetInput2(this->GetInputMask());
162 m_MaskFilter->GraftOutput(this->GetOutput());
163 m_MaskFilter->Update();
164 this->GraftOutput(m_MaskFilter->GetOutput());
168 template <
class TInputImage,
class TMaskImage>
171 Superclass::PrintSelf(os, indent);