From 98974132dfb169419b1a7026c7bbbf1df9882ca0 Mon Sep 17 00:00:00 2001 From: Jordi Inglada <jordi.inglada@orfeo-toolbox.org> Date: Wed, 14 May 2008 14:28:38 +0000 Subject: [PATCH] Exemple ImageSeriesIO --- Examples/IO/CMakeLists.txt | 4 + Examples/IO/ImageSeriesIOExample.cxx | 216 +++++++++++++++++++++++++++ 2 files changed, 220 insertions(+) create mode 100644 Examples/IO/ImageSeriesIOExample.cxx diff --git a/Examples/IO/CMakeLists.txt b/Examples/IO/CMakeLists.txt index aaf3ef5185..d5375714fa 100644 --- a/Examples/IO/CMakeLists.txt +++ b/Examples/IO/CMakeLists.txt @@ -39,6 +39,10 @@ TARGET_LINK_LIBRARIES(MultibandImageReadWrite OTBCommon OTBIO ITKCommon ITKIO) ADD_EXECUTABLE(ExtractROI ExtractROI.cxx ) TARGET_LINK_LIBRARIES(ExtractROI OTBCommon OTBIO ITKCommon ITKIO) +ADD_EXECUTABLE(ImageSeriesIOExample ImageSeriesIOExample.cxx ) +TARGET_LINK_LIBRARIES(ImageSeriesIOExample OTBCommon OTBIO ITKCommon ITKIO) + + ADD_EXECUTABLE(MetadataExample MetadataExample.cxx ) TARGET_LINK_LIBRARIES(MetadataExample OTBCommon OTBIO ITKCommon ITKIO) diff --git a/Examples/IO/ImageSeriesIOExample.cxx b/Examples/IO/ImageSeriesIOExample.cxx new file mode 100644 index 0000000000..f8c34bf8b6 --- /dev/null +++ b/Examples/IO/ImageSeriesIOExample.cxx @@ -0,0 +1,216 @@ +/*========================================================================= + + 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 <iostream> + +// Software Guide : BeginLatex +// +// This example shows how to read a list of images and concatenate +// them into a vector image. We will write a program which is able to +// perform this operation taking advantage of the streaming +// functionnalities of the processing pipeline. We will assume that +// all the input images have the same size and a single band. +// +// The following header files will be needed: +// +// Software Guide : EndLatex + + +// Software Guide : BeginCodeSnippet +#include "otbImage.h" +#include "otbVectorImage.h" +#include "otbImageFileReader.h" +#include "otbObjectList.h" +#include "otbImageList.h" +#include "otbImageListToVectorImageFilter.h" +#include "otbStreamingImageFileWriter.h" +// Software Guide : EndCodeSnippet + + +int main(int argc, char** argv) +{ + if(argc < 4 ) + { + std::cerr << "Usage: " << argv[0] ; + std::cerr << "outputImage image1 image2 ... " << std::endl; + } + + const unsigned int NbImages = argc-2; + + std::cout << "Concat of " << NbImages << " images into a multi-band image " << + std::endl; + +// Software Guide : BeginLatex +// +// We will start by defining the types for the input images and the +// associated readers. +// +// Software Guide : EndLatex + + +// Software Guide : BeginCodeSnippet + typedef unsigned short int PixelType; + const unsigned int Dimension = 2; + + typedef otb::Image< PixelType, Dimension > InputImageType; + + typedef otb::ImageFileReader< InputImageType > ImageReaderType; +// Software Guide : EndCodeSnippet + +// Software Guide : BeginLatex +// +// We will use a list of image file readers in order to open all the +// input images at once. For this, we use the +// \doxygen{otb}{ObjectList} object and we template it over the type +// of the readers. +// +// Software Guide : EndLatex + + +// Software Guide : BeginCodeSnippet + typedef otb::ObjectList< ImageReaderType > ReaderListType; + + ReaderListType::Pointer readerList = ReaderListType::New(); + +// Software Guide : EndCodeSnippet + +// Software Guide : BeginLatex +// +// We will also build a list of input images in order to store the +// smart pointers obtained at the output of each reader. This allows +// us to build a pipeline without really reading the images and using +// lots of RAM. The \doxygen{otb}{ImageList} object will be used. +// +// Software Guide : EndLatex + + +// Software Guide : BeginCodeSnippet + typedef otb::ImageList< InputImageType > ImageListType; + + ImageListType::Pointer imageList = ImageListType::New(); + +// Software Guide : EndCodeSnippet + +// Software Guide : BeginLatex +// +// We can now loop over the input image list in order to populate the +// reader list and the input image list. +// +// Software Guide : EndLatex + + +// Software Guide : BeginCodeSnippet + for(unsigned int i = 0; i<NbImages; i++) + { + + ImageReaderType::Pointer imageReader = ImageReaderType::New(); + + imageReader->SetFileName( argv[i+2] ); + + std::cout << "Adding image " << argv[i+2] << std::endl; + + imageReader->UpdateOutputInformation(); + + imageList->PushBack( imageReader->GetOutput() ); + + readerList->PushBack( imageReader ); + + } + +// Software Guide : EndCodeSnippet + +// Software Guide : BeginLatex +// +// All the input images will be concatenated into a single output +// vector image. For this matter, we will use the +// \doxygen{otb}{ImageListToVectorImageFilter} which is templated +// over the input image list type and the output vector image type. +// +// Software Guide : EndLatex + + +// Software Guide : BeginCodeSnippet + typedef otb::VectorImage< PixelType, Dimension > VectorImageType; + + typedef otb::ImageListToVectorImageFilter< ImageListType, VectorImageType > + ImageListToVectorImageFilterType; + + ImageListToVectorImageFilterType::Pointer iL2VI = + ImageListToVectorImageFilterType::New(); + +// Software Guide : EndCodeSnippet + +// Software Guide : BeginLatex +// +// We plug the image list as input of the filter and use a +// \doxygen{otb}{StreamingImageFileWriter} to write the result image +// to a file, so that the streaming capabilities of all the readers +// and the filter are used. +// +// Software Guide : EndLatex + + +// Software Guide : BeginCodeSnippet + iL2VI->SetInput( imageList ); + + typedef otb::StreamingImageFileWriter< VectorImageType > ImageWriterType; + + ImageWriterType::Pointer imageWriter = ImageWriterType::New(); + + imageWriter->SetFileName( argv[1] ); + +// Software Guide : EndCodeSnippet + +// Software Guide : BeginLatex +// +// We can tune the size of the image tiles as a function of the +// number of input images, so that the total memory footprint of the +// pipeline is constant for any execution of the program. +// +// Software Guide : EndLatex + + +// Software Guide : BeginCodeSnippet + + unsigned long size = (10000 * 10000 * sizeof(PixelType)) / NbImages; + + std::cout<<"Streaming size: "<<size<<std::endl; + + imageWriter->SetBufferMemorySize(size); + + imageWriter->SetInput( iL2VI->GetOutput() ); + + imageWriter->Update(); + +// Software Guide : EndCodeSnippet + + + return 0; +} -- GitLab