Commit f6994514 authored by Julien Michel's avatar Julien Michel
Browse files

Ajout du filtre d'application d'un filtre à chacune des images d'une liste d'image.

parent cb4917fe
/*=========================================================================
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 _otbImageListToImageListApplyFilter_h
#define _otbImageListToImageListApplyFilter_h
#include "otbImageListToImageListFilter.h"
namespace otb
{
/** \class ImageListToImageListApplyFilter
* \brief
*
* \ingroup
* \ingroup
*/
template <class TInputImageList, class TOutputImageList, class TFilter>
class ITK_EXPORT ImageListToImageListApplyFilter
: public ImageListToImageListFilter<typename TInputImageList::ImageType,
typename TOutputImageList::ImageType>
{
public:
/** Standard typedefs */
typedef ImageListToImageListApplyFilter Self;
typedef ImageListToImageListFilter<typename TInputImageList::ImageType,
typename TOutputImageList::ImageType> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Type macro */
itkNewMacro(Self);
/** Creation through object factory macro */
itkTypeMacro(ImageListToImageListApplyFilter, ImageListToImageListFilter);
/** Template parameters typedefs */
typedef TInputImageList InputImageListType;
typedef typename InputImageListType::ConstPointer InputImageListConstPointerType;
typedef typename InputImageListType::ImageType InputImageType;
typedef TOutputImageList OutputImageListType;
typedef typename OutputImageListType::Pointer OutputImageListPointerType;
typedef typename OutputImageListType::ImageType OutputImageType;
typedef TFilter FilterType;
typedef typename FilterType::Pointer FilterPointerType;
/** Accessors */
itkSetObjectMacro(Filter,FilterType);
itkGetObjectMacro(Filter,FilterType);
itkGetMacro(OutputIndex,unsigned int);
itkSetMacro(OutputIndex,unsigned int);
/** Generate output information for the ImageList and for each image
in the list. */
virtual void GenerateOutputInformation(void);
/** Generate input requested region for each image in the list. */
virtual void GenerateInputRequestedRegion(void);
protected:
/** Main computation method */
virtual void GenerateData(void);
/** Constructor */
ImageListToImageListApplyFilter();
/** Destructor */
virtual ~ImageListToImageListApplyFilter() {};
/**PrintSelf method */
virtual void PrintSelf(std::ostream& os, itk::Indent indent) const;
private:
ImageListToImageListApplyFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
/** The processing filter */
FilterPointerType m_Filter;
/** The index of the output of the filter to use */
unsigned int m_OutputIndex;
};
}// End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
#include "otbImageListToImageListApplyFilter.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 _otbImageListToImageListApplyFilter_txx
#define _otbImageListToImageListApplyFilter_txx
#include "otbImageListToImageListApplyFilter.h"
namespace otb
{
/**
* Constructor
*/
template <class TInputImageList, class TOutputImageList, class TFilter>
ImageListToImageListApplyFilter<TInputImageList,TOutputImageList,TFilter>
::ImageListToImageListApplyFilter()
{
m_Filter = FilterType::New();
m_OutputIndex=0;
}
/** Generate output information for the ImageList and for each image
in the List. */
template <class TInputImageList, class TOutputImageList, class TFilter>
void
ImageListToImageListApplyFilter<TInputImageList,TOutputImageList,TFilter>
::GenerateOutputInformation()
{
// Retrieving input/output pointers
InputImageListConstPointerType inputPtr = this->GetInput();
OutputImageListPointerType outputPtr = this->GetOutput();
if(outputPtr)
{
// For each input image
typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
while(inputListIt!=inputPtr->End())
{
// Create the output image and set its information
outputPtr->PushBack(OutputImageType::New());
m_Filter->SetInput(inputListIt.Get());
m_Filter->UpdateOutputInformation();
outputPtr->Back()->CopyInformation(m_Filter->GetOutput(m_OutputIndex));
outputPtr->Back()->SetRegions(m_Filter->GetOutput(m_OutputIndex)->GetLargestPossibleRegion());
++inputListIt;
}
}
}
/** Generate input requested region for each image in the List. */
template <class TInputImageList, class TOutputImageList, class TFilter>
void
ImageListToImageListApplyFilter<TInputImageList,TOutputImageList,TFilter>
::GenerateInputRequestedRegion()
{
// Retrieving input/output pointers
InputImageListConstPointerType inputPtr = this->GetInput();
OutputImageListPointerType outputPtr = this->GetOutput();
// For each input image and corresponding output image
typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
typename OutputImageListType::Iterator outputListIt = outputPtr->Begin();
// Use the filter to generate input requested region
while(inputListIt!=inputPtr->End()&&outputListIt!=outputPtr->End())
{
m_Filter->SetInput(inputListIt.Get());
m_Filter->GetOutput(m_OutputIndex)->SetRequestedRegion(outputListIt.Get()->GetRequestedRegion());
m_Filter->GenerateInputRequestedRegion();
++inputListIt;
++outputListIt;
}
}
/** Main computation method */
template <class TInputImageList, class TOutputImageList, class TFilter>
void
ImageListToImageListApplyFilter<TInputImageList,TOutputImageList,TFilter>
::GenerateData()
{
// Retrieving input/output pointers
InputImageListConstPointerType inputPtr = this->GetInput();
OutputImageListPointerType outputPtr = this->GetOutput();
// For each input image and corresponding output image
typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
typename OutputImageListType::Iterator outputListIt = outputPtr->Begin();
unsigned int counter = 0;
while(inputListIt!=inputPtr->End()&&outputListIt!=outputPtr->End())
{
m_Filter->SetInput(inputListIt.Get());
m_Filter->GetOutput(m_OutputIndex)->SetRequestedRegion(outputListIt.Get()->GetRequestedRegion());
m_Filter->Update();
outputPtr->SetNthElement(counter,m_Filter->GetOutput(m_OutputIndex));
outputListIt.Get()->DisconnectPipeline();
++inputListIt;
++outputListIt;
++counter;
}
}
/**
* PrintSelf Method
*/
template <class TInputImageList, class TOutputImageList, class TFilter>
void
ImageListToImageListApplyFilter<TInputImageList,TOutputImageList,TFilter>
::PrintSelf(std::ostream& os, itk::Indent indent) const
{
Superclass::PrintSelf(os, indent);
}
} // End namespace otb
#endif
......@@ -81,7 +81,10 @@ ImageList<TImage>
Superclass::UpdateOutputInformation();
for(ConstIterator it = this->Begin(); it!=this->End();++it)
{
it.Get()->GetSource()->UpdateOutputInformation();
if(it.Get()->GetSource())
{
it.Get()->GetSource()->UpdateOutputInformation();
}
}
}
......
......@@ -273,26 +273,26 @@ ADD_TEST(bfTvImageListToVectorImageFilter ${BASICFILTERS_TESTS}
# ------- otb::ImageListToImageListApplyFilter ----------------------------
#ADD_TEST(bfTuImageListToImageListApplyFilterNew ${BASICFILTERS_TESTS}
# otbImageListToImageListApplyFilterNew)
#ADD_TEST(bfTvImageListToImageListApplyFilter ${BASICFILTERS_TESTS}
# --compare-n-images ${EPSILON} 3
# ${BASELINE}/bfTvImageListToImageListApplyFilterBand1.png
# ${TEMP}/bfTvImageListToImageListApplyFilterBand1.png
# ${BASELINE}/bfTvImageListToImageListApplyFilterBand2.png
# ${TEMP}/bfTvImageListToImageListApplyFilterBand2.png
# ${BASELINE}/bfTvImageListToImageListApplyFilterBand3.png
# ${TEMP}/bfTvImageListToImageListApplyFilterBand3.png
# otbImageListToImageListApplyFilter
# ${INPUTDATA}/poupees.c1
# ${INPUTDATA}/poupees.c2
# ${INPUTDATA}/poupees.c3
# ${TEMP}/bfTvImageListToImageListApplyFilterBand1.png
# ${TEMP}/bfTvImageListToImageListApplyFilterBand2.png
# ${TEMP}/bfTvImageListToImageListApplyFilterBand3.png
#)
ADD_TEST(bfTuImageListToImageListApplyFilterNew ${BASICFILTERS_TESTS}
otbImageListToImageListApplyFilterNew)
ADD_TEST(bfTvImageListToImageListApplyFilter ${BASICFILTERS_TESTS}
--compare-n-images ${EPSILON} 3
${BASELINE}/bfTvImageListToImageListApplyFilterBand1.png
${TEMP}/bfTvImageListToImageListApplyFilterBand1.png
${BASELINE}/bfTvImageListToImageListApplyFilterBand2.png
${TEMP}/bfTvImageListToImageListApplyFilterBand2.png
${BASELINE}/bfTvImageListToImageListApplyFilterBand3.png
${TEMP}/bfTvImageListToImageListApplyFilterBand3.png
otbImageListToImageListApplyFilter
${INPUTDATA}/poupees.c1
${INPUTDATA}/poupees.c2
${INPUTDATA}/poupees.c3
${TEMP}/bfTvImageListToImageListApplyFilterBand1.png
${TEMP}/bfTvImageListToImageListApplyFilterBand2.png
${TEMP}/bfTvImageListToImageListApplyFilterBand3.png
)
# A enrichir
SET(BasicFilters_SRCS
......@@ -327,8 +327,8 @@ otbVectorImageToImageListFilterNew.cxx
otbVectorImageToImageListFilter.cxx
otbImageListToVectorImageFilterNew.cxx
otbImageListToVectorImageFilter.cxx
#otbImageListToImageListApplyFilterNew.cxx
#otbImageListToImageListApplyFilter.cxx
otbImageListToImageListApplyFilterNew.cxx
otbImageListToImageListApplyFilter.cxx
)
......
......@@ -58,6 +58,6 @@ REGISTER_TEST(otbVectorImageToImageListFilterNew);
REGISTER_TEST(otbVectorImageToImageListFilter);
REGISTER_TEST(otbImageListToVectorImageFilterNew);
REGISTER_TEST(otbImageListToVectorImageFilter);
//REGISTER_TEST(otbImageListToVectorImageApplyFilterNew);
//REGISTER_TEST(otbImageListToVectorImageApplyFilter);
REGISTER_TEST(otbImageListToImageListApplyFilterNew);
REGISTER_TEST(otbImageListToImageListApplyFilter);
}
/*=========================================================================
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.
=========================================================================*/
#include "itkExceptionObject.h"
#include "otbImageListToImageListApplyFilter.h"
#include "otbImageList.h"
#include "otbImage.h"
#include "itkMeanImageFilter.h"
#include "otbImageFileReader.h"
#include "otbImageFileWriter.h"
int otbImageListToImageListApplyFilter(int argc, char * argv[])
{
try
{
char * infname1 = argv[1];
char * infname2 = argv[2];
char * infname3 = argv[3];
char * outfname1 = argv[4];
char * outfname2 = argv[5];
char * outfname3 = argv[6];
const unsigned int Dimension = 2;
typedef unsigned char PixelType;
typedef otb::Image<PixelType,Dimension> ImageType;
typedef otb::ImageList<ImageType> ImageListType;
typedef itk::MeanImageFilter<ImageType,ImageType> MeanFilterType;
// IO
typedef otb::ImageFileReader<ImageType> ReaderType;
typedef otb::ImageFileWriter<ImageType> WriterType;
typedef otb::ImageListToImageListApplyFilter<ImageListType,ImageListType,MeanFilterType>
ImageListToImageListApplyFilterType;
// Instantiating object
ImageListToImageListApplyFilterType::Pointer filter = ImageListToImageListApplyFilterType::New();
ReaderType::Pointer reader1,reader2,reader3;
reader1 = ReaderType::New();
reader1->SetFileName(infname1);
reader2 = ReaderType::New();
reader2->SetFileName(infname2);
reader3 = ReaderType::New();
reader3->SetFileName(infname3);
ImageListType::Pointer imageList = ImageListType::New();
imageList->PushBack(reader1->GetOutput());
imageList->PushBack(reader2->GetOutput());
imageList->PushBack(reader3->GetOutput());
MeanFilterType::Pointer meanFilter = MeanFilterType::New();
filter->SetInput(imageList);
filter->SetFilter(meanFilter);
filter->Update();
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(outfname1);
writer->SetInput(filter->GetOutput()->GetNthElement(0));
writer->Update();
writer = WriterType::New();
writer->SetFileName(outfname2);
writer->SetInput(filter->GetOutput()->GetNthElement(0));
writer->Update();
writer = WriterType::New();
writer->SetFileName(outfname3);
writer->SetInput(filter->GetOutput()->GetNthElement(0));
writer->Update();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
/*=========================================================================
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.
=========================================================================*/
#include "itkExceptionObject.h"
#include "otbImageListToImageListApplyFilter.h"
#include "otbImageList.h"
#include "otbImage.h"
#include "itkMeanImageFilter.h"
int otbImageListToImageListApplyFilterNew(int argc, char * argv[])
{
try
{
const unsigned int Dimension = 2;
typedef unsigned char PixelType;
typedef otb::Image<PixelType,Dimension> ImageType;
typedef otb::ImageList<ImageType> ImageListType;
typedef itk::MeanImageFilter<ImageType,ImageType> MeanFilterType;
typedef otb::ImageListToImageListApplyFilter<ImageListType,ImageListType,MeanFilterType>
ImageListToImageListApplyFilterType;
// Instantiating object
ImageListToImageListApplyFilterType::Pointer object = ImageListToImageListApplyFilterType::New();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject thrown !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Unknown exception thrown !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment