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

ENH: fix bug with nodata

parent dc7fc35c
......@@ -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);
......
......@@ -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;
}
......
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