Commit a5ba5bd4 authored by Cresson Remi's avatar Cresson Remi
Browse files

ENH: fix bug with nodata

parent dc7fc35c
...@@ -197,8 +197,14 @@ public: ...@@ -197,8 +197,14 @@ public:
SamplerType::Pointer sampler = SamplerType::New(); SamplerType::Pointer sampler = SamplerType::New();
sampler->SetInputVectorData(GetParameterVectorData("vec")); sampler->SetInputVectorData(GetParameterVectorData("vec"));
sampler->SetField(GetParameterAsString("field")); sampler->SetField(GetParameterAsString("field"));
sampler->SetRejectPatchesWithNodata(GetParameterInt("usenodata")==1); if (GetParameterInt("usenodata")==1)
sampler->SetNodataValue(GetParameterFloat("nodataval")); {
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) for (auto& bundle: m_Bundles)
{ {
sampler->PushBackInputWithPatchSize(bundle.m_ImageSource.Get(), bundle.m_PatchSize); sampler->PushBackInputWithPatchSize(bundle.m_ImageSource.Get(), bundle.m_PatchSize);
......
...@@ -20,6 +20,10 @@ template <class TInputImage, class TVectorData> ...@@ -20,6 +20,10 @@ template <class TInputImage, class TVectorData>
TensorflowSampler<TInputImage, TVectorData> TensorflowSampler<TInputImage, TVectorData>
::TensorflowSampler() ::TensorflowSampler()
{ {
m_NumberOfAcceptedSamples = 0;
m_NumberOfRejectedSamples = 0;
m_RejectPatchesWithNodata = false;
m_NodataValue = 0;
} }
template <class TInputImage, class TVectorData> template <class TInputImage, class TVectorData>
...@@ -181,7 +185,7 @@ TensorflowSampler<TInputImage, TVectorData> ...@@ -181,7 +185,7 @@ TensorflowSampler<TInputImage, TVectorData>
// If not, reject this sample // If not, reject this sample
hasBeenSampled = false; hasBeenSampled = false;
} }
// Check if it contains no-data values // Check if the sampled patch contains a no-data value
if (m_RejectPatchesWithNodata && hasBeenSampled) if (m_RejectPatchesWithNodata && hasBeenSampled)
{ {
IndexType outIndex; IndexType outIndex;
...@@ -193,13 +197,13 @@ TensorflowSampler<TInputImage, TVectorData> ...@@ -193,13 +197,13 @@ TensorflowSampler<TInputImage, TVectorData>
for (it.GoToBegin(); !it.IsAtEnd(); ++it) for (it.GoToBegin(); !it.IsAtEnd(); ++it)
{ {
PixelType pix = it.Get(); PixelType pix = it.Get();
for (int i; i<pix.Size(); i++) for (int i; i < pix.Size(); i++)
if (pix[i] == m_NodataValue) if (pix[i] == m_NodataValue)
{ {
hasBeenSampled = false; hasBeenSampled = false;
break; break;
} }
if (hasBeenSampled) if (!hasBeenSampled)
break; break;
} }
......
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