diff --git a/app/otbPatchesExtraction.cxx b/app/otbPatchesExtraction.cxx index 2f9cee23781984f9f9749b7cd3c360274c5230fd..eb52220ac69bd731dde287f508defa885be7e016 100644 --- a/app/otbPatchesExtraction.cxx +++ b/app/otbPatchesExtraction.cxx @@ -197,8 +197,14 @@ public: SamplerType::Pointer sampler = SamplerType::New(); sampler->SetInputVectorData(GetParameterVectorData("vec")); sampler->SetField(GetParameterAsString("field")); - sampler->SetRejectPatchesWithNodata(GetParameterInt("usenodata")==1); - sampler->SetNodataValue(GetParameterFloat("nodataval")); + if (GetParameterInt("usenodata")==1) + { + otbAppLogINFO("Rejecting patches that have at least one no-data value"); + sampler->SetRejectPatchesWithNodata(true); + float nodatavalue = GetParameterFloat("nodataval"); + otbAppLogINFO("No-data value: " << nodatavalue); + sampler->SetNodataValue(nodatavalue); + } for (auto& bundle: m_Bundles) { sampler->PushBackInputWithPatchSize(bundle.m_ImageSource.Get(), bundle.m_PatchSize); diff --git a/include/otbTensorflowSampler.hxx b/include/otbTensorflowSampler.hxx index 8c5d98970043ada5b5e617c5da19d6be62e93cea..00a45a60d320b8d319140d28605352a4c9376103 100644 --- a/include/otbTensorflowSampler.hxx +++ b/include/otbTensorflowSampler.hxx @@ -20,6 +20,10 @@ template <class TInputImage, class TVectorData> TensorflowSampler<TInputImage, TVectorData> ::TensorflowSampler() { + m_NumberOfAcceptedSamples = 0; + m_NumberOfRejectedSamples = 0; + m_RejectPatchesWithNodata = false; + m_NodataValue = 0; } template <class TInputImage, class TVectorData> @@ -181,7 +185,7 @@ TensorflowSampler<TInputImage, TVectorData> // If not, reject this sample hasBeenSampled = false; } - // Check if it contains no-data values + // Check if the sampled patch contains a no-data value if (m_RejectPatchesWithNodata && hasBeenSampled) { IndexType outIndex; @@ -193,13 +197,13 @@ TensorflowSampler<TInputImage, TVectorData> for (it.GoToBegin(); !it.IsAtEnd(); ++it) { PixelType pix = it.Get(); - for (int i; i<pix.Size(); i++) + for (int i; i < pix.Size(); i++) if (pix[i] == m_NodataValue) { hasBeenSampled = false; break; } - if (hasBeenSampled) + if (!hasBeenSampled) break; }