otbClearCutsMultitemporalDetection.cxx 15.05 KiB
/*=========================================================================
  Copyright (c) IRSTEA. All rights reserved.
     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 "itkFixedArray.h"
#include "itkObjectFactory.h"
// Elevation handler
#include "otbWrapperElevationParametersHandler.h"
#include "otbWrapperApplicationFactory.h"
// Application engine
#include "otbStandardFilterWatcher.h"
#include "itkFixedArray.h"
// LayerStack
#include "otbImageListToVectorImageFilter.h"
#include "otbMultiToMonoChannelExtractROI.h"
#include "otbImageList.h"
// Extract multichannel
#include "otbMultiChannelExtractROI.h"
// Input images list
#include "otbWrapperInputImageListParameter.h"
// Functors for NDVI operations
#include "otbDeltaNDVIFunctor.h"
#include "itkBinaryFunctorImageFilter.h"
#include "otbUnaryFunctorImageFilter.h"
// Mask handler
#include "otbMosaicFromDirectoryHandler.h"
#include "itkMaskImageFilter.h"
// Dates
#include "otbDates.h"
//// Label image filtering
//#include "otbConnectedComponentsFunctorImageFilter.h"
namespace otb
namespace Wrapper
class ClearCutsMultitemporalDetection : public Application
public:
  /** Standard class typedefs. */
  typedef ClearCutsMultitemporalDetection            Self;
  typedef Application                   Superclass;
  typedef itk::SmartPointer<Self>       Pointer;
  typedef itk::SmartPointer<const Self> ConstPointer;
  /** Standard macro */
  itkNewMacro(Self);
  itkTypeMacro(ClearCutsMultitemporalDetection, Application);
  /** Typedefs for image concatenation */
  typedef otb::ImageList<FloatImageType>  ImageListType;
  typedef ImageListToVectorImageFilter<ImageListType, FloatVectorImageType>    ListConcatenerFilterType;
  typedef MultiToMonoChannelExtractROI<FloatVectorImageType::InternalPixelType, FloatImageType::PixelType> ExtractROIFilterType;
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
typedef ObjectList<ExtractROIFilterType> ExtractROIFilterListType; /** Typedefs for temporal correlation */ typedef otb::dates::SingleDate DateType; typedef otb::Functor::MultitemporalCorrelationFunctor<FloatVectorImageType::PixelType, UInt8VectorImageType::PixelType> TemporalCorrelationFunctorType; typedef otb::UnaryFunctorImageFilter<FloatVectorImageType, UInt8VectorImageType, TemporalCorrelationFunctorType> TemporalCorrelationFilterType; /** Typedefs for mask */ typedef itk::MaskImageFilter<FloatVectorImageType, UInt8ImageType, FloatVectorImageType> MaskImageFilterType; typedef otb::MosaicFromDirectoryHandler<UInt8ImageType> MaskHandlerType; // /** Typedefs for label filtering */ // typedef otb::ConnectedComponentsFunctorImageFilter<UInt8VectorImageType> LabelFilterType; void DoUpdateParameters() { // Nothing to do here : all parameters are independent } void DoInit() { // Documentation SetDocName("ClearCutsMultitemporalDetection"); SetDocLongDescription("This application performs of clear cuts detection from " "temporal series."); SetDocLimitations("None"); SetDocAuthors("RemiCresson"); AddDocTag(Tags::FeatureExtraction); // Input time series AddParameter(ParameterType_InputImageList, "il", "Input time series"); // Input time series dates AddParameter(ParameterType_StringList, "dates", "Input time series dates (Must be dd/mm/yyyy format)"); // Input (optional) masks AddParameter(ParameterType_Directory, "masksdir", "Vegetation masks directory"); MandatoryOff("masksdir"); // Backward range parameters AddParameter(ParameterType_Group, "backward", "backward range"); AddParameter(ParameterType_Int, "backward.tmax", "Limit, in number of days, to look backward"); SetMinimumParameterIntValue("backward.tmax",1); MandatoryOff("backward.tmax"); SetDefaultParameterInt("backward.tmax", 2*365); // trees are there since at least 2 years // Forward range parameters AddParameter(ParameterType_Group, "forward", "forward range"); AddParameter(ParameterType_Int, "forward.tmax", "Limit, in number of days, to look forward"); SetMinimumParameterIntValue("forward.tmax",1); MandatoryOff("forward.tmax"); SetDefaultParameterInt("forward.tmax", 2*31); // 3 months before growing again? (too much?) // clouds flag detection AddParameter(ParameterType_Group, "clouds", "clouds detection"); AddParameter(ParameterType_Float, "clouds.threshold", "Clouds drop threshold"); MandatoryOff("clouds.threshold"); SetDefaultParameterFloat("clouds.threshold", 0.4); AddParameter(ParameterType_Int, "clouds.tmax", "Limit, in number of days, for rejecting NDVI drop due to clouds."); MandatoryOff("clouds.tmax"); SetDefaultParameterInt("clouds.tmax", 3*31); // Accorded to literature, 20 days is a good value // Detection range AddParameter(ParameterType_Group, "range", "detection range"); AddParameter(ParameterType_Group, "range.start", "detection range start"); AddParameter(ParameterType_Int, "range.start.day", "Detection range start (day)"); MandatoryOff("range.start.day"); SetDefaultParameterInt("range.start.day", 1);
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
AddParameter(ParameterType_Int, "range.start.month", "Detection range start (month)"); MandatoryOff("range.start.month"); SetDefaultParameterInt("range.start.month", 5); // May AddParameter(ParameterType_Group, "range.end", "detection range end"); AddParameter(ParameterType_Int, "range.end.day", "Detection range end (day)"); MandatoryOff("range.end.day"); SetDefaultParameterInt("range.end.day", 31); AddParameter(ParameterType_Int, "range.end.month", "Detection range end (month)"); MandatoryOff("range.end.month"); SetDefaultParameterInt("range.end.month", 8); // August // Input nodata AddParameter(ParameterType_Float, "nodata", "Input NDVI no-data value"); MandatoryOff("nodata"); SetDefaultParameterInt("nodata", -2.0); // Output image AddParameter(ParameterType_OutputImage, "out", "Output labels image"); SetDefaultOutputPixelType("out", ImagePixelType_uint8); // // Objects filtering // AddParameter(ParameterType_Int, "minsize", "Minimum size of detected clear cuts in pixels"); // MandatoryOff("minsize"); // SetMinimumParameterIntValue("minsize",1); // SetDefaultParameterInt("minsize", 5); AddRAMParameter(); } /* * Retrieve the dates (numeric) from the input dates (string) dd/mm/yyyy */ std::vector<DateType> GetTimeSeriesDates() { std::vector<std::string> list = this->GetParameterStringList("dates"); std::vector<DateType> dates = otb::dates::GetDatesFromStringVector(list); otbAppLogINFO("Using " << dates.size() << " input dates from " << list[0] << " to " << list[list.size()-1] ); return dates; } // // void testFunctor() // { // std::vector<DateType> dates; // FloatVectorImageType::PixelType p,y; // p.SetSize(42); // y.SetSize(42); // p[0]=-2; // dates.push_back(DateType(2015,5,8)); // p[1]=-2; // dates.push_back(DateType(2015,5,10)); // p[2]=-2; // dates.push_back(DateType(2015,5,17)); // p[3]=-2; // dates.push_back(DateType(2015,5,24)); // p[4]=-2; // dates.push_back(DateType(2015,5,26)); // p[5]=0.23809523880481719970703125; // dates.push_back(DateType(2015,6,2)); // p[6]=-2; // dates.push_back(DateType(2015,6,9)); // p[7]=-2; // dates.push_back(DateType(2015,6,11)); // p[8]=0.18518517911434173583984375; // dates.push_back(DateType(2015,6,18)); // p[9]=-2; // dates.push_back(DateType(2015,6,25));