Commit 6b3e69bb authored by Victor Poughon's avatar Victor Poughon

BUG: Improve Convert and DynamicConvert mask handling (fix #1647)

parent 258d3f59
......@@ -128,8 +128,10 @@ private:
MandatoryOff("type.linear.gamma");
AddParameter(ParameterType_InputImage, "mask", "Input mask");
SetParameterDescription("mask", "The masked pixels won't be used to adapt the dynamic "
"(the mask must have the same dimensions as the input image)");
SetParameterDescription("mask",
"Optional binary mask to only process part of the input image."
"Only pixels where the mask is less than 0.5 will be processed."
"The mask must have the same dimensions as the input image.");
MandatoryOff("mask");
DisableParameter("mask");
......
......@@ -78,6 +78,8 @@ public:
typedef StreamingShrinkImageFilter<FloatVectorImageType,
FloatVectorImageType> ShrinkFilterType;
typedef StreamingShrinkImageFilter<UInt8ImageType, UInt8ImageType> UInt8ShrinkFilterType;
typedef Functor::LogFunctor<FloatVectorImageType::InternalPixelType> TransferLogFunctor;
typedef UnaryImageFunctorWithVectorImageFilter<FloatVectorImageType,
FloatVectorImageType,
......@@ -135,8 +137,9 @@ private:
AddParameter(ParameterType_InputImage, "mask", "Input mask");
SetParameterDescription("mask",
"The masked pixels won't be used to adapt the dynamic "
"(the mask must have the same dimensions as the input image)");
"Optional binary mask to only process part of the input image."
"Pixels where the mask is zero will not be processed."
"The mask must have the same dimensions as the input image.");
MandatoryOff("mask");
DisableParameter("mask");
......@@ -300,15 +303,15 @@ private:
// Now we generate the list of samples
if (IsParameterEnabled("mask"))
{
FloatVectorImageType::Pointer mask = this->GetParameterImage("mask");
ShrinkFilterType::Pointer maskShrinkFilter = ShrinkFilterType::New();
UInt8ImageType::Pointer mask = this->GetParameterUInt8Image("mask");
UInt8ShrinkFilterType::Pointer maskShrinkFilter = UInt8ShrinkFilterType::New();
maskShrinkFilter->SetShrinkFactor(shrinkFactor);
maskShrinkFilter->SetInput(mask);
maskShrinkFilter->GetStreamer()->
SetAutomaticAdaptativeStreaming(GetParameterInt("ram"));
maskShrinkFilter->Update();
auto itMask = itk::ImageRegionConstIterator<FloatVectorImageType>(
auto itMask = itk::ImageRegionConstIterator<UInt8ImageType>(
maskShrinkFilter->GetOutput(),
maskShrinkFilter->GetOutput()->GetLargestPossibleRegion());
......@@ -317,8 +320,8 @@ private:
itMask.GoToBegin();
for(; !it.IsAtEnd(); ++it, ++itMask)
{
// float values, so the threshold is set to 0.5
if (itMask.Get()[0] > 0.5)
// valid pixels are non zero
if (itMask.Get() != 0)
{
listSample->PushBack(it.Get());
}
......
......@@ -124,6 +124,20 @@ otb_test_application(NAME apTvUtDynamicConvertFloat
${OTBAPP_BASELINE}/apTvUtDynamicConvertFloatOutput.tif
${TEMP}/apTvUtDynamicConvertFloatOutput.tif)
otb_test_application(NAME apTvUtDynamicConvertMask
APP DynamicConvert
OPTIONS -in ${INPUTDATA}/QB_Toulouse_Ortho_PAN.tif
-out ${TEMP}/apTvUtDynamicConvertMaskOutput.tif
-outmin 0
-outmax 255
-quantile.low 4
-quantile.high 4
-mask ${INPUTDATA}/QB_Toulouse_Ortho_PAN_mask.tif
VALID --compare-image ${NOTOL}
${OTBAPP_BASELINE}/apTvUtDynamicConvertMaskOutput.tif
${TEMP}/apTvUtDynamicConvertMaskOutput.tif)
#----------- PixelInfo TESTS ----------------
#----------- ExtractROI TESTS ----------------
......
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