Commit 862f60c2 authored by Thierry Koleck's avatar Thierry Koleck
Browse files

Add the MultitempFilterinb OTB application

parent 20d3c75b
cmake_minimum_required(VERSION 2.8.9)
project(SARMultiTempFiltering)
#set(DiapOTBModule_LIBRARIES DiapOTBModule)
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fopenmp")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp")
if(NOT OTB_SOURCE_DIR)
find_package(OTB REQUIRED)
list(APPEND CMAKE_MODULE_PATH ${OTB_CMAKE_DIR})
include(OTBModuleExternal)
else()
otb_module_impl()
endif()
To install this module in your OTB, create a file ```SARMultiTempFiltering.remote.cmake```
in your otb_install_dir/Modules/Remote directory.
Then copy the following text in the file:
```
otb_fetch_module(SARMultiTempFiltering
"
A more detailed description can be found on the project website:
http://tully.ups-tlse.fr/koleckt/otbsarmultitempfiltering.git
"
GIT_REPOSITORY http://tully.ups-tlse.fr/koleckt/otbsarmultitempfiltering.git
# Commit on master branch
GIT_TAG master
)
```
#
# Copyright (C) 2005-2017 Centre National d'Etudes Spatiales (CNES)
#
# This file is part of Orfeo Toolbox
#
# https://www.orfeo-toolbox.org/
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#Contact: Thierry Koleck <thierry.koleck@cnes.fr>
otb_fetch_module(SARMultiTempFiltering
"Speckle filtering of a time-serie of SAR images using the multichanel Quegan-like filter
A more detailed description can be found on the project website:
http://tully.ups-tlse.fr/koleckt/otbsarmultitempfiltering.git
"
GIT_REPOSITORY http://tully.ups-tlse.fr/koleckt/otbsarmultitempfiltering.git
# Commit on master branch
GIT_TAG master
)
otb_create_application(
NAME MultitempFiltering
SOURCES otbMultitempFiltering.cxx
LINK_LIBRARIES ${${otb-module}_LIBRARIES})
otb_create_application(
NAME MultitempFilteringOutcore
SOURCES otbMultitempFilteringOutcore.cxx
LINK_LIBRARIES ${${otb-module}_LIBRARIES})
otb_create_application(
NAME MultitempFilteringFilter
SOURCES otbMultitempFilteringFilter.cxx
LINK_LIBRARIES ${${otb-module}_LIBRARIES})
/*=========================================================================
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 "otbOutcoreFilter.h"
#include "otbMultiplyVectorImageFilter.h"
#include "itkAddImageFilter.h"
#include "otbImage.h"
#include "otbImageList.h"
#include "itkBinaryFunctorImageFilter.h"
#include <itkVariableLengthVector.h>
#include "otbMultiplyVectorImageFilter.h"
#include "otbObjectList.h"
#include "otbMeanFilter.h"
#include "otbImageFileWriter.h"
//#include "boost/filesystem/path.hpp"
namespace otb
{
namespace Wrapper
{
class MultitempFiltering : public Application
{
public:
/** Standard class typedefs. */
typedef MultitempFiltering Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef ImageList<FloatVectorImageType> ImageListType;
typedef itk::AddImageFilter<FloatVectorImageType,FloatVectorImageType,FloatVectorImageType> AddImageFilterType;
typedef typename otb::MultiplyVectorImageFilter<FloatVectorImageType,FloatVectorImageType,FloatVectorImageType> MultiplyVectorImageFilterType;
typedef otb::ImageFileWriter<FloatVectorImageType> WriterType;
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(MultitempFiltering, otb::Application);
typedef OutcoreFilter<FloatVectorImageType,FloatVectorImageType> OutcoreFilterType;
typedef MeanFilter<FloatVectorImageType,FloatVectorImageType> MeanFilterType;
private:
void DoInit()
{
SetName("MultitempFiltering");
SetDescription("");
// Documentation
SetDocName("MultitempFiltering");
SetDocLongDescription("" );
SetDocLimitations("None");
SetDocAuthors("Thierry Koleck (CNES)");
SetDocSeeAlso("");
AddDocTag(Tags::SAR);
AddParameter(ParameterType_InputImageList, "inl", "Input images list");
SetParameterDescription("inl", "Input image list");
AddParameter(ParameterType_Int , "wr", "Spatial averaging Window radius ");
SetParameterDescription("wr", "Window radius");
//AddParameter(ParameterType_OutputImage, "out", "Output name");
//SetParameterDescription("out", "Output name");
AddRAMParameter();
// Default values
}
void DoUpdateParameters()
{
// Nothing to do here : all parameters are independent
}
void DoExecute()
{
int Radius = this->GetParameterInt("wr");
FloatVectorImageListType::Pointer inList = this->GetParameterImageList("inl");
// On verifie que la liste en entree n'est pas vide
std::cout << inList->Size() << "\n";
if( inList->Size() == 0 )
{
itkExceptionMacro("No input Image set...");
}
std::vector< std::string> filelist;
filelist=this->GetParameterStringList("inl");
//boost::filesystem::path my_path(filelist[0]);
//std::cout<< my_path.string();
inList->GetNthElement(0)->UpdateOutputInformation();
// Recupere la taille de l'image
// Initialise le filtre de calcul du outcore
m_AddImageFilter=AddImageFilterType::New();
FilterList=otb::ObjectList<itk::ImageToImageFilter<FloatVectorImageType,FloatVectorImageType> >::New();
OutcoreFilterType::Pointer m_OutcoreFilter;
m_OutcoreFilter=OutcoreFilterType::New();
m_OutcoreFilter->SetInput(inList->GetNthElement(0));
m_OutcoreFilter->SetRadius(Radius);
m_OutcoreFilter->UpdateOutputInformation();
FilterList->PushBack(m_OutcoreFilter);
for( unsigned int i=1; i<inList->Size(); i++ ) {
m_OutcoreFilter=OutcoreFilterType::New();
m_OutcoreFilter->SetInput(inList->GetNthElement(i));
m_OutcoreFilter->SetRadius(Radius);
m_OutcoreFilter->UpdateOutputInformation();
m_AddImageFilter=AddImageFilterType::New();
m_AddImageFilter->SetInput1(m_OutcoreFilter->GetOutput());
m_AddImageFilter->SetInput2(FilterList->GetNthElement(2*i-1)->GetOutput());
m_AddImageFilter->UpdateOutputInformation();
FilterList->PushBack(m_OutcoreFilter);
FilterList->PushBack(m_AddImageFilter);
}
m_MultiplyByConstImageFilter=MultiplyVectorImageFilterType::New();
m_MultiplyByConstImageFilter->SetInput(FilterList->Back()->GetOutput());
itk::VariableLengthVector<float> constante=itk::VariableLengthVector<float>(1);
constante.Fill(1./inList->Size());
m_MultiplyByConstImageFilter->SetConstant(constante);
FilterList->PushBack(m_MultiplyByConstImageFilter);
// Calcul des images de sortie
m_MultiplyByOutcoreImageFilter=MultiplyVectorImageFilterType::New();
m_MeanImageFilter=MeanFilterType::New();
WriterType::Pointer writer = WriterType::New();
for( unsigned int i=0; i<inList->Size(); i++ )
{
m_MeanImageFilter->SetInput(inList->GetNthElement(i));
//FloatVectorImageType::SizeType indexRadius;
m_MeanImageFilter->SetRadius(Radius);
m_MeanImageFilter->UpdateOutputInformation();
m_MultiplyByOutcoreImageFilter=MultiplyVectorImageFilterType::New();
m_MultiplyByOutcoreImageFilter->SetInput1(m_MeanImageFilter->GetOutput());
m_MultiplyByOutcoreImageFilter->SetInput2(m_MultiplyByConstImageFilter->GetOutput());
m_MultiplyByOutcoreImageFilter->UpdateOutputInformation();
// Definit le nom du fichier de sortie (images filtrees)
std::ostringstream oss;
size_t lastindex = filelist[i].find_last_of(".");
size_t lastindex2 = filelist[i].find_last_of("/");
std::string rawname = filelist[i].substr(0, lastindex);
oss << filelist[i].substr(0,lastindex2)<<"/filtered"<<filelist[i].substr(lastindex2,lastindex-lastindex2) << "_filtered" <<filelist[i].substr(lastindex);
//OutputImageParameter::Pointer paramOut = OutputImageParameter::New();
// writer label
std::ostringstream osswriter;
osswriter<< "writer (File : "<< i<<")";
/*
// Set the filename of the current output image
paramOut->SetFileName(oss.str());
otbAppLogINFO(<< "File: "<<paramOut->GetFileName() << " will be written.");
//paramOut->SetValue(m_MultiplyByOutcoreImageFilter->GetOutput());
paramOut->SetValue(m_MeanImageFilter->GetOutput());
//paramOut->SetValue(inList->GetNthElement(i));
paramOut->SetPixelType(this->GetParameterOutputImagePixelType("out"));
std::cout << this->GetParameterOutputImagePixelType("out") << "\n";
// Add the current level to be written
paramOut->InitializeWriters();
AddProcess(paramOut->GetWriter(), osswriter.str());
paramOut->Write();
*/
writer->SetFileName(oss.str());
writer->SetInput(m_MultiplyByOutcoreImageFilter->GetOutput());
otbAppLogINFO(<< "File: "<<writer->GetFileName() << " will be written.");
AddProcess(writer, osswriter.str());
writer->Update();
}
//SetParameterOutputImage("out", m_MultiplyByOutcoreImageFilter->GetOutput());
}
otb::ObjectList<itk::ImageToImageFilter<FloatVectorImageType,FloatVectorImageType> >::Pointer FilterList;
AddImageFilterType::Pointer m_AddImageFilter;
MultiplyVectorImageFilterType::Pointer m_MultiplyByOutcoreImageFilter;
MultiplyVectorImageFilterType::Pointer m_MultiplyByConstImageFilter;
MeanFilterType::Pointer m_MeanImageFilter;
};
} //end namespace Wrapper
} //end namespace otb
OTB_APPLICATION_EXPORT(otb::Wrapper::MultitempFiltering)
/*=========================================================================
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 "otbMultiplyVectorImageFilter.h"
#include "otbImageList.h"
#include "otbMultiplyVectorImageFilter.h"
#include "otbMeanFilter.h"
#include "otbImageFileWriter.h"
#include "otbMultiToMonoChannelExtractROI.h"
#include <iostream>
namespace otb
{
namespace Wrapper
{
class MultitempFilteringFilter : public Application
{
public:
/** Standard class typedefs. */
typedef MultitempFilteringFilter Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef ImageList<FloatVectorImageType> ImageListType;
typedef typename otb::MultiplyVectorImageFilter<FloatVectorImageType,FloatVectorImageType,FloatVectorImageType> MultiplyVectorImageFilterType;
typedef otb::ImageFileWriter<FloatVectorImageType> WriterType;
typedef otb::MultiToMonoChannelExtractROI<FloatVectorImageType::InternalPixelType,
FloatVectorImageType::InternalPixelType> ExtractChannelFilterType;
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(MultitempFilteringFilter, otb::Application);
typedef MeanFilter<FloatVectorImageType,FloatVectorImageType> MeanFilterType;
private:
void DoInit()
{
SetName("MultitempFilteringFilter");
SetDescription("");
// Documentation
SetDocName("MultitempFilteringFilter");
SetDocLongDescription("This application implement the Quegan speckle filter for SAR images. It applies the outcore to a list of images. The outcore is genenerated by the MultitempFilteringOutcore application" );
SetDocLimitations("None");
SetDocAuthors("Thierry Koleck (CNES)");
SetDocSeeAlso("MultitempFilteringOutcore");
AddDocTag(Tags::SAR);
AddParameter(ParameterType_InputImageList, "inl", "Input images list");
SetParameterDescription("inl", "Input image list");
AddParameter(ParameterType_Int , "wr", "Spatial averaging Window radius ");
SetParameterDescription("wr", "Window radius");
AddParameter(ParameterType_InputImage, "oc", "Outcore filename");
SetParameterDescription("oc", "Outcore filename");
AddParameter(ParameterType_OutputImage, "enl", "ENL filename");
SetParameterDescription("enl", "Number of images averaged");
AddRAMParameter();
}
void DoUpdateParameters()
{
// Nothing to do here : all parameters are independent
}
void DoExecute()
{
int Radius = this->GetParameterInt("wr");
FloatVectorImageListType::Pointer inList = this->GetParameterImageList("inl");
// On verifie que la liste en entree n'est pas vide
std::cout << inList->Size() << "\n";
if( inList->Size() == 0 )
{
itkExceptionMacro("No input Image set...");
}
std::vector< std::string> filelist;
filelist=this->GetParameterStringList("inl");
inList->GetNthElement(0)->UpdateOutputInformation();
// Recupere la taille de l'image
// Initialise le filtre de calcul du outcore
FloatVectorImageType::Pointer Outcore = GetParameterFloatVectorImage("oc");
// Calcul des images de sortie
m_MultiplyByOutcoreImageFilter=MultiplyVectorImageFilterType::New();
m_MeanImageFilter=MeanFilterType::New();
m_MultiplyByOutcoreImageFilter=MultiplyVectorImageFilterType::New();
for( unsigned int i=0; i<inList->Size(); i++ )
{
m_MeanImageFilter->SetInput(inList->GetNthElement(i));
m_MeanImageFilter->SetRadius(Radius);
m_MeanImageFilter->UpdateOutputInformation();
m_MultiplyByOutcoreImageFilter->SetInput1(m_MeanImageFilter->GetOutput());
m_MultiplyByOutcoreImageFilter->SetInput2(Outcore);
m_MultiplyByOutcoreImageFilter->UpdateOutputInformation();
// Definit le nom du fichier de sortie (images filtrees)
std::ostringstream oss;
if(filelist[i].find("/") != std::string::npos)
{
size_t lastindex = filelist[i].find_last_of(".");
size_t lastindex2 = filelist[i].find_last_of("/");
oss << filelist[i].substr(0,lastindex2)<<"/filtered"<<filelist[i].substr(lastindex2,lastindex-lastindex2) << "_filtered" <<filelist[i].substr(lastindex);
} else {
size_t lastindex = filelist[i].find_last_of(".");
oss << "filtered"<<filelist[i].substr(0,lastindex) << "_filtered" <<filelist[i].substr(lastindex);
}
// writer label
WriterType::Pointer writer = WriterType::New();
writer->SetFileName(oss.str());
writer->SetInput(m_MultiplyByOutcoreImageFilter->GetOutput());
AddProcess(writer, writer->GetFileName());
writer->Update();
}
m_Filter = ExtractChannelFilterType::New();
m_Filter->SetInput(Outcore);
m_Filter->SetChannel(Outcore->GetVectorLength());
m_Filter->UpdateOutputInformation();
SetParameterOutputImage("enl", m_Filter->GetOutput());
SetParameterOutputImagePixelType("enl",ImagePixelType_uint16);
}
MultiplyVectorImageFilterType::Pointer m_MultiplyByOutcoreImageFilter;
MeanFilterType::Pointer m_MeanImageFilter;
ExtractChannelFilterType::Pointer m_Filter;
};
} //end namespace Wrapper
} //end namespace otb
OTB_APPLICATION_EXPORT(otb::Wrapper::MultitempFilteringFilter)
/*=========================================================================
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 "otbOutcoreFilter.h"
#include "otbMultiplyVectorImageFilter.h"
#include "itkAddImageFilter.h"
#include "otbImageList.h"
#include <itkVariableLengthVector.h>
#include "otbObjectList.h"
namespace otb
{
namespace Wrapper
{
class MultitempFilteringOutcore : public Application
{
public:
/** Standard class typedefs. */
typedef MultitempFilteringOutcore Self;
typedef Application Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
typedef ImageList<FloatImageType> ImageListType;
typedef itk::AddImageFilter<FloatVectorImageType,FloatVectorImageType,FloatVectorImageType> AddVectorImageFilterType;
typedef typename otb::MultiplyVectorImageFilter<FloatVectorImageType,FloatVectorImageType,FloatVectorImageType> MultiplyVectorImageFilterType;
typedef OutcoreFilter<FloatVectorImageType,FloatVectorImageType> OutcoreFilterType;
/** Standard macro */
itkNewMacro(Self);
itkTypeMacro(MultitempFilteringOutcore, otb::Wrapper::Application);
private:
void DoInit() ITK_OVERRIDE
{
SetName("MultitempFilteringOutcore");
SetDescription("This application implements the Quegan speckle filter for SAR images. It computes the outcore function of the filter. It must be followed by the MultitempFilteringFilter application to compute the filtered images");
// Documentation
SetDocName("MultitempFilteringOutcore");
SetDocLongDescription("This application implements the Quegan speckle filter for SAR images. It computes the outcore function of the filter. It must be followed by the MultitempFilteringFilter application to compute the filtered images" );
SetDocLimitations("None");
SetDocAuthors("Thierry Koleck (CNES), Marie Ballere (CNES)");
SetDocSeeAlso("MultitempFilteringFilter");
AddDocTag(Tags::SAR);
AddParameter(ParameterType_InputImageList, "inl", "Input images list");
SetParameterDescription("inl", "Input image list");
AddParameter(ParameterType_Int , "wr", "Spatial averaging Window radius ");
SetParameterDescription("wr", "Window radius");
AddParameter(ParameterType_OutputImage, "oc", "Outcore filename");
SetParameterDescription("oc", "Outcore filename");
AddRAMParameter();
// Default values
}
void DoUpdateParameters() ITK_OVERRIDE
{
// Nothing to do here : all parameters are independent
}
void DoExecute() ITK_OVERRIDE
{
AddVectorImageFilterType::Pointer m_AddImageFilter;
MultiplyVectorImageFilterType::Pointer m_MultiplyByConstImageFilter;
OutcoreFilterType::Pointer m_OutcoreFilter;
int Radius = this->GetParameterInt("wr");
FloatVectorImageListType::Pointer inList = this->GetParameterImageList("inl");
// On verifie que la liste en entree n'est pas vide
std::cout << inList->Size() << "\n";
if( inList->Size() == 0 )
{
itkExceptionMacro("No input Image set...");
}
std::vector< std::string> filelist;
filelist=this->GetParameterStringList("inl");
inList->GetNthElement(0)->UpdateOutputInformation();
FilterList=otb::ObjectList<itk::ImageToImageFilter<FloatVectorImageType,FloatVectorImageType> >::New();
m_AddImageFilter=AddVectorImageFilterType::New();