ImFusion SDK 4.3
PadOperation Class Reference

#include <ImFusion/ML/Operations/PadOperation.h>

Pad an image to a specific padding size in each dimension. More...

+ Inheritance diagram for PadOperation:

Detailed Description

Pad an image to a specific padding size in each dimension.

This operation expands an image by adding padding pixels to any or all sides. The value of the border can be specified by the padding mode. The padding mode can be one of the following:

  • Clamp: The border pixels are the same as the closest image pixel.
  • Mirror: The border pixels are the same as the closest image pixel.
  • Zero: Constant padding with zeros or, if provided, with paddingValue.

For label maps (i.e. modality == Modality::LABEL), a separate padding mode and value can be specified:

  • If both label padding mode and label padding value are specified, those values are used to pad the label map.
  • If only the label padding mode is specified, the paddingValue is used to fill the label map (only for zero padding).
  • If only the label padding value is specified, the paddingMode is used as the label padding mode.
  • If neither label padding mode nor label padding value are specified, paddingMode and paddingValue are used for label maps as well.

Note: Padding sizes are specified in pixels, and can be positive, negative or mixed. Negative padding means cropping.

Note: Both GPU and CPU implementations are provided.

Public Member Functions

 PadOperation (const vec2i &padSizeX=vec2i(0, 0), const vec2i &padSizeY=vec2i(0, 0), const vec2i &padSizeZ=vec2i(0, 0), PaddingMode paddingMode=PaddingMode::Mirror, std::optional< double > paddingValue=std::nullopt, std::optional< PaddingMode > labelPaddingMode=std::nullopt, std::optional< uint8_t > labelPaddingValue=std::nullopt, bool allowDimensionChange=true)
 
virtual std::shared_ptr< SharedImageSetprocessImages (std::shared_ptr< SharedImageSet > input) const override
 Virtual function that every subclass should override.
 
bool doesNotModifyInput () const override
 Returns whether the operation is guaranteed to not modify its input element, either because it computes its output out-of-place or because it is a no-op.
 
bool configure (const Properties &properties) override
 Configure an Operation with the given properties and return whether the configuration was successful.
 
void checkParams () const
 
Operation::Specs getInverseSpecsImpl () const override
 Returns specifications for a PadOperation with inverse properties.
 
- Public Member Functions inherited from InvertibleOperation
 InvertibleOperation (std::string name, ProcessingPolicy processingPolicy)
 
bool supportsInversion () const override
 Indicates that this operation supports inversion.
 
Operation::Specs inverseSpecs () const
 Returns the specifications needed to create an operation that can invert this one.
 
- Public Member Functions inherited from Operation
 Operation (std::string name, ProcessingPolicy processingPolicy)
 Derived classes must specify a name and whether, by default, the operation should also be applied to label maps.
 
virtual void process (DataItem &item)
 Main function that processes a DataItem in-place, may throw OperationException The data to be processed is determined by the active fields (if set) and the processing policy otherwise (if set), otherwise all fields are processed.
 
virtual std::shared_ptr< SharedImageSetprocess (std::shared_ptr< SharedImageSet > input)
 Utility function to directly apply an operation on a SharedImageSet irrespective of active fields and processing policy.
 
virtual std::shared_ptr< KeypointSetprocess (std::shared_ptr< KeypointSet > input)
 Utility function to directly apply an operation on a set of KeypointSet irrespective of active fields and processing policy.
 
virtual std::shared_ptr< BoundingBoxSetprocess (std::shared_ptr< BoundingBoxSet > input)
 Utility function to directly apply an operation on a set of BoundingBoxSet irrespective of active fields and processing policy.
 
virtual std::unique_ptr< SharedImageSetprocess (std::unique_ptr< SharedImageSet > input) final
 Utility function with unique_ptr as input and output to avoid breaking changes (must not be overridden)
 
void addTemporaryPreProcessHook (PreProcessHook hook)
 Add a temporary hook that will only be active for the next process call and then automatically removed after the DataItem is processed.
 
void addTemporaryPostProcessHook (PostProcessHook hook)
 Add a temporary hook that will only be active for the next process call and then automatically removed after the DataItem is processed.
 
virtual bool checkRequiredItemsTypes (const DataItem &item) const
 Checks if the data item holds fields with types required by the operation.
 
const std::stringname () const
 Returns the name of the operation.
 
virtual Properties configuration () const
 Return the Operation configuration.
 
void setActiveFields (std::optional< std::unordered_set< std::string > > activeFields)
 
std::optional< std::unordered_set< std::string > > activeFields () const
 
virtual void setProcessingPolicy (ProcessingPolicy policy)
 
ProcessingPolicy processingPolicy () const
 
std::optional< uint32_t > seed () const
 Return the current seed (if there is one)
 
virtual void seedRandomEngine (uint32_t seed)
 Set a seed for the random generator.
 
ML::ComputingDevice computingDevice () const
 Get the computing device.
 
virtual void setComputingDevice (ML::ComputingDevice device)
 Set the computing device selection strategy.
 
void configFailed (const std::string &missingParam) const
 Helper function to show an error message due to a bad configuration.
 
void logDeprecatedParam (const std::string &oldName, const std::string &newName) const
 Helper function to print a warning because of a deprecated parameter has been specified.
 
bool errorOnUnexpectedBehaviour () const
 Get the policy whether to treat unexpected behavior warnings as errors.
 
virtual void setErrorOnUnexpectedBehaviour (bool error)
 Treat unexpected behavior warnings as errors.
 
void registerParameter (ParameterBase *param)
 Register a parameter so that the operation knows about it, and can automatically configure it (unless it has been marked as manually configured parameter via the Operation::setManuallyConfiguredParameters method).
 
std::vector< ParameterBase * > parameters () const
 Return the list of registered parameters.
 
const std::stringrecordIdentifier () const
 Get the operation's record identifier.
 
virtual void setRecordIdentifier (const std::string &recordIdentifier)
 Set the operation's record identifier.
 
const std::stringlogDomain () const
 Log domain for AdvancedParameter.
 
std::optional< std::unordered_set< std::string > > selectedFields (const DataItem &item)
 Get the fields on which the operation will be applied.
 

Public Attributes

OpParam< vec2i > p_padSizeX = {"pad_size_x", vec2i(0, 0), this, ParamRequired::No}
 
OpParam< vec2i > p_padSizeY = {"pad_size_y", vec2i(0, 0), this, ParamRequired::No}
 
OpParam< vec2i > p_padSizeZ = {"pad_size_z", vec2i(0, 0), this, ParamRequired::No}
 
OpParam< PaddingModep_paddingMode = {"padding_mode", PaddingMode::Mirror, this, ParamRequired::No}
 
OpParam< std::optional< double > > p_paddingValue = {"padding_value", std::nullopt, this, ParamRequired::No}
 
OpParam< std::optional< std::string > > p_labelPaddingMode = {"label_padding_mode", std::nullopt, this, ParamRequired::No}
 
OpParam< std::optional< uint8_t > > p_labelPaddingValue = {"label_padding_value", std::nullopt, this, ParamRequired::No}
 
OpParam< bool > p_allowDimensionChange = {"allow_dimension_change", true, this, ParamRequired::No}
 Allow padding dimensions equal to 1. This results in changing image dimension e.g. from 2D to 3D.
 

Additional Inherited Members

- Public Types inherited from Operation
enum  ProcessingPolicy { EverythingExceptLabels = 0 , Everything , OnlyLabels }
 Policy used by default when selecting on the fields on which the operation will be applied Note that "Labels" here refers to the target tag, not to be confused with Data::Modality::LABEL. More...
 
using PreProcessHook = std::function<void(Operation&, DataElement*)>
 
using PostProcessHook = std::function<void(Operation&, DataElement*)>
 
- Static Public Member Functions inherited from Operation
static std::string processingPolicyToString (const ProcessingPolicy policy)
 
static ProcessingPolicy stringToProcessingPolicy (const std::string &s)
 
static std::unique_ptr< OperationcreateFromFactories (const Operation::Specs &specs)
 Helper function to create an operation from any factory (both C++ and Python factories are tested)
 
- Protected Member Functions inherited from Operation
virtual std::shared_ptr< BoundingBoxSetprocessBoxes (std::shared_ptr< BoundingBoxSet > input) const
 Virtual function that every subclass should override.
 
virtual std::shared_ptr< KeypointSetprocessPoints (std::shared_ptr< KeypointSet > input) const
 Virtual function that every subclass should override.
 
virtual std::shared_ptr< SharedImageSetprocessVectors (std::shared_ptr< SharedImageSet > input) const
 Virtual function that every subclass should override.
 
virtual std::shared_ptr< TensorSetprocessTensors (std::shared_ptr< TensorSet > input) const
 
void throwOperationError (const std::string &msg) const
 Helper function to throw an exception due to a runtime error.
 
void warnOperationUnexpectedBehaviour (const std::string &msg) const
 Helper function to warn about a behavior different than asked.
 
bool inputIsEmptyOrNull (const SharedImageSet *input) const
 Helper function to check if the input is empty or null and print a warning if so.
 
virtual bool useGPU (const SharedImageSet *input) const
 Helper function that returns which device the operation should choose based on its configuration and a given input.
 
void prepareInputForDevice (SharedImageSet &input) const
 Make sure the input is on the correct device for the current device strategy.
 
virtual bool allowChannelBatchOnGPU () const
 Whether the operation implements channel-batching so that it can still be run on input with more than 4 channels.
 
bool configureOnly (const Properties &properties, const std::vector< ParameterBase * > &paramSelection) noexcept
 Helper method to configure only a subset of parameters.
 
void setManuallyConfiguredParameters (const std::vector< ParameterBase * > &manuallyConfiguredParams)
 Disable the auto-configuration of some of the parameters so that they can be parsed manually (in the configure function of the derived class).
 
void applyPreProcessHooks (DataElement *element)
 Apply the current pre-process hooks to an element.
 
void applyPostProcessHooks (DataElement *element)
 Apply the current post-process hooks to an element.
 
- Protected Attributes inherited from Operation
std::string m_name
 
ProcessingPolicy m_processingFieldsPolicy
 Flag specifying whether labels should be processed by default (when no active field has been specified)
 
std::optional< std::unordered_set< std::string > > m_activeFields
 Run the Operation only on those fields (if empty, will select suitable fields based on the current processing policy) when calling process()
 
std::unordered_set< std::stringm_alreadyWarned
 Set of warnings about unexpected behavior that have already been printed.
 
bool m_errorOnUnexpectedBehaviour = false
 Whether to throw an exception instead of warning about unexpected behavior.
 
std::optional< uint32_t > m_seed
 
Random::Generator m_randGenerator
 
ML::ComputingDevice m_device = ML::ComputingDevice::GPUIfOpenGl
 
std::vector< ParameterBase * > m_params
 All registered parameters.
 
std::vector< ParameterBase * > m_manuallyConfiguredParams
 All registered parameters that should not be configured automatically.
 
std::unordered_map< std::string, ElementTypem_requiredFieldsTypes
 List of all required field types used by checkRequiredItemsTypes.
 
std::string m_recordIdentifier
 User-provided unique identifier for this operation, used for recording processing history and inversion.
 
std::vector< PreProcessHookm_preProcessHooks
 
std::vector< PostProcessHookm_postProcessHooks
 
std::vector< PreProcessHookm_temporaryPreProcessHooks
 Pre-process hooks that will be used for the next processing call only.
 
std::vector< PostProcessHookm_temporaryPostProcessHooks
 Post-process hooks that will be used for the next processing call only.
 

Member Function Documentation

◆ processImages()

virtual std::shared_ptr< SharedImageSet > processImages ( std::shared_ptr< SharedImageSet > input) const
overridevirtual

Virtual function that every subclass should override.

Default implementation does nothing, so if those function are not implemented in a derived class, they won't act on the input in any way.

Reimplemented from Operation.

◆ doesNotModifyInput()

bool doesNotModifyInput ( ) const
inlineoverridevirtual

Returns whether the operation is guaranteed to not modify its input element, either because it computes its output out-of-place or because it is a no-op.

This can be used to decide whether a copy of the input should be made before calling the Operation::process function. Note that this only relates to the overloads taking specific elements as inputs (e.g. images, keypoints, etc.), since the Operation::process(DataItem& item) function always modifies its input.

Returns
Always returns true, because this Operation does not modify its input data.

Reimplemented from Operation.

◆ configure()

bool configure ( const Properties & properties)
overridevirtual

Configure an Operation with the given properties and return whether the configuration was successful.

Reimplemented from Operation.

◆ getInverseSpecsImpl()

Operation::Specs getInverseSpecsImpl ( ) const
overridevirtual

Returns specifications for a PadOperation with inverse properties.

Implements InvertibleOperation.


The documentation for this class was generated from the following file:
Search Tab / S to search, Esc to close