Skip to content
Snippets Groups Projects
Commit c8b6a10a authored by Julien Michel's avatar Julien Michel
Browse files

ENH: Added a filter to handle channel extraction otb::Image<itk::Vector<PixelType,N>>

parent a2cfed95
No related branches found
No related tags found
No related merge requests found
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbImageOfVectorsToMonoChannelExtractROI_h
#define __otbImageOfVectorsToMonoChannelExtractROI_h
#include "otbExtractROIBase.h"
#include "otbImage.h"
#include "otbVectorImage.h"
#include "itkMacro.h"
namespace otb
{
/** \class ImageOfVectorsToMonoChannelExtractROI
* \brief
* \todo Document this class
*/
template <class TInputImage, class TOutputImage>
class ITK_EXPORT ImageOfVectorsToMonoChannelExtractROI:
public ExtractROIBase< TInputImage , TOutputImage >
{
public:
/** Standard class typedefs. */
typedef ImageOfVectorsToMonoChannelExtractROI Self;
typedef ExtractROIBase< TInputImage , TOutputImage > Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(ImageOfVectorsToMonoChannelExtractROI, ExtractROIBase);
/** Image type information. */
typedef typename Superclass::InputImageType InputImageType;
typedef typename Superclass::OutputImageType OutputImageType;
/** Pixel type information */
typedef typename OutputImageType::ValueType OutputValueType;
/** Typedef to describe the output and input image region types. */
typedef typename OutputImageType::RegionType OutputImageRegionType;
typedef typename InputImageType::RegionType InputImageRegionType;
/** Typedef to describe the type of pixel. */
typedef typename OutputImageType::PixelType OutputImagePixelType;
typedef typename InputImageType::PixelType InputImagePixelType;
/** Typedef to describe the output and input image index and size types. */
typedef typename OutputImageType::IndexType OutputImageIndexType;
typedef typename InputImageType::IndexType InputImageIndexType;
typedef typename OutputImageType::SizeType OutputImageSizeType;
typedef typename InputImageType::SizeType InputImageSizeType;
/** Selectionne le canal a traiter */
itkSetMacro(Channel,unsigned int);
itkGetConstMacro(Channel,unsigned int);
/** ImageDimension enumeration */
itkStaticConstMacro(InputImageDimension, unsigned int,
InputImageType::ImageDimension);
itkStaticConstMacro(OutputImageDimension, unsigned int,
OutputImageType::ImageDimension);
protected:
ImageOfVectorsToMonoChannelExtractROI();
~ImageOfVectorsToMonoChannelExtractROI() {};
void PrintSelf(std::ostream& os, itk::Indent indent) const;
/** ExtractImageFilter can produce an image which is a different
* resolution than its input image. As such, ExtractImageFilter
* needs to provide an implementation for
* GenerateOutputInformation() in order to inform the pipeline
* execution model. The original documentation of this method is
* below.
*
* \sa ProcessObject::GenerateOutputInformaton() */
virtual void GenerateOutputInformation();
/** ExtractImageFilter can be implemented as a multithreaded filter.
* \sa ImageToImageFilter::ThreadedGenerateData(),
* ImageToImageFilter::GenerateData() */
void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
int threadId );
private:
ImageOfVectorsToMonoChannelExtractROI(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
/** Channel to process [1...] */
unsigned int m_Channel;
};
} // end namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbImageOfVectorsToMonoChannelExtractROI.txx"
#endif
#endif
/*=========================================================================
Program: ORFEO Toolbox
Language: C++
Date: $Date$
Version: $Revision$
Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
See OTBCopyright.txt for details.
This software is distributed WITHOUT ANY WARRANTY; without even
the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE. See the above copyright notices for more information.
=========================================================================*/
#ifndef __otbMultiToMonoChannelExtractROI_txx
#define __otbMultiToMonoChannelExtractROI_txx
#include "otbMultiToMonoChannelExtractROI.h"
namespace otb
{
/**
*
*/
template<class TInputImage, class TOutputImage>
MultiToMonoChannelExtractROI<TInputImage,TOutputImage>
::MultiToMonoChannelExtractROI() : ExtractROIBase< VectorImage<TInputImage,2> , Image<TOutputImage,2> >(),
m_Channel(1)
{
}
/**
*
*/
template<class TInputImage, class TOutputImage>
void
MultiToMonoChannelExtractROI<TInputImage,TOutputImage>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os,indent);
}
/**
* ExtractImageFilter can produce an image which is a different resolution
* than its input image. As such, ExtractImageFilter needs to provide an
* implementation for GenerateOutputInformation() in order to inform
* the pipeline execution model. The original documentation of this
* method is below.
*
* \sa ProcessObject::GenerateOutputInformaton()
*/
template<class TInputImage, class TOutputImage>
void
MultiToMonoChannelExtractROI<TInputImage,TOutputImage>
::GenerateOutputInformation()
{
typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
// Analyse du canal trait
if ( (m_Channel <= 0) || (m_Channel > InputImagePixelType::Dimension ) )
{
itkExceptionMacro(<< "otb::ExtractImMultiToMonoChannelExtractROIageFilter::GenerateOutputInformation "
<< " Channel must be in the following range: [1;"<< InputImagePixelType::Dimension <<"] "
<< typeid(itk::ImageBase<InputImageDimension>*).name() );
}
// Appel la methode de la classe de base
Superclass::GenerateOutputInformation();
}
template<class TInputImage, class TOutputImage>
void
MultiToMonoChannelExtractROI<TInputImage,TOutputImage>
::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
int threadId)
{
itkDebugMacro(<<"Actually executing");
// Get the input and output pointers
typename Superclass::InputImageConstPointer inputPtr = this->GetInput();
typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
// support progress methods/callbacks
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
// Define the portion of the input to walk for this thread
InputImageRegionType inputRegionForThread;
this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
// Define the iterators.
typedef itk::ImageRegionIterator<OutputImageType> OutputIterator;
typedef itk::ImageRegionConstIterator<InputImageType> InputIterator;
OutputIterator outIt(outputPtr, outputRegionForThread);
InputIterator inIt(inputPtr, inputRegionForThread);
// Parcours des canaux a traiter
unsigned int channelIn(m_Channel-1);
InputImagePixelType pixelInput;
while( !outIt.IsAtEnd() )
{
OutputImagePixelType pixelOutput;
pixelInput = inIt.Get();
pixelOutput = static_cast<OutputValueType>(pixelInput[channelIn]);
outIt.Set( pixelOutput );
++outIt;
++inIt;
progress.CompletedPixel();
}
}
} // end namespace otb
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment