Commit 92e0b671 authored by Cédric Traizet's avatar Cédric Traizet

Merge remote-tracking branch 'lhermitte/S1TilingApps' into release-7.2

parents acb91cf0 de0bdbff
......@@ -70,7 +70,7 @@ if(XDK_PATH)
set(cmake_configure_option
"${cmake_configure_option}
CMAKE_PREFIX_PATH=${XDK_PATH}")
foreach(remote_module OTBTemporalGapFilling SertitObject otbGRM DiapOTBModule)
foreach(remote_module OTBTemporalGapFilling SertitObject otbGRM DiapOTBModule S1TilingSupportApplications)
set(cmake_configure_option
"${cmake_configure_option}
Module_${remote_module}:BOOL=ON")
......
......@@ -92,3 +92,13 @@ OTB_CREATE_APPLICATION(
NAME Mosaic
SOURCES otbMosaic.cxx
LINK_LIBRARIES ${${otb-module}_LIBRARIES})
OTB_CREATE_APPLICATION(
NAME ResetMargin
SOURCES otbResetMargin.cxx
LINK_LIBRARIES ${${otb-module}_LIBRARIES})
OTB_CREATE_APPLICATION(
NAME Synthetize
SOURCES otbSynthetize.cxx
LINK_LIBRARIES ${${otb-module}_LIBRARIES})
/*
* Copyright (C) 2005-2020 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.
*/
#include "otbResetMarginFilter.h"
#include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
namespace otb
{
namespace Wrapper
{
/**
* Application that fills margins to 0.
*
* This application is similar to ExtractROI with the difference the margin is
* kept, and filled with 0.
*
* This application is used to implement the _cut_ processing in S1Tiling
* chain.
*
* \author Luc Hermitte (CS Group)
* \copyright CNES
*/
class ResetMargin : public Application
{
public:
using Self = ResetMargin;
using Pointer = itk::SmartPointer<Self>;
itkNewMacro(Self);
itkTypeMacro(ResetMargin, otb::Wrapper::Application);
private:
void DoInit() override
{
SetName("ResetMargin");
SetDescription("This is the ResetMargin application");
SetDocLongDescription(
"This application is similar to ExtractROI in the sense it extracts a Region of Interrest.\n"
"However, the region outside of the ROI isn't trimmed, but set to 0.\n"
"\n"
"The filter set lines of index < threshold.y, and of index >= threshold.y to 0\n"
"The filter set columns of index < threshold.x, and of index >= threshold.x to 0");
SetDocLimitations("This application only works on scalar (and complex) images.");
SetDocAuthors("Luc Hermitte (CS Group)");
SetDocSeeAlso("ManageNoData, ExtractROI");
AddDocTag(Tags::Manip);
AddParameter(ParameterType_InputImage, "in", "Input image");
SetParameterDescription("in", "Scalar Input image");
AddParameter(ParameterType_OutputImage, "out", "Output Image");
SetParameterDescription("out", "Scalar Output image");
AddParameter(ParameterType_Group, "threshold", "threshold group");
AddParameter(ParameterType_Group, "threshold.y", "threshold group");
MandatoryOff("threshold");
MandatoryOff("threshold.y");
AddParameter(ParameterType_Int, "threshold.x", "Column index threshold");
SetParameterDescription("threshold.x", "Column index threshold");
SetDefaultParameterInt("threshold.x", 0);
AddParameter(ParameterType_Int, "threshold.y.start", "Top line index threshold");
SetParameterDescription("threshold.y.start", "Top line index threshold");
SetDefaultParameterInt("threshold.y.start", 0);
AddParameter(ParameterType_Int, "threshold.y.end", "Bottom line index threshold");
SetParameterDescription("threshold.y.end", "Bottom line index threshold");
SetDefaultParameterInt("threshold.y.end", 0);
SetMinimumParameterIntValue("threshold.x", 0);
SetMinimumParameterIntValue("threshold.y.start", 0);
SetMinimumParameterIntValue("threshold.y.end", 0);
AddRAMParameter();
SetDocExampleParameterValue("in", "ResetMarginInput100x100.tiff");
SetDocExampleParameterValue("threshold.x", "10");
SetDocExampleParameterValue("threshold.y.start", "12");
SetDocExampleParameterValue("threshold.y.end", "25");
SetDocExampleParameterValue("out", "ResetMargin.tiff");
SetOfficialDocLink();
}
void DoUpdateParameters() override
{}
void DoExecute() override
{
auto const thrX = GetParameterInt("threshold.x");
auto const thrYtop = GetParameterInt("threshold.y.start");
auto const thrYbot = GetParameterInt("threshold.y.end");
if (thrX < 0)
itkExceptionMacro("The column threshold is expected to be positive");
if (thrYtop < 0)
itkExceptionMacro("The top line threshold is expected to be positive");
if (thrYbot < 0)
itkExceptionMacro("The bottom line threshold is expected to be positive");
if (thrX == 0 && thrYtop == 0 && thrYbot == 0)
itkExceptionMacro("Don't use ResetMargin to clamp nothing!");
auto filter = ResetMarginFilter<FloatImageType>::New();
assert(thrX >= 0);
assert(thrYtop >= 0);
assert(thrYbot >= 0);
filter->SetThresholdX(thrX);
filter->SetThresholdYtop(thrYtop);
filter->SetThresholdYbot(thrYbot);
filter->SetInput(GetParameterFloatImage("in"));
SetParameterOutputImage("out", filter->GetOutput());
RegisterPipeline();
}
};
} // otb::Wrapper namespace
} // otb namespace
OTB_APPLICATION_EXPORT(otb::Wrapper::ResetMargin)
/*
* Copyright (C) 2005-2020 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.
*/
#include "otbSynthetizeFilter.h"
#include "otbWrapperApplication.h"
#include "otbWrapperApplicationFactory.h"
#include "otbImageFileReader.h"
#include <set>
namespace otb
{
namespace Wrapper
{
/**
* This application synthetizes/reduces multiple inputs into a single one.
* In that particular case, for each output pixel, this application will
* consider the corresponding pixels from all the input images, and keep the
* first one that isn't equal to 0.
*
* This application is used to implement the _concatenate_ processing in
* S1Tiling chain.
*
* \author Luc Hermitte (CS Group)
* \copyright CNES
* \todo find a better name for the application. Alas `otbConcatenate` is
* already used...
*/
class Synthetize : public Application
{
public:
using Self = Synthetize;
using Pointer = itk::SmartPointer<Self>;
itkNewMacro(Self);
itkTypeMacro(Synthetize, otb::Wrapper::Application);
private:
using ReaderType = otb::ImageFileReader<FloatImageType>;
void DoInit() override
{
SetName("Synthetize");
SetDescription("This is the Synthetize application");
SetDocLongDescription("Concatenate a list of images of the same size into a single single-channel image.\n\
It keeps the first non-null pixel value found in the input list.");
SetDocLimitations("This application will break incoming pipelines.");
SetDocAuthors("Luc Hermitte (CS Group)");
SetDocSeeAlso("");
AddDocTag(Tags::Manip);
AddParameter(ParameterType_StringList, "il", "Input images list");
SetParameterDescription("il", "Input image list");
AddParameter(ParameterType_OutputImage, "out", "Output Image");
SetParameterDescription("out","Output image.");
AddRAMParameter();
SetDocExampleParameterValue("il", "s1a_33NWB_vv_DES_007_20200108t044150.tif s1a_33NWB_vv_DES_007_20200108t044215.tif");
SetDocExampleParameterValue("out", "s1a_33NWB_vv_DES_007_20200108txxxxxx.tif");
SetOfficialDocLink();
}
void DoUpdateParameters() override
{}
void DoExecute() override
{
// Get the input image list
auto inNameList = GetParameterStringList("il");
// checking the input images list validity
auto const nbImages = inNameList.size();
if (nbImages == 0)
{
itkExceptionMacro("No input Image set...; please set at least one input image");
}
auto functor = [](auto input) {
assert(!input.empty());
auto const wh = std::find_if(
input.begin(), input.end()-1,
[](auto v){ return v != 0;});
return *wh;
};
auto filter = MakeSynthetizeFilter<FloatImageType, FloatImageType>(functor);
for (unsigned int i = 0; i < nbImages; i++)
{
// Given the explicit use of a Reader, this application cannot be used in
// a in-memory pipeline
auto reader = ReaderType::New();
// currentImage->SetExtendedFileName(inNameList[i]);
reader->SetFileName(inNameList[i]);
auto currentImage = reader->GetOutput();
currentImage->UpdateOutputInformation();
otbAppLogINFO(<< "Image #" << i + 1 << " has " << currentImage->GetNumberOfComponentsPerPixel() << " components");
filter->SetInput(i, currentImage);
m_Cache.insert(reader);
}
SetParameterOutputImage("out", filter->GetOutput());
RegisterPipeline(); // TODO: check!!
}
// Needed to register the inputs handled manually
// and not with a VectorImageList through GetParameterImageList
std::set<ReaderType::Pointer> m_Cache;
};
} // otb::Wrapper namespace
} // otb namespace
OTB_APPLICATION_EXPORT(otb::Wrapper::Synthetize)
......@@ -120,6 +120,18 @@ otb_test_application(NAME apTvUtExtractROIExtentFitVect
${OTBAPP_BASELINE}/apTvUtExtractROI.tif
${TEMP}/apTvUtExtractROIExtentFitVect.tif)
#----------- Clamp ROI tests ----------------
otb_test_application(NAME apTvUtResetMargin
APP ResetMargin
OPTIONS -in ${INPUTDATA}/ResetMarginInput100x100.tiff
-out ${TEMP}/apTvUtResetMargin.tif
-threshold.x 10
-threshold.y.start 12
-threshold.y.end 25
VALID --compare-image ${NOTOL}
${OTBAPP_BASELINE}/ResetMarginBaseline100x100.tiff
${TEMP}/apTvUtResetMargin.tif)
#----------- Rescale TESTS ----------------
otb_test_application(NAME apTvUtRescaleTest
APP Rescale
......@@ -252,6 +264,16 @@ otb_test_application(NAME apTvUtConcatenateImages_1Image
${TEMP}/apTvUtConcatenateImages_1Image.tif)
#----------- Synthetize TESTS ----------------
otb_test_application(NAME apTvUtSynthetize
APP Synthetize
OPTIONS -il ${INPUTDATA}/s1a_33NWB_vv_DES_007_20200108t044150_100x100.tif
${INPUTDATA}/s1a_33NWB_vv_DES_007_20200108t044215_100x100.tif
-out ${TEMP}/apTvUtSynthetize.tif
VALID --compare-image ${NOTOL}
${OTBAPP_BASELINE}/s1a_33NWB_vv_DES_007_20200108txxxxxx_100x100.tif
${TEMP}/apTvUtSynthetize.tif)
#----------- MultiResolutionPyramid TESTS ----------------
#----------- PixelValue TESTS ----------------
......@@ -443,8 +465,8 @@ otb_test_application(NAME apTvUtSplitImage
#----------- Mosaic TESTS ----------------
otb_test_application(NAME MosaicTestLargeFeathering
APP Mosaic
OPTIONS -il ${INPUTDATA}/SP67_FR_subset_1.tif ${INPUTDATA}/SP67_FR_subset_2.tif
-out ${TEMP}/apTvMosaicTestLargeFeathering.tif uint8
OPTIONS -il ${INPUTDATA}/SP67_FR_subset_1.tif ${INPUTDATA}/SP67_FR_subset_2.tif
-out ${TEMP}/apTvMosaicTestLargeFeathering.tif uint8
-comp.feather large
VALID --compare-image ${EPSILON_8}
${BASELINE}/apTvMosaicTestLargeFeathering.tif
......@@ -453,9 +475,9 @@ otb_test_application(NAME MosaicTestLargeFeathering
otb_test_application(NAME MosaicTestSlimFeathering
APP Mosaic
OPTIONS -il ${INPUTDATA}/SP67_FR_subset_1.tif ${INPUTDATA}/SP67_FR_subset_2.tif
-out ${TEMP}/apTvMosaicTestSlimFeathering.tif uint8
-comp.feather slim
OPTIONS -il ${INPUTDATA}/SP67_FR_subset_1.tif ${INPUTDATA}/SP67_FR_subset_2.tif
-out ${TEMP}/apTvMosaicTestSlimFeathering.tif uint8
-comp.feather slim
-comp.feather.slim.length 100
VALID --compare-image ${EPSILON_8}
${BASELINE}/apTvMosaicTestSlimFeathering.tif
......@@ -464,9 +486,9 @@ otb_test_application(NAME MosaicTestSlimFeathering
otb_test_application(NAME MosaicTestSimpleWithHarmoBandRmse
APP Mosaic
OPTIONS -il ${INPUTDATA}/SP67_FR_subset_1.tif ${INPUTDATA}/SP67_FR_subset_2.tif
-out ${TEMP}/apTvMosaicTestSimpleWithHarmoBandRmse.tif uint8
-harmo.method band
OPTIONS -il ${INPUTDATA}/SP67_FR_subset_1.tif ${INPUTDATA}/SP67_FR_subset_2.tif
-out ${TEMP}/apTvMosaicTestSimpleWithHarmoBandRmse.tif uint8
-harmo.method band
-harmo.cost rmse
VALID --compare-image ${EPSILON_8}
${BASELINE}/apTvMosaicTestSimpleWithHarmoBandRmse.tif
......@@ -474,9 +496,9 @@ otb_test_application(NAME MosaicTestSimpleWithHarmoBandRmse
otb_test_application(NAME MosaicTestSimpleWithHarmoRgbRmse
APP Mosaic
OPTIONS -il ${INPUTDATA}/SP67_FR_subset_1.tif ${INPUTDATA}/SP67_FR_subset_2.tif
-out ${TEMP}/apTvMosaicTestSimpleWithHarmoRgbRmse.tif uint8
-harmo.method rgb
OPTIONS -il ${INPUTDATA}/SP67_FR_subset_1.tif ${INPUTDATA}/SP67_FR_subset_2.tif
-out ${TEMP}/apTvMosaicTestSimpleWithHarmoRgbRmse.tif uint8
-harmo.method rgb
-harmo.cost rmse
VALID --compare-image ${EPSILON_8}
${BASELINE}/apTvMosaicTestSimpleWithHarmoRgbRmse.tif
......@@ -484,18 +506,18 @@ otb_test_application(NAME MosaicTestSimpleWithHarmoRgbRmse
otb_test_application(NAME MosaicTestSimpleWithCutline
APP Mosaic
OPTIONS -il ${INPUTDATA}/SP67_FR_subset_1.tif ${INPUTDATA}/SP67_FR_subset_2.tif
-out ${TEMP}/apTvMosaicTestSimpleWithCutline.tif uint8
-vdcut ${INPUTDATA}/SP67_FR_subset_1_cutline.shp ${INPUTDATA}/SP67_FR_subset_2_cutline.shp
OPTIONS -il ${INPUTDATA}/SP67_FR_subset_1.tif ${INPUTDATA}/SP67_FR_subset_2.tif
-out ${TEMP}/apTvMosaicTestSimpleWithCutline.tif uint8
-vdcut ${INPUTDATA}/SP67_FR_subset_1_cutline.shp ${INPUTDATA}/SP67_FR_subset_2_cutline.shp
VALID --compare-image ${EPSILON_8}
${BASELINE}/apTvMosaicTestSimpleWithCutline.tif
${TEMP}/apTvMosaicTestSimpleWithCutline.tif)
otb_test_application(NAME MosaicTestSimpleWithVdstats
APP Mosaic
OPTIONS -il ${INPUTDATA}/SP67_FR_subset_1.tif ${INPUTDATA}/SP67_FR_subset_2.tif
-out ${TEMP}/apTvMosaicTestSimpleWithVdstats.tif uint8
-vdstats ${INPUTDATA}/SP67_FR_subset_1_cutline.shp ${INPUTDATA}/SP67_FR_subset_2_cutline.shp
OPTIONS -il ${INPUTDATA}/SP67_FR_subset_1.tif ${INPUTDATA}/SP67_FR_subset_2.tif
-out ${TEMP}/apTvMosaicTestSimpleWithVdstats.tif uint8
-vdstats ${INPUTDATA}/SP67_FR_subset_1_cutline.shp ${INPUTDATA}/SP67_FR_subset_2_cutline.shp
VALID --compare-image ${EPSILON_8}
${BASELINE}/apTvMosaicTestSimpleWithVdstats.tif
${TEMP}/apTvMosaicTestSimpleWithVdstats.tif)
/*
* Copyright (C) 2005-2020 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.
*/
#ifndef otbInterval_h
#define otbInterval_h
#include "itkIntTypes.h"
#include <algorithm>
#include <cassert>
#include <ostream>
namespace otb
{
/** Simplified index interval.
* Inspired by `boost::numeric::interval`.
*
* \invariant Can be empty.
* \invariant lower <= upper
* \author Luc Hermitte (CS Group)
* \copyright CNES
* \ingroup OTBCommon
*/
class Interval
{
public:
using IndexType = itk::IndexValueType;
using SizeType = itk::SizeValueType;
/** Init constructor from the pair of its extremities. */
constexpr Interval(IndexType l, IndexType u) noexcept
: m_lower(l), m_upper(u)
{
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304
assert(l <= u);
#endif
}
/** Alternate factory function from a position and a length. */
static constexpr Interval OfLength(IndexType low, SizeType len) noexcept{
return Interval{low, IndexType(low+len)};
}
constexpr SizeType size() const noexcept
{ return m_upper - m_lower; }
constexpr bool empty() const noexcept
{ return m_lower == m_upper; }
constexpr IndexType lower() const noexcept
{ return m_lower; }
constexpr IndexType upper() const noexcept
{ return m_upper; }
/** Computes the intersection between two interals.
* @return their intersection
* @return {0,0} if theyr don't intersect.
*
* @note this function is an hidden friend
*/
friend constexpr Interval intersect(
Interval const& lhs, Interval const& rhs) noexcept
{
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304
auto const low = std::max(lhs.lower(), rhs.lower());
auto const upp = std::min(lhs.upper(), rhs.upper());
return low <= upp ? Interval{low, upp} : Interval{0,0};
#else
// MSVC version supported is not C++14 compliant
return std::max(lhs.lower(), rhs.lower()) <= std::min(lhs.upper(), rhs.upper())
? Interval{std::max(lhs.lower(), rhs.lower()), std::min(lhs.upper(), rhs.upper())}
: Interval{0,0};
#endif
}
/** Stream inserter for intervals.
* @note this function is an hidden friend
*/
friend std::ostream & operator<<(std::ostream & os, Interval const& v)
{
return os << '[' << v.lower() << ".." << v.upper() << '[';
}
private:
IndexType m_lower;
IndexType m_upper;
};
} // otb namespace
#endif // otbInterval_h
/*
* Copyright (C) 2005-2020 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.
*/
#ifndef otbLogHelpers_h
#define otbLogHelpers_h
#include "itkImageRegion.h"
#include <ostream>
namespace otb
{
/** Helper class to log region in a more human readable way:
* e.g.
* \code
x ∈ [0..42[, y ∈ [12..24[, size=42x12 @(0, 12)
* \endcode
* \author Luc Hermitte (CS Group)
* \copyright CNES
* \ingroup OTBCommon
*/
struct NeatRegionLogger
{
using RegionType = itk::ImageRegion<2u>;
NeatRegionLogger(RegionType const& region) : m_region(region) {}
friend std::ostream & operator<<(std::ostream & os, NeatRegionLogger const& r)
{
auto const& size = r.m_region.GetSize();
auto const& idx = r.m_region.GetIndex();
auto const idx_x1 = idx[0];
int const idx_x2 = idx[0] + size[0];
int const idx_y1 = idx[1];
auto const idx_y2 = idx[1] + size[1];
os
<< "x ∈ ["<<idx_x1 << ".." << idx_x2 << '['
<< ", y ∈ ["<<idx_y1 << ".." << idx_y2 << '['
<< ", size=" << size[0]<<'x'<<size[1] << " @("<<idx_x1<<", "<<idx_y1<<')'
;
return os ;
}
RegionType const& m_region;
};
} // otb namespace
#endif // otbLogHelpers_h
/*
* Copyright (C) 2005-2020 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.
*/
#ifndef Span_h
#define Span_h
#include <type_traits>
#include <iterator>
#include <limits>
#include <cassert>
namespace otb
{
#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304
// In C++ (only; fixed in C++14), constexpr implies const on member
// functions, and OTB support VC++14 which is not C++14 compliant on this
// topic.
// Hence the workaround...