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

Commit final PerBandImageFilter.

parent 49b898cd
No related branches found
No related tags found
No related merge requests found
......@@ -60,7 +60,7 @@ class ITK_EXPORT ImageListToImageListApplyFilter
/** Template parameters typedefs */
typedef TInputImageList InputImageListType;
typedef typename InputImageListType::ConstPointer InputImageListConstPointerType;
typedef typename InputImageListType::Pointer InputImageListPointerType;
typedef typename InputImageListType::ImageType InputImageType;
typedef TOutputImageList OutputImageListType;
typedef typename OutputImageListType::Pointer OutputImageListPointerType;
......
......@@ -40,21 +40,36 @@ ImageListToImageListApplyFilter<TInputImageList,TOutputImageList,TFilter>
::GenerateOutputInformation()
{
// Retrieving input/output pointers
InputImageListConstPointerType inputPtr = this->GetInput();
InputImageListPointerType inputPtr = this->GetInput();
OutputImageListPointerType outputPtr = this->GetOutput();
if(outputPtr)
{
if(outputPtr->Size()!=inputPtr->Size())
{
// in this case, clear the list
outputPtr->Clear();
typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
while(inputListIt!=inputPtr->End())
{
outputPtr->PushBack(OutputImageType::New());
++inputListIt;
}
}
// For each input image
typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
while(inputListIt!=inputPtr->End())
typename OutputImageListType::Iterator outputListIt = outputPtr->Begin();
while(inputListIt!=inputPtr->End()&&outputListIt!=outputPtr->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());
outputListIt.Get()->CopyInformation(m_Filter->GetOutput(m_OutputIndex));
outputListIt.Get()->SetLargestPossibleRegion(m_Filter->GetOutput(m_OutputIndex)->GetLargestPossibleRegion());
++inputListIt;
++outputListIt;
}
}
}
......@@ -65,7 +80,7 @@ ImageListToImageListApplyFilter<TInputImageList,TOutputImageList,TFilter>
::GenerateInputRequestedRegion()
{
// Retrieving input/output pointers
InputImageListConstPointerType inputPtr = this->GetInput();
InputImageListPointerType inputPtr = this->GetInput();
OutputImageListPointerType outputPtr = this->GetOutput();
// For each input image and corresponding output image
......@@ -89,7 +104,7 @@ ImageListToImageListApplyFilter<TInputImageList,TOutputImageList,TFilter>
::GenerateData()
{
// Retrieving input/output pointers
InputImageListConstPointerType inputPtr = this->GetInput();
InputImageListPointerType inputPtr = this->GetInput();
OutputImageListPointerType outputPtr = this->GetOutput();
// For each input image and corresponding output image
......
......@@ -40,7 +40,7 @@ ImageListToVectorImageFilter<TImageList,TVectorImage>
{
this->GetOutput()->CopyInformation(this->GetInput()->GetNthElement(0));
this->GetOutput()->SetNumberOfComponentsPerPixel(this->GetInput()->Size());
this->GetOutput()->SetRegions(this->GetInput()->GetNthElement(0)->GetLargestPossibleRegion());
this->GetOutput()->SetLargestPossibleRegion(this->GetInput()->GetNthElement(0)->GetLargestPossibleRegion());
}
}
}
......@@ -68,7 +68,7 @@ void
ImageListToVectorImageFilter<TImageList,TVectorImage>
::GenerateData(void)
{
InputImageListPointerType inputPtr = this->GetInput();
OutputVectorImagePointerType outputPtr = this->GetOutput();
......@@ -76,6 +76,7 @@ ImageListToVectorImageFilter<TImageList,TVectorImage>
typename OutputVectorImageType::PixelType black;
black.SetSize(inputPtr->Size());
black.Fill(0);
outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
outputPtr->Allocate();
outputPtr->FillBuffer(black);
......
......@@ -82,30 +82,17 @@ class ITK_EXPORT PerBandVectorImageFilter
typedef ImageListToVectorImageFilter<OutputImageListType,OutputVectorImageType> RecompositionFilterType;
typedef typename RecompositionFilterType::Pointer RecompositionFilterPointerType;
/**
* Set the processing filter. This method is provided to allow the setting up of the filter.
* \param filter The filter to use.
*/
void SetFilter(FilterType * filter);
/**
* Get the processing filter. This method is provided to allow the setting of the filter.
* \return The filter used.
*/
FilterType * GetFilter(void);
/**
* Set the index of the output of the filter from which to recompose the vector image.
* Default is 0.
* \param index The index of the output of the filter to use.
*/
void SetOutputIndex(unsigned int index);
/**
* Get the index of the output of the filter from which the vector image is recomposed.
* Default is 0.
* \return The index of the output of the filter used.
*/
unsigned int GetOutputIndex(void);
/// Accessors
itkSetObjectMacro(Filter,FilterType);
itkGetObjectMacro(Filter,FilterType);
itkSetMacro(OutputIndex,unsigned int);
itkGetMacro(OutputIndex,unsigned int);
virtual void GenerateInputRequestedRegion(void);
virtual void GenerateOutputInformation(void);
protected:
/** Main computation method */
virtual void GenerateData(void);
......@@ -119,13 +106,12 @@ protected:
private:
PerBandVectorImageFilter(const Self&); //purposely not implemented
void operator=(const Self&); //purposely not implemented
/// Splits VectorImage to ImageList
DecompositionFilterPointerType m_DecompositionFilter;
/// Processes the ImageList
ProcessingFilterPointerType m_ProcessingFilter;
/// Recompose the VectorImage
RecompositionFilterPointerType m_RecompositionFilter;
/// The processing filter
FilterPointerType m_Filter;
/// The index of the output of the filter to gather
unsigned m_OutputIndex;
};
}// End namespace otb
#ifndef OTB_MANUAL_INSTANTIATION
......
......@@ -29,56 +29,41 @@ template <class TInputImage, class TOutputImage, class TFilter>
PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::PerBandVectorImageFilter()
{
m_DecompositionFilter = DecompositionFilterType::New();
m_ProcessingFilter = ProcessingFilterType::New();
m_RecompositionFilter = RecompositionFilterType::New();
m_Filter = FilterType::New();
m_OutputIndex = 0;
}
/**
* Set the processing filter. This method is provided to allow the setting up of the filter.
* \param filter The filter to use.
*/
template <class TInputImage, class TOutputImage, class TFilter>
void
PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::SetFilter(FilterType * filter)
::GenerateOutputInformation()
{
m_ProcessingFilter->SetFilter(filter);
if(this->GetInput())
{
// Create a false monoband image
typename InputImageType::Pointer dummyInputImage = InputImageType::New();
dummyInputImage->CopyInformation(this->GetInput());
dummyInputImage->SetNumberOfComponentsPerPixel(1);
m_Filter->SetInput(dummyInputImage);
m_Filter->UpdateOutputInformation();
this->GetOutput()->CopyInformation(m_Filter->GetOutput(m_OutputIndex));
this->GetOutput()->SetNumberOfComponentsPerPixel(this->GetInput()->GetNumberOfComponentsPerPixel());
}
}
/**
* Get the processing filter. This method is provided to allow the setting of the filter.
* \return The filter used.
*/
template <class TInputImage, class TOutputImage, class TFilter>
typename PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::FilterType *
PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::GetFilter()
{
return m_ProcessingFilter->GetFilter();
}
/**
* Set the index of the output of the filter from which to recompose the vector image.
* Default is 0.
* \param index The index of the output of the filter to use.
*/
template <class TInputImage, class TOutputImage, class TFilter>
void
PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::SetOutputIndex(unsigned int index)
{
m_ProcessingFilter->SetOutputIndex(index);
}
/**
* Get the index of the output of the filter from which the vector image is recomposed.
* Default is 0.
* \return The index of the output of the filter used.
*/
template <class TInputImage, class TOutputImage, class TFilter>
unsigned int
PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::GetOutputIndex()
::GenerateInputRequestedRegion()
{
return m_ProcessingFilter->GetOutputIndex();
InputVectorImageType * inputPtr = const_cast<InputVectorImageType *>(this->GetInput());
typename InputImageType::Pointer dummyInputImage = InputImageType::New();
dummyInputImage->CopyInformation(this->GetInput());
dummyInputImage->SetNumberOfComponentsPerPixel(1);
m_Filter->SetInput(dummyInputImage);
m_Filter->GetOutput(m_OutputIndex)->SetRequestedRegion(this->GetOutput()->GetRequestedRegion());
m_Filter->GenerateInputRequestedRegion();
inputPtr->SetRequestedRegion(m_Filter->GetInput()->GetRequestedRegion());
}
/**
* Main computation method
......@@ -88,15 +73,25 @@ void
PerBandVectorImageFilter<TInputImage,TOutputImage,TFilter>
::GenerateData()
{
m_DecompositionFilter->SetInput(this->GetInput());
m_ProcessingFilter->SetInput(m_DecompositionFilter->GetOutput());
m_RecompositionFilter->SetInput(m_ProcessingFilter->GetOutput());
InputVectorImageType * inputPtr = const_cast<InputVectorImageType *>(this->GetInput());
OutputVectorImagePointerType outputPtr = this->GetOutput();
DecompositionFilterPointerType decomposer = DecompositionFilterType::New();
ProcessingFilterPointerType processor = ProcessingFilterType::New();
RecompositionFilterPointerType recomposer = RecompositionFilterType::New();
m_RecompositionFilter->GraftOutput(this->GetOutput());
m_RecompositionFilter->Update();
this->GraftOutput(m_RecompositionFilter->GetOutput());
}
inputPtr->UpdateOutputData();
decomposer->SetInput(this->GetInput());
processor->SetInput(decomposer->GetOutput());
processor->SetFilter(m_Filter);
processor->SetOutputIndex(m_OutputIndex);
recomposer->SetInput(processor->GetOutput());
recomposer->GetOutput()->SetRequestedRegion(this->GetOutput()->GetRequestedRegion());
recomposer->GraftOutput(this->GetOutput());
recomposer->Update();
this->GraftOutput(recomposer->GetOutput());
}
/**
* PrintSelf Method
*/
......
......@@ -19,8 +19,8 @@ PURPOSE. See the above copyright notices for more information.
#define _otbVectorImageToImageListFilter_txx
#include "otbVectorImageToImageListFilter.h"
#include "itkImageRegionIterator.h"
#include "itkImageRegionConstIterator.h"
#include "itkImageRegionIteratorWithIndex.h"
#include "itkImageRegionConstIteratorWithIndex.h"
#include <vector>
#include "otbMacro.h"
......@@ -37,12 +37,22 @@ VectorImageToImageListFilter<TVectorImageType,TImageList>
if(inputPtr)
{
if(outputPtr->Size()!=inputPtr->GetNumberOfComponentsPerPixel())
{
// if the number of components does not match, clear the list
outputPtr->Clear();
for(unsigned int i=0;i<inputPtr->GetNumberOfComponentsPerPixel();++i)
{
typename OutputImageType::Pointer tmpImagePtr = OutputImageType::New();
outputPtr->PushBack(tmpImagePtr);
}
}
for(unsigned int i=0;i<inputPtr->GetNumberOfComponentsPerPixel();++i)
{
typename OutputImageType::Pointer tmpImagePtr = OutputImageType::New();
tmpImagePtr->CopyInformation(inputPtr);
tmpImagePtr->SetRegions(inputPtr->GetLargestPossibleRegion());
outputPtr->PushBack(tmpImagePtr);
typename OutputImageType::Pointer tmpImagePtr = outputPtr->GetNthElement(i);
tmpImagePtr->CopyInformation(inputPtr);
tmpImagePtr->SetLargestPossibleRegion(inputPtr->GetLargestPossibleRegion());
tmpImagePtr->SetRequestedRegion(inputPtr->GetLargestPossibleRegion());
}
}
}
......@@ -71,11 +81,12 @@ void
VectorImageToImageListFilter<TVectorImageType,TImageList>
::GenerateData(void)
{
OutputImageListPointerType outputPtr = this->GetOutput();
InputVectorImagePointerType inputPtr = this->GetInput();
typedef itk::ImageRegionConstIterator<InputVectorImageType> InputIteratorType;
typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType;
typedef itk::ImageRegionConstIteratorWithIndex<InputVectorImageType> InputIteratorType;
typedef itk::ImageRegionIteratorWithIndex<OutputImageType> OutputIteratorType;
InputIteratorType inputIt(inputPtr,inputPtr->GetRequestedRegion());
......@@ -84,6 +95,7 @@ VectorImageToImageListFilter<TVectorImageType,TImageList>
typename OutputImageListType::ConstIterator outputListIt = outputPtr->Begin();
for(;outputListIt!=outputPtr->End();++outputListIt)
{
outputListIt.Get()->SetBufferedRegion(outputListIt.Get()->GetRequestedRegion());
outputListIt.Get()->Allocate();
outputIteratorList.push_back(OutputIteratorType(outputListIt.Get(),outputListIt.Get()->GetRequestedRegion()));
outputIteratorList.back().GoToBegin();
......@@ -104,7 +116,7 @@ VectorImageToImageListFilter<TVectorImageType,TImageList>
}
else
{
itkGenericExceptionMacro("End of image !");
itkGenericExceptionMacro("End of image for band "<<counter<<" at index "<<(*it).GetIndex()<<" !");
}
}
++inputIt;
......
......@@ -18,6 +18,8 @@ PURPOSE. See the above copyright notices for more information.
#ifndef _otbImageList_txx
#define _otbImageList_txx
#include "otbMacro.h"
namespace otb
{
......@@ -78,7 +80,13 @@ void
ImageList<TImage>
::UpdateOutputInformation()
{
// otbMsgDebugMacro(<<"ImageList: Call to UpdateOutputInformation()");
Superclass::UpdateOutputInformation();
if(this->GetSource())
{
this->GetSource()->UpdateOutputInformation();
}
for(ConstIterator it = this->Begin(); it!=this->End();++it)
{
if(it.Get()->GetSource())
......
......@@ -79,6 +79,11 @@ ADD_TEST(viTvImageViewerWithLargeOtbImage ${VISU_TESTS}
${IMAGEDATA}/TOULOUSE/QuickBird/000000128955_01_P001_PAN/02APR01105228-P1BS-000000128955_01_P001.TIF
)
ADD_TEST(viTvImageViewerWithMultiBandFilter ${VISU_TESTS}
otbImageViewerWithMultiBandFilter
${INPUTDATA}/couleurs.jpg
)
# ------- Fichiers sources CXX -----------------------------------
SET(BasicVisu_SRCS
......@@ -91,6 +96,7 @@ otbZoomableImageWidgetNew.cxx
otbZoomableImageWidget.cxx
otbImageViewer.cxx
otbImageViewerWithOtbImage.cxx
otbImageViewerWithMultiBandFilter.cxx
otbImageViewerNew.cxx
)
......
/*=========================================================================
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 "otbImageFileReader.h"
#include "otbImageViewer.h"
#include "otbMacro.h"
#include "itkSobelEdgeDetectionImageFilter.h"
#include "otbPerBandVectorImageFilter.h"
#include "otbImage.h"
int otbImageViewerWithMultiBandFilter( int argc, char * argv[] )
{
try
{
char * filename = argv[1];
// Parse command line parameters
typedef double PixelType;
typedef otb::ImageViewer<PixelType> ImageViewerType;
typedef ImageViewerType::ImageType VectorImageType;
typedef ImageViewerType::SingleImageType ImageType;
typedef itk::SobelEdgeDetectionImageFilter<ImageType,ImageType> FilterType;
typedef otb::PerBandVectorImageFilter<VectorImageType,VectorImageType,FilterType>
PerBandFilterType;
typedef otb::ImageFileReader<VectorImageType> ReaderType;
// instantiation
ImageViewerType::Pointer viewer = ImageViewerType::New();
PerBandFilterType::Pointer filter = PerBandFilterType::New();
// check for input images
ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName(filename);
filter->SetInput(reader->GetOutput());
filter->UpdateOutputInformation();
std::cout<<"Main - number of bands: "<<filter->GetOutput()->GetNumberOfComponentsPerPixel()<<std::endl;
std::cout<<"Main - largest region: "<<filter->GetOutput()->GetLargestPossibleRegion()<<std::endl;
viewer->SetImage(filter->GetOutput());
// build the app
viewer->Show();
Fl::check();
}
catch( itk::ExceptionObject & err )
{
std::cout << "Exception itk::ExceptionObject levee !" << std::endl;
std::cout << err << std::endl;
return EXIT_FAILURE;
}
catch( ... )
{
std::cout << "Exception levee inconnue !" << std::endl;
return EXIT_FAILURE;
}
return EXIT_SUCCESS;
}
......@@ -35,5 +35,6 @@ REGISTER_TEST(otbZoomableImageWidgetNew);
REGISTER_TEST(otbZoomableImageWidget);
REGISTER_TEST(otbImageViewer);
REGISTER_TEST(otbImageViewerWithOtbImage);
REGISTER_TEST(otbImageViewerWithMultiBandFilter);
REGISTER_TEST(otbImageViewerNew);
}
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