Commit d960fd01 authored by remi cresson's avatar remi cresson
Browse files

ADD: binary and ternary functors + dates classes

parents
project(TimeSeriesUtils)
otb_module_impl()
This diff is collapsed.
Summary
=======
This module provides one application dedicated to clear cuts detection
Clear cuts detection
----------------------------
This application implements the clear cuts detection pipeline, developed by IRSTEA (Kenji Ose, Michel Deshayes, Rémi Cresson)
###Method###
From a pair of images, (each one aquired at a different date), and an optional forest mask, dNDVI (the difference of the normalized difference vegetation index) is computed. Then, mean and standard deviation are both computed from this resulting image. The last step is the multiple thresholding of dNDVI (based on mean and standard deviation) in order to produce a map of detected clear cuts confidence. The actual values can be 0,1,2 or 3 (A value equals to 3 beeing the most high NDVI difference range, i.e. the most realistic clear cut detection).
Licence
=======
This code is provided under the CeCILL-B free software license agreement.
Contact
=======
For any issues regarding this module please contact Rémi Cresson.
remi.cresson@teledetection.fr
Irstea ((French) National Research Institute of Science and Technology for Environment and Agriculture)
www.irstea.fr
/*=========================================================================
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.
=========================================================================*/
#ifndef otbBinaryFunctorImageFilter_h
#define otbBinaryFunctorImageFilter_h
#include "itkBinaryFunctorImageFilter.h"
namespace otb
{
/**
* \class BinaryFunctorImageFilter
* \brief Implements pixel-wise generic operation on two images.
*
* Add the capability to change the number of channel when operation on
* VectorImage compared to the itk::BinaryFunctorImageFilter
*
* The number of channel is provided by the functor: TFunction::OutputSize. If
* this number is lower or equal to zero, the behavior of the itk::BinaryFunctorImageFilter
* remains unchanged.
*
* \sa itk::BinaryFunctorImageFilter
*
* \ingroup OTBCommon
*/
template <class TInputImage1, class TInputImage2, class TOutputImage, class TFunction>
class ITK_EXPORT BinaryFunctorImageFilter : public itk::BinaryFunctorImageFilter<TInputImage1, TInputImage2, TOutputImage, TFunction>
{
public:
/** Standard class typedefs. */
typedef BinaryFunctorImageFilter Self;
typedef itk::BinaryFunctorImageFilter<TInputImage1, TInputImage2, TOutputImage, TFunction> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(BinaryFunctorImageFilter, itk::BinaryFunctorImageFilter);
protected:
BinaryFunctorImageFilter() {};
~BinaryFunctorImageFilter() ITK_OVERRIDE {}
/** BinaryFunctorImageFilter can produce an image which has a different number of bands
* than its input image. As such, BinaryFunctorImageFilter
* needs to provide an implementation for
* GenerateOutputInformation() in order to inform the pipeline
* execution model. The original documentation of this method is
* below.
*
* \sa ProcessObject::GenerateOutputInformaton() */
void GenerateOutputInformation() ITK_OVERRIDE
{
Superclass::GenerateOutputInformation();
typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
outputPtr->SetNumberOfComponentsPerPixel( // propagate vector length info
this->GetFunctor().GetOutputSize());
}
private:
BinaryFunctorImageFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
};
} // end namespace otb
#endif
/*
* otbDates.h
*
* Created on: 3 août 2017
* Author: cresson
*/
#ifndef MODULES_REMOTE_TIMESERIESUTILS_INCLUDE_OTBDATES_H_
#define MODULES_REMOTE_TIMESERIESUTILS_INCLUDE_OTBDATES_H_
#include "boost/date_time/gregorian/gregorian.hpp"
#include "boost/math/distributions/students_t.hpp"
#include "assert.h"
#include <vector>
#include <stdexcept>
namespace otb
{
namespace dates
{
/*
* \class SingleDate
*
* \brief Class to handle dates. Julian day is computed at instantiation.
*
*/
class SingleDate
{
public:
SingleDate(int yyyy, int mm, int dd){
year = yyyy;
day = dd;
month = mm;
// Compute julianday
boost::gregorian::date d(yyyy, mm, dd);
julianday = d.julian_day();
}
~SingleDate (){}
bool IsInRange(const int& startMonth,const int& startDay,const int& endMonth, const int& endDay) const
{
if (startMonth < month && month < endMonth)
{
return true;
}
else if (startMonth == month && startDay <= day)
{
return true;
}
else if (endMonth == month && day <= endDay)
{
return true;
}
else
{
return false;
}
}
int day;
int month;
int year;
int julianday;
};
/*
* Retrieve the dates (numeric) from the input dates (string) dd/mm/yyyy
*/
std::vector<SingleDate> GetDatesFromStringVector(std::vector<std::string> list, bool check_order = true){
std::vector<SingleDate> dates;
for (unsigned int i = 0 ; i < list.size() ; i++)
{
if (list[i].size()<=10)
{
int yyyy = std::stoi( list[i].substr(0,4) );
int mm = std::stoi( list[i].substr(5,2) );
int dd = std::stoi( list[i].substr(8,2) );
// Check values ranges
assert (1950 > yyyy);
assert (0 >= mm || mm > 12);
int nbOfDaysInMonth[12] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
assert (0 >= dd || dd > nbOfDaysInMonth[mm-1]);
// Add new date
SingleDate d(yyyy, mm, dd);
dates.push_back(d);
}
}
// Check dates ordering
if (check_order)
{
for (unsigned int i = 0 ; i < list.size()-1 ; i++)
{
assert (dates[i+1].julianday < dates[i].julianday);
}
}
// return output
return dates;
}
} // namespace dates
} // namespace otb
#endif /* MODULES_REMOTE_TIMESERIESUTILS_INCLUDE_OTBDATES_H_ */
/*=========================================================================
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.
=========================================================================*/
#ifndef otbTernaryFunctorImageFilter_h
#define otbTernaryFunctorImageFilter_h
#include "itkTernaryFunctorImageFilter.h"
namespace otb
{
/**
* \class TernaryFunctorImageFilter
* \brief Implements pixel-wise generic operation on three images.
*
* Add the capability to change the number of channel when operation on
* VectorImage compared to the itk::TernaryFunctorImageFilter
*
* The number of channel is provided by the functor: TFunction::OutputSize. If
* this number is lower or equal to zero, the behavior of the itk::TernaryFunctorImageFilter
* remains unchanged.
*
* \sa itk::TernaryFunctorImageFilter
*
* \ingroup OTBCommon
*/
template <class TInputImage1, class TInputImage2, class TInputImage3, class TOutputImage, class TFunction>
class ITK_EXPORT TernaryFunctorImageFilter : public itk::TernaryFunctorImageFilter<TInputImage1, TInputImage2, TInputImage3, TOutputImage, TFunction>
{
public:
/** Standard class typedefs. */
typedef TernaryFunctorImageFilter Self;
typedef itk::TernaryFunctorImageFilter<TInputImage1, TInputImage2, TInputImage3, TOutputImage, TFunction> Superclass;
typedef itk::SmartPointer<Self> Pointer;
typedef itk::SmartPointer<const Self> ConstPointer;
/** Method for creation through the object factory. */
itkNewMacro(Self);
/** Run-time type information (and related methods). */
itkTypeMacro(TernaryFunctorImageFilter, itk::TernaryFunctorImageFilter);
protected:
TernaryFunctorImageFilter() {};
~TernaryFunctorImageFilter() ITK_OVERRIDE {}
/** TernaryFunctorImageFilter can produce an image which has a different number of bands
* than its input image. As such, TernaryFunctorImageFilter
* needs to provide an implementation for
* GenerateOutputInformation() in order to inform the pipeline
* execution model. The original documentation of this method is
* below.
*
* \sa ProcessObject::GenerateOutputInformaton() */
void GenerateOutputInformation() ITK_OVERRIDE
{
Superclass::GenerateOutputInformation();
typename Superclass::OutputImagePointer outputPtr = this->GetOutput();
outputPtr->SetNumberOfComponentsPerPixel( // propagate vector length info
this->GetFunctor().GetOutputSize());
}
private:
TernaryFunctorImageFilter(const Self &); //purposely not implemented
void operator =(const Self&); //purposely not implemented
};
} // end namespace otb
#endif
set(DOCUMENTATION "Time Series Utils")
otb_module(TimeSeriesUtils
DEPENDS
OTBIndices
OTBStatistics
TEST_DEPENDS
OTBTestKernel
OTBCommandLine
DESCRIPTION
$DOCUMENTATION
)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment