diff --git a/app/otbTensorflowModelServe.cxx b/app/otbTensorflowModelServe.cxx index 6189e8fa13b05315a48d0cb643577a1a3291d4b4..59969e36f4b90a3e473c3328844d78778a5aa940 100644 --- a/app/otbTensorflowModelServe.cxx +++ b/app/otbTensorflowModelServe.cxx @@ -192,7 +192,12 @@ public: SetDefaultParameterFloat ("output.spcscale", 1.0); SetParameterDescription ("output.spcscale", "The output image size/scale and spacing*scale where size and spacing corresponds to the first input"); AddParameter(ParameterType_StringList, "output.names", "Names of the output tensors"); - MandatoryOff ("output.names"); + MandatoryOff ("output.names"); + + // Output background value + AddParameter(ParameterType_Float, "output.bv", "Output background value"); + SetDefaultParameterFloat ("output.bv", 0.0); + SetParameterDescription ("output.bv", "The value used when one input has only no-data values in its receptive field"); // Output Field of Expression AddParameter(ParameterType_Int, "output.efieldx", "The output expression field (width)"); @@ -297,6 +302,11 @@ public: m_TFFilter->SetFullyConvolutional(true); } + // Output background value + const float outBV = GetParameterFloat("output.bv"); + otbAppLogINFO("Setting background value to " << outBV); + m_TFFilter->SetOutputBackgroundValue(outBV); + // Output field of expression FloatVectorImageType::SizeType foe; foe[0] = GetParameterInt("output.efieldx"); diff --git a/include/otbTensorflowMultisourceModelFilter.h b/include/otbTensorflowMultisourceModelFilter.h index bdf9a02d0b00e9dbc228f3a0401ac8dab4c49e32..ce855b2858605187d09a75eb8c93f9eaa9f841b1 100644 --- a/include/otbTensorflowMultisourceModelFilter.h +++ b/include/otbTensorflowMultisourceModelFilter.h @@ -132,6 +132,8 @@ public: itkGetMacro(FullyConvolutional, bool); itkSetMacro(OutputSpacingScale, float); itkGetMacro(OutputSpacingScale, float); + itkSetMacro(OutputBackgroundValue, OutputInternalPixelType); + itkGetMacro(OutputBackgroundValue, OutputInternalPixelType); protected: TensorflowMultisourceModelFilter(); @@ -162,17 +164,18 @@ private: void operator=(const Self &); // purposely not implemented - SizeType m_OutputGridSize; // Output grid size - bool m_ForceOutputGridSize; // Force output grid size - bool m_FullyConvolutional; // Convolution mode - float m_OutputSpacingScale; // scaling of the output spacings + SizeType m_OutputGridSize; // Output grid size + bool m_ForceOutputGridSize; // Force output grid size + bool m_FullyConvolutional; // Convolution mode + float m_OutputSpacingScale; // scaling of the output spacings + OutputInternalPixelType m_OutputBackgroundValue; // Output background value // Internal - SpacingType m_OutputSpacing; // Output image spacing - PointType m_OutputOrigin; // Output image origin - SizeType m_OutputSize; // Output image size - PixelType m_NullPixel; // Pixel filled with zeros - + SpacingType m_OutputSpacing; // Output image spacing + PointType m_OutputOrigin; // Output image origin + SizeType m_OutputSize; // Output image size + PixelType m_NullPixel; // Pixel filled with zeros + }; // end class diff --git a/include/otbTensorflowMultisourceModelFilter.hxx b/include/otbTensorflowMultisourceModelFilter.hxx index 59105dd08bbf1c8a622cb4f4a73082e1998083a2..0f32334ce18c3ef4ad25e8a30ab9a5e614973728 100644 --- a/include/otbTensorflowMultisourceModelFilter.hxx +++ b/include/otbTensorflowMultisourceModelFilter.hxx @@ -302,7 +302,7 @@ TensorflowMultisourceModelFilter<TInputImage, TOutputImage>::GenerateOutputInfor // Set null pixel m_NullPixel.SetSize(outputPtr->GetNumberOfComponentsPerPixel()); - m_NullPixel.Fill(0); + m_NullPixel.Fill(m_OutputBackgroundValue); ////////////////////////////////////////////////////////////////////////////////////////// // Set the tiling layout hint in metadata