From ff94a803bdd609dba591c28926fc72d5f34e5931 Mon Sep 17 00:00:00 2001 From: Emmanuel Christophe <emmanuel.christophe@orfeo-toolbox.org> Date: Mon, 10 Dec 2007 07:51:29 +0000 Subject: [PATCH] Correction fusion et ajout filtre pour generation des png --- Code/BasicFilters/otbPrintableImageFilter.h | 101 +++++++++++++++++ Code/BasicFilters/otbPrintableImageFilter.txx | 103 ++++++++++++++++++ ...bSimpleRcsPanSharpeningFusionImageFilter.h | 4 +- ...impleRcsPanSharpeningFusionImageFilter.txx | 12 +- Examples/Fusion/PanSharpeningExample.cxx | 56 +++++++++- 5 files changed, 267 insertions(+), 9 deletions(-) create mode 100644 Code/BasicFilters/otbPrintableImageFilter.h create mode 100644 Code/BasicFilters/otbPrintableImageFilter.txx diff --git a/Code/BasicFilters/otbPrintableImageFilter.h b/Code/BasicFilters/otbPrintableImageFilter.h new file mode 100644 index 0000000000..847e9c4b38 --- /dev/null +++ b/Code/BasicFilters/otbPrintableImageFilter.h @@ -0,0 +1,101 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + Some parts of this code are derived from ITK. See ITKCopyright.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 __otbPrintableImageFilter_h +#define __otbPrintableImageFilter_h + +#include "itkImageToImageFilter.h" +#include "otbVectorRescaleIntensityImageFilter.h" +#include "otbMultiChannelExtractROI.h" + +namespace otb { + /** + * \class PrintableImageFilter + * \brief This class + * + * + * + * + * + * + * + **/ + + template <class TInputImageType> +class ITK_EXPORT PrintableImageFilter : + public itk::ImageToImageFilter<TInputImageType, otb::VectorImage<unsigned char,2> > + { + public: + typedef PrintableImageFilter Self; + typedef itk::ImageToImageFilter + <TInputImageType, otb::VectorImage<unsigned char,2> > Superclass; + typedef itk::SmartPointer<Self> Pointer; + typedef itk::SmartPointer<const Self> ConstPointer; + typedef otb::VectorImage<unsigned char,2> OutputImageType; +// typedef typename OutputImageType::PixelType PixelType; + typedef unsigned char PixelType; + + typedef otb::VectorRescaleIntensityImageFilter + <TInputImageType,OutputImageType> VectorRescalerType; + typedef otb::MultiChannelExtractROI + <PixelType,PixelType> ChannelExtractorType; + typedef typename ChannelExtractorType::ChannelsType ChannelsType; + + + /** Method for creation through object factory */ + itkNewMacro(Self); + + /** Run-time type information */ + itkTypeMacro(PrintableImageFilter, + itk::ImageToImageFilter); + + /** Display */ + void PrintSelf( std::ostream& os, itk::Indent indent ) const; + + void SetChannel( unsigned int channel); + const ChannelsType GetChannels(void); + + protected: + + PrintableImageFilter(); + + void GenerateData(); + + private: + + PrintableImageFilter(Self&); // intentionally not implemented + void operator=(const Self&); // intentionally not implemented + + typename VectorRescalerType::Pointer m_Rescaler; + typename ChannelExtractorType::Pointer m_Extractor; + + + + }; + +} // end namespace otb + +#ifndef OTB_MANUAL_INSTANTIATION +#include "otbPrintableImageFilter.txx" +#endif + +#endif + diff --git a/Code/BasicFilters/otbPrintableImageFilter.txx b/Code/BasicFilters/otbPrintableImageFilter.txx new file mode 100644 index 0000000000..3012da03b3 --- /dev/null +++ b/Code/BasicFilters/otbPrintableImageFilter.txx @@ -0,0 +1,103 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + Some parts of this code are derived from ITK. See ITKCopyright.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 __otbPrintableImageFilter_txx +#define __otbPrintableImageFilter_txx + +#include "otbPrintableImageFilter.h" + + +namespace otb +{ + + template <class TInputImage> + PrintableImageFilter<TInputImage> + ::PrintableImageFilter() + { + + m_Rescaler = VectorRescalerType::New(); + m_Extractor = ChannelExtractorType::New(); + + m_Extractor->SetInput( m_Rescaler->GetOutput() ); + + } + + template <class TInputImage> + void + PrintableImageFilter<TInputImage> + ::SetChannel(unsigned int channel) + { + m_Extractor->SetChannel(channel); + this->Modified(); + } + + template <class TInputImage> + const typename PrintableImageFilter<TInputImage>::ChannelsType + PrintableImageFilter<TInputImage> + ::GetChannels() + { + return m_Extractor->GetChannels(); + } + + + template <class TInputImage> + void + PrintableImageFilter<TInputImage> + ::GenerateData() + { + + if(m_Extractor->GetNbChannels() == 0){ + m_Extractor->SetChannel(2); + m_Extractor->SetChannel(3); + m_Extractor->SetChannel(4); + } + + typename TInputImage::PixelType minimum,maximum; + minimum.SetSize(this->GetInput()->GetNumberOfComponentsPerPixel()); + maximum.SetSize(this->GetInput()->GetNumberOfComponentsPerPixel()); + minimum.Fill(0); + maximum.Fill(255); + + m_Rescaler->SetInput(this->GetInput()); + m_Rescaler->SetOutputMinimum(minimum); + m_Rescaler->SetOutputMaximum(maximum); + m_Rescaler->SetClampThreshold(0.01); +// m_Rescaler->GetOutput()->SetNumberOfComponentsPerPixel(4); + + m_Extractor->GraftOutput( this->GetOutput() ); + m_Extractor->Update(); + this->GraftOutput( m_Extractor->GetOutput() ); + } + + template <class TInputImage> + void + PrintableImageFilter<TInputImage> + ::PrintSelf( std::ostream& os, itk::Indent indent ) const + { + Superclass::PrintSelf(os,indent); + + os +// << indent << "Channels:" << this->m_Extractor->GetChannels() + << std::endl; + } + +} // end namespace otb + +#endif diff --git a/Code/Fusion/otbSimpleRcsPanSharpeningFusionImageFilter.h b/Code/Fusion/otbSimpleRcsPanSharpeningFusionImageFilter.h index 60ccfce77f..5564946094 100644 --- a/Code/Fusion/otbSimpleRcsPanSharpeningFusionImageFilter.h +++ b/Code/Fusion/otbSimpleRcsPanSharpeningFusionImageFilter.h @@ -44,12 +44,12 @@ namespace otb { template <class TPanImageType,class TXsImageType,class TOutputImageType> class ITK_EXPORT SimpleRcsPanSharpeningFusionImageFilter : - public itk::ImageToImageFilter<TPanImageType, TOutputImageType> + public itk::ImageToImageFilter<TXsImageType, TOutputImageType> { public: typedef SimpleRcsPanSharpeningFusionImageFilter Self; typedef itk::ImageToImageFilter - <TPanImageType, TOutputImageType> Superclass; + <TXsImageType, TOutputImageType> Superclass; typedef itk::SmartPointer<Self> Pointer; typedef itk::SmartPointer<const Self> ConstPointer; typedef otb::Image<double,2> InternalImageType; diff --git a/Code/Fusion/otbSimpleRcsPanSharpeningFusionImageFilter.txx b/Code/Fusion/otbSimpleRcsPanSharpeningFusionImageFilter.txx index a0cba29c98..71a91519aa 100644 --- a/Code/Fusion/otbSimpleRcsPanSharpeningFusionImageFilter.txx +++ b/Code/Fusion/otbSimpleRcsPanSharpeningFusionImageFilter.txx @@ -52,7 +52,7 @@ namespace otb // We have 2 inputs: an image and a vector image // Process object is not const-correct so the const_cast is required here - this->itk::ProcessObject::SetNthInput(0, + this->itk::ProcessObject::SetNthInput(1, const_cast< TPanImageType* >( image ) ); this->Modified(); } @@ -62,13 +62,13 @@ namespace otb SimpleRcsPanSharpeningFusionImageFilter<TPanImageType, TXsImageType, TOutputImageType> ::GetPanInput(void) { - if (this->GetNumberOfInputs() < 1) + if (this->GetNumberOfInputs() < 2) { return 0; } return static_cast<const TPanImageType * > - (this->itk::ProcessObject::GetInput(0) ); + (this->itk::ProcessObject::GetInput(1) ); } template <class TPanImageType, class TXsImageType, class TOutputImageType> @@ -79,7 +79,7 @@ namespace otb // We have 2 inputs: an image and a vector image // Process object is not const-correct so the const_cast is required here - this->itk::ProcessObject::SetNthInput(1, + this->itk::ProcessObject::SetNthInput(0, const_cast< TXsImageType* >( image ) ); this->Modified(); } @@ -89,13 +89,13 @@ namespace otb SimpleRcsPanSharpeningFusionImageFilter<TPanImageType, TXsImageType, TOutputImageType> ::GetXsInput(void) { - if (this->GetNumberOfInputs() < 2) + if (this->GetNumberOfInputs() < 1) { return 0; } return static_cast<const TXsImageType * > - (this->itk::ProcessObject::GetInput(1) ); + (this->itk::ProcessObject::GetInput(0) ); } diff --git a/Examples/Fusion/PanSharpeningExample.cxx b/Examples/Fusion/PanSharpeningExample.cxx index 2deca33348..b16b46c26c 100644 --- a/Examples/Fusion/PanSharpeningExample.cxx +++ b/Examples/Fusion/PanSharpeningExample.cxx @@ -1,3 +1,31 @@ +/*========================================================================= + + Program: ORFEO Toolbox + Language: C++ + Date: $Date$ + Version: $Revision$ + + + Copyright (c) Centre National d'Etudes Spatiales. All rights reserved. + See OTBCopyright.txt for details. + + Some parts of this code are derived from ITK. See ITKCopyright.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. + +=========================================================================*/ +#if defined(_MSC_VER) +#pragma warning ( disable : 4786 ) +#endif + +#ifdef __BORLANDC__ +#define ITK_LEAN_AND_MEAN +#endif + #include "otbImage.h" #include "otbVectorImage.h" @@ -5,9 +33,19 @@ #include "otbStreamingImageFileWriter.h" #include "otbSimpleRcsPanSharpeningFusionImageFilter.h" +#include "otbPrintableImageFilter.h" int main( int argc, char* argv[] ) { + + if( argc < 4 ) + { + std::cerr << "Missing Parameters " << std::endl; + std::cerr << "Usage: " << argv[0]; + std::cerr << " inputPanchromatiqueImage inputMultiSpectralImage outputImage outputImagePrinted msPrinted msiPrinted panchroPrinted " << std::endl; + return 1; + } + typedef otb::Image<double, 2> ImageType; typedef otb::VectorImage<double, 2> VectorImageType; typedef otb::ImageFileReader<ImageType> ReaderType; @@ -36,7 +74,23 @@ int main( int argc, char* argv[] ) writer->SetFileName(argv[3]); writer->SetInput(fusion->GetOutput()); writer->Update(); - + + typedef otb::PrintableImageFilter<VectorIntImageType> PrintableImageType; + PrintableImageType::Pointer printable = PrintableImageType::New(); + printable->SetInput(fusion->GetOutput()); +// printable->SetInput(readerXS->GetOutput()); +// printable->SetChannel(1); + printable->SetChannel(3); + printable->SetChannel(2); + printable->SetChannel(1); + + typedef otb::VectorImage<unsigned char, 2> VectorCharImageType; + typedef otb::StreamingImageFileWriter<VectorCharImageType> PNGWriterType; + PNGWriterType::Pointer pngwriter = PNGWriterType::New(); + pngwriter->SetFileName(argv[4]); + pngwriter->SetInput(printable->GetOutput()); + pngwriter->Update(); + return 0; } -- GitLab