Skip to content
Snippets Groups Projects
Commit 0b0792b5 authored by Cyrille Valladeau's avatar Cyrille Valladeau
Browse files

ENH: ConcatenateImages application in the new framework

parent 7509e803
Branches
Tags
No related merge requests found
......@@ -17,4 +17,8 @@ OTB_CREATE_APPLICATION(NAME ReadImageInfo
OTB_CREATE_APPLICATION(NAME MultiResolutionPyramid
SOURCES otbMultiResolutionPyramid.cxx
LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters)
OTB_CREATE_APPLICATION(NAME ConcatenateImages
SOURCES otbConcatenateImages.cxx
LINK_LIBRARIES OTBIO;OTBCommon;OTBBasicFilters)
\ No newline at end of file
/*=========================================================================
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 "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
#include "otbImageListToVectorImageFilter.h"
#include "otbMultiToMonoChannelExtractROI.h"
#include "otbObjectList.h"
#include "otbWrapperTypes.h"
namespace otb
{
namespace Wrapper
{
class ConcatenateImages : public Application
{
public:
/** Standard class typedefs. */
typedef ConcatenateImages Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(ConcatenateImages, otb::Application);
/** Filters typedef */
typedef ImageListToVectorImageFilter<FloatImageListType,
FloatVectorImageType > ListConcatenerFilterType;
typedef MultiToMonoChannelExtractROI<FloatVectorImageType::InternalPixelType,
FloatImageType::PixelType> ExtractROIFilterType;
typedef ObjectList<ExtractROIFilterType> ExtractROIFilterListType;
private:
ConcatenateImages()
{
SetName("ConcatenateImages");
SetDescription("Concatenate a list of image into a single mulit channel one.");
m_Concatener = ListConcatenerFilterType::New();
m_ExtractorList = ExtractROIFilterListType::New();
m_ImageList = FloatImageListType::New();
}
virtual ~ConcatenateImages()
{
}
void DoCreateParameters()
{
AddParameter(ParameterType_InputImageList, "il", "Input image list");
SetParameterDescription("il", "Image list to concatenate");
AddParameter(ParameterType_OutputImage, "out", "Output Image");
SetParameterDescription("out", "Outmput multiband image");
}
void DoUpdateParameters()
{
// Nothing to do here for the parameters : all are independent
// Reinitialize the object
m_Concatener = ListConcatenerFilterType::New();
m_ImageList = FloatImageListType::New();
m_ExtractorList = ExtractROIFilterListType::New();
this->ClearInternalProcessList();
}
void DoExecute()
{
// Get the input image list
FloatVectorImageListType::Pointer inList = this->GetParameterImageList("il");
// Split each input vector image into image
// and generate an mono channel image list
for( unsigned int i=0; i<inList->Size(); i++ )
{
FloatVectorImageType::Pointer vectIm = inList->GetNthElement(i);
vectIm->UpdateOutputInformation();
for( unsigned int j=0; j<vectIm->GetNumberOfComponentsPerPixel(); j++)
{
ExtractROIFilterType::Pointer extractor = ExtractROIFilterType::New();
extractor->SetInput( vectIm );
extractor->SetChannel( j+1 );
extractor->UpdateOutputInformation();
m_ExtractorList->PushBack( extractor );
m_ImageList->PushBack( extractor->GetOutput() );
}
}
m_Concatener->SetInput( m_ImageList );
SetParameterOutputImage("out", m_Concatener->GetOutput());
}
ListConcatenerFilterType::Pointer m_Concatener;
ExtractROIFilterListType::Pointer m_ExtractorList;
FloatImageListType::Pointer m_ImageList;
};
}
}
OTB_APPLICATION_EXPORT(otb::Wrapper::ConcatenateImages)
/*=========================================================================
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 "otbConcatenateImages.h"
#include <iostream>
#include "otbImage.h"
#include "otbVectorImage.h"
#include "otbImageFileReader.h"
#include "otbObjectList.h"
#include "otbImageList.h"
#include "otbImageListToVectorImageFilter.h"
#include "otbStreamingImageFileWriter.h"
#include "otbStandardFilterWatcher.h"
namespace otb
{
template<typename PixelType>
int generic_main_concatenate(otb::ApplicationOptionsResult* parseResult)
{
const unsigned int NbImages = parseResult->GetNumberOfParameters("InputImagesList");
std::ofstream textFile;
if (parseResult->IsOptionPresent("OutputNameList"))
{
std::string textName = parseResult->GetParameterString("OutputNameList");
textFile.open(textName.c_str());
}
std::cout << "Concat of " << NbImages << " images into a multi-band image " << std::endl;
const unsigned int Dimension = 2;
typedef otb::Image<PixelType, Dimension> InputImageType;
typedef otb::ImageFileReader<InputImageType> ImageReaderType;
typedef otb::ObjectList<ImageReaderType> ReaderListType;
typename ReaderListType::Pointer readerList = ReaderListType::New();
typedef otb::ImageList<InputImageType> ImageListType;
typename ImageListType::Pointer imageList = ImageListType::New();
for (unsigned int i = 0; i < NbImages; i++)
{
typename ImageReaderType::Pointer imageReader = ImageReaderType::New();
imageReader->SetFileName(parseResult->GetParameterString("InputImagesList", i).c_str());
std::cout << "Adding image " << parseResult->GetParameterString("InputImagesList", i).c_str() << std::endl;
textFile << parseResult->GetParameterString("InputImagesList", i) << "\n";
imageReader->UpdateOutputInformation();
imageList->PushBack(imageReader->GetOutput());
readerList->PushBack(imageReader);
}
textFile.close();
typedef otb::VectorImage<PixelType, Dimension> VectorImageType;
typedef otb::ImageListToVectorImageFilter<ImageListType, VectorImageType> ImageListToVectorImageFilterType;
typename ImageListToVectorImageFilterType::Pointer iL2VI = ImageListToVectorImageFilterType::New();
iL2VI->SetInput(imageList);
typedef otb::StreamingImageFileWriter<VectorImageType> ImageWriterType;
typename ImageWriterType::Pointer imageWriter = ImageWriterType::New();
imageWriter->SetFileName(parseResult->GetOutputImage().c_str());
unsigned int ram = 256;
if (parseResult->IsOptionPresent("AvailableMemory"))
{
ram = parseResult->GetParameterUInt("AvailableMemory");
}
imageWriter->SetAutomaticTiledStreaming(ram);
imageWriter->SetInput(iL2VI->GetOutput());
otb::StandardFilterWatcher watcher(imageWriter, "Writing");
imageWriter->Update();
return EXIT_SUCCESS;
}
int ConcatenateImages::Describe(ApplicationDescriptor* descriptor)
{
descriptor->SetName("ConcatenateImages");
descriptor->SetDescription("Concatenate n images in a multiband image");
descriptor->AddOptionNParams("InputImagesList", "Images list to concatenate", "il", true, ApplicationDescriptor::InputImage);
descriptor->AddOutputImage();
descriptor->AddOption("OutputPixelType",
"OutputPixelType: unsigned char (1), short int (2), int (3), float (4),"
" double (5), unsigned short int (12), unsigned int (13); default 2",
"t", 1, false, ApplicationDescriptor::Integer);
descriptor->AddOption("OutputNameList",
"Text file containing the name of the images used to generate the output in the same order",
"ot", 1, false, ApplicationDescriptor::String);
descriptor->AddOption("AvailableMemory","Set the maximum of available memory for the pipeline execution in mega bytes (optional, 256 by default)","ram", 1, false, otb::ApplicationDescriptor::Integer);
return EXIT_SUCCESS;
}
int ConcatenateImages::Execute(otb::ApplicationOptionsResult* parseResult)
{
unsigned int type = 2; //default to short int as the original
//program
if (parseResult->IsOptionPresent("OutputPixelType"))
{
type = parseResult->GetParameterUInt("OutputPixelType");
}
switch (type)
{
case 1:
generic_main_concatenate<unsigned char> (parseResult);
break;
case 2:
generic_main_concatenate<short int> (parseResult);
break;
case 3:
generic_main_concatenate<int> (parseResult);
break;
case 4:
generic_main_concatenate<float> (parseResult);
break;
case 5:
generic_main_concatenate<double> (parseResult);
break;
case 12:
generic_main_concatenate<unsigned short int> (parseResult);
break;
case 13:
generic_main_concatenate<unsigned int> (parseResult);
break;
default:
generic_main_concatenate<unsigned char> (parseResult);
break;
}
return EXIT_SUCCESS;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment