21 #ifndef otbMultiChannelExtractROI_hxx
22 #define otbMultiChannelExtractROI_hxx
26 #include "itkImageRegionIterator.h"
27 #include "itkObjectFactory.h"
28 #include "itkExtractImageFilterRegionCopier.h"
36 template <
class TInputPixelType,
class TOutputPixelType>
41 this->DynamicMultiThreadingOn();
48 template <
class TInputPixelType,
class TOutputPixelType>
51 if (m_ChannelsKind == 1)
53 itkExceptionMacro(<<
"m_Channels already set using channels interval.");
55 m_Channels.push_back(channel);
56 if (m_ChannelsKind == 0)
64 template <
class TInputPixelType,
class TOutputPixelType>
67 if (m_ChannelsKind == 2)
69 itkExceptionMacro(<<
"m_Channels already set using SetChannels method.");
72 if (m_ChannelsKind == 0)
79 template <
class TInputPixelType,
class TOutputPixelType>
82 if (m_ChannelsKind == 2)
84 itkExceptionMacro(<<
"m_Channels already set using SetChannels method.");
87 if (m_ChannelsKind == 0)
97 template <
class TInputPixelType,
class TOutputPixelType>
104 m_ChannelsWorks.clear();
111 template <
class TInputPixelType,
class TOutputPixelType>
114 Superclass::PrintSelf(os, indent);
117 template <
class TInputPixelType,
class TOutputPixelType>
121 m_ChannelsWorks.clear();
123 if (m_Channels.empty() ==
true)
126 if (m_ChannelsKind == 1)
128 this->SetChannelsWorkWithLimits();
133 if (m_Channels.empty() ==
true && m_ChannelsKind == 2)
135 m_ChannelsWorks = m_Channels;
143 if (m_ChannelsKind == 1)
146 this->SetChannelsWorkWithLimits();
151 if (m_ChannelsKind == 2)
153 m_ChannelsWorks = m_Channels;
159 template <
class TInputPixelType,
class TOutputPixelType>
162 if ((m_FirstChannel == 0) || (m_LastChannel == 0))
164 itkExceptionMacro(<<
"otb::ExtractImageFilter::GenerateOutputInformation "
165 <<
"Channels must reside into [1...] " <<
typeid(itk::ImageBase<InputImageDimension>*).name());
167 if (m_FirstChannel > m_LastChannel)
169 itkExceptionMacro(<<
"otb::ExtractImageFilter::GenerateOutputInformation "
170 <<
"FirstChannel is greater than LastChannel" <<
typeid(itk::ImageBase<InputImageDimension>*).name());
173 for (
unsigned int channel = m_FirstChannel; channel <= m_LastChannel; channel++)
175 m_ChannelsWorks.push_back(channel);
178 m_Channels = m_ChannelsWorks;
190 template <
class TInputPixelType,
class TOutputPixelType>
194 Superclass::GenerateOutputInformation();
195 this->ChannelsReInitialization();
198 typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
199 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
201 unsigned int nbComponentsPerPixel = inputPtr->GetNumberOfComponentsPerPixel();
202 if (m_ChannelsKind != 0)
206 m_BadChannels.clear();
207 for (
unsigned int i = 0; i < m_ChannelsWorks.size(); ++i)
209 if ((m_ChannelsWorks[i] < 1) || (m_ChannelsWorks[i] > nbComponentsPerPixel))
211 bool isInsideBadChannels =
false;
212 for (
unsigned int j = 0; j < m_BadChannels.size(); ++j)
214 if (m_BadChannels[j] == m_ChannelsWorks[i])
215 isInsideBadChannels =
true;
217 if (!isInsideBadChannels)
218 m_BadChannels.push_back(m_ChannelsWorks[i]);
221 if (m_BadChannels.empty() ==
false)
223 std::ostringstream oss;
224 oss <<
"otb::ExtractImageFilter::GenerateOutputInformation : ";
225 oss <<
"Channel(s) [ ";
226 for (
unsigned int i = 0; i < m_BadChannels.size(); ++i)
228 oss << m_BadChannels[i] <<
" ";
230 oss <<
"] not authorized.";
231 oss <<
" Each channel index has to be in [1," << nbComponentsPerPixel <<
"].";
232 itkExceptionMacro(<< oss.str().c_str());
234 nbComponentsPerPixel = m_ChannelsWorks.size();
238 outputPtr->SetNumberOfComponentsPerPixel(nbComponentsPerPixel);
241 template <
class TInputPixelType,
class TOutputPixelType>
244 itkDebugMacro(<<
"Actually executing");
246 typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
247 typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
251 this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
254 typedef itk::ImageRegionIterator<OutputImageType> OutputIterator;
255 typedef itk::ImageRegionConstIterator<InputImageType> InputIterator;
257 OutputIterator outIt(outputPtr, outputRegionForThread);
258 InputIterator inIt(inputPtr, inputRegionForThread);
264 if (m_ChannelsKind == 0)
267 while (!outIt.IsAtEnd())
269 outIt.Set(inIt.Get());
278 unsigned int channelIn(0);
279 unsigned int channelOut(0);
280 unsigned int nbChannels(0);
283 while (!outIt.IsAtEnd())
286 pixelOutput.Reserve(outputPtr->GetVectorLength());
287 pixelInput = inIt.Get();
289 for (nbChannels = 0; nbChannels < m_ChannelsWorks.size(); ++nbChannels)
291 channelIn = m_ChannelsWorks[nbChannels] - 1;
292 pixelOutput[channelOut] =
static_cast<OutputValueType>(pixelInput[channelIn]);
295 outIt.Set(pixelOutput);
Creation of an "otb" vector image which contains metadata.
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.