Skip to content
Snippets Groups Projects
Commit f219063a authored by Emmanuel Christophe's avatar Emmanuel Christophe
Browse files

Code for VectorImageToIntensityImageFilter

parent ce211098
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 _otbVectorImageToIntensityImageFilter_h
#define _otbVectorImageToIntensityImageFilter_h
#include "itkImageToImageFilter.h"
namespace otb
{
/** \class VectorImageToIntensityImageFilter
* \brief This filter implements the computation of the mean of the spectral values of each pixel.
*
* The spectral mean
* is defined as:
*
* \f[SM = \frac{1}{n_{b}} \times {\sum_{b=1}^{n_{b}}p(b) \f]
* with \f$b\f$ being the spectral band and \f$p\f$
* the current pixel.
*
* Since the spectral mean deals with multi-bands image, the InputImage pixels are suposed to
* support the [] operator, and the input image to support the GetNumberOfComponentsPerPixel() method.
*
* \sa VectorImage
*
* This filter is implemented as a multithreaded filter.
*
* \ingroup IntensityImageFilters
* \ingroup Threading
* \ingroup Streamed
*/
template <class TInputImage,class TOutputImage>
class ITK_EXPORT VectorImageToIntensityImageFilter
: public itk::ImageToImageFilter<TInputImage,TOutputImage>
{
public:
/** Standard typedefs */
typedef VectorImageToIntensityImageFilter Self;
typedef itk::ImageToImageFilter<TInputImage,TOutputImage> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Type macro */
itkNewMacro(Self);
/** Creation through object factory macro */
itkTypeMacro(VectorImageToIntensityImageFilter,itk::ImageToImageFilter);
/** Template parameters typedefs */
typedef TInputImage InputImageType;
typedef typename InputImageType::ConstPointer InputImageConstPointerType;
typedef typename InputImageType::RegionType InputImageRegionType;
typedef typename InputImageType::PixelType InputPixelType;
typedef TOutputImage OutputImageType;
typedef typename OutputImageType::Pointer OutputImagePointerType;
typedef typename OutputImageType::RegionType OutputImageRegionType;
typedef typename OutputImageType::PixelType OutputPixelType;
protected:
/** Constructor */
VectorImageToIntensityImageFilter();
/** Destructor */
virtual ~VectorImageToIntensityImageFilter() {};
/**PrintSelf method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
/** VectorImageToIntensityImageFilter can be implemented as a multithreaded filter.
* Therefore, this implementation provides a ThreadedGenerateData() routine
* which is called for each processing thread. The output image data is
* allocated automatically by the superclass prior to calling
* ThreadedGenerateData(). ThreadedGenerateData can only write to the
* portion of the output image specified by the parameter
* "outputRegionForThread"
*
* \sa ImageToImageFilter::ThreadedGenerateData(),
* ImageToImageFilter::GenerateData() */
void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
int threadId );
private:
VectorImageToIntensityImageFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
};
}// End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbVectorImageToIntensityImageFilter.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 _otbVectorImageToIntensityImageFilter_txx
#define _otbVectorImageToIntensityImageFilter_txx
#include "otbVectorImageToIntensityImageFilter.h"
#include "itkImageRegionIterator.h"
#include "itkImageRegionConstIterator.h"
#include "itkProgressReporter.h"
#include "otbMacro.h"
#include "otbMath.h"
namespace otb
{
/**
* Constructor
*/
template <class TInputImage, class TOutputImage>
VectorImageToIntensityImageFilter<TInputImage,TOutputImage>
::VectorImageToIntensityImageFilter()
{
}
template <class TInputImage, class TOutputImage>
void
VectorImageToIntensityImageFilter<TInputImage,TOutputImage>
::ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,int threadId)
{
InputImageConstPointerType inputPtr = this->GetInput();
OutputImagePointerType outputPtr = this->GetOutput();
// Define the portion of the input to walk for this thread, using
// the CallCopyOutputRegionToInputRegion method allows for the input
// and output images to be different dimensions
InputImageRegionType inputRegionForThread;
this->CallCopyOutputRegionToInputRegion(inputRegionForThread, outputRegionForThread);
// Define the iterators
itk::ImageRegionConstIterator<InputImageType> inputIt(inputPtr, inputRegionForThread);
itk::ImageRegionIterator<OutputImageType> outputIt(outputPtr, outputRegionForThread);
itk::ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
inputIt.GoToBegin();
outputIt.GoToBegin();
while(!inputIt.IsAtEnd() && !outputIt.IsAtEnd())
{
double sum=0.0;
InputPixelType pixel = inputIt.Get();
for (unsigned int i=0; i<pixel.Size(); i++)
{
sum += pixel[i];
}
sum /= pixel.Size() ;
outputIt.Set(static_cast<OutputPixelType>(sum));
++inputIt;
++outputIt;
progress.CompletedPixel(); // potential exception thrown here
}
}
/**
* PrintSelf Method
*/
template <class TInputImage, class TOutputImage>
void
VectorImageToIntensityImageFilter<TInputImage,TOutputImage>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
} // 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