![]() |
ImFusion C++ SDK 4.5.0
|
#include <ImFusion/ML/Samplers/SplitROISampler.h>
Sampler which splits the input image into overlapping ROIs for sliding window inference. More...
Sampler which splits the input image into overlapping ROIs for sliding window inference.
This sampler mimics the situation at test-time, when one image needs to be processed in regularly spaced patches.
The step size is used to compute valid ROI positions that cover the full input image. The sampling behavior is controlled by the patch_step_size parameter, which is used to compute the ROIs offsets in the input image as a fraction of the specified ROI size.
roi_size: Target size of the ROIs to be extracted as [Width, Height, Slices]. patch_step_size [0, 1]: Controls the step size between ROIs as a fraction of the ROI size. In cases where the input image is a multiple of the ROI size, a step size of 1.0 means no overlapping patches, while a lower step size means a higher number of overlapping patches. Example: If the input image is 100x100 and the ROI size is 50x50, a patch_step_size of 1.0 will result in a 2x2 grid of non-overlapping patches, while a patch_step_size of 0.5 will result in a 3x3 grid of patches, with a 25 pixel overlap between adjacent patches. In cases where the input image is not a multiple of the ROI size, a step size of 1.0 indicates the optimal way of splitting the image in the least possible number of patches. Example: If the input image is 100x100 and the ROI size is 40x40, a patch_step_size of 1.0 will result in a 3x3 grid of patches, with a 10 pixel overlap between adjacent patches. Conversely, a patch_step_size of 0.5 will result in a 4x4 grid of patches, with a 20 pixel overlap between adjacent patches. extract_all_patches (bool): When true, returns all overlapping patches according to the step size. When false, returns a single randomly selected patch from all possible positions.
Public Member Functions | |
| SplitROISampler (double patchStepSize=0.8, bool extractAllPatches=false, bool allowDimensionChange=true) | |
| SplitROISampler (vec3i roiSize, double patchStepSize=0.8, bool extractAllPatches=false, bool allowDimensionChange=true) | |
| SplitROISampler (vec2i roiSize, double patchStepSize=0.8, bool extractAllPatches=false, bool allowDimensionChange=true) | |
| bool | configure (const Properties &properties) override |
| Configure an Operation with the given properties and return whether the configuration was successful. | |
| virtual std::optional< RegionOfInterest > | computeROI (const SharedImageSet *image) const override |
| Compute the location of the ROI to sample from. | |
| std::vector< RegionOfInterest > | computeROIs (const SharedImageSet *image) const |
| Compute all the rois for splitting the input image at once. | |
| std::unique_ptr< SharedImageSet > | extractROI (const SharedImageSet *image, std::optional< RegionOfInterest > precomputedRoi) const override |
| Extract a patch from input image using a single ROI. | |
| std::shared_ptr< SharedImageSet > | processImages (std::shared_ptr< SharedImageSet > input) const override |
| Sample images from input image. | |
| void | process (DataItem &item) override |
| Sample from input item. | |
| DataItem | sampleFromROI (const DataItem &item, const RegionOfInterest &roi) const |
| Sample a patch from input item using a single ROI. | |
| void | checkParams () const |
| virtual std::shared_ptr< SharedImageSet > | process (std::shared_ptr< SharedImageSet > input) |
| Utility function with unique_ptr as input and output to avoid breaking changes (must not be overridden). | |
| virtual std::shared_ptr< KeypointSet > | process (std::shared_ptr< KeypointSet > input) |
| Utility function with unique_ptr as input and output to avoid breaking changes (must not be overridden). | |
| virtual std::shared_ptr< BoundingBoxSet > | process (std::shared_ptr< BoundingBoxSet > input) |
| Utility function with unique_ptr as input and output to avoid breaking changes (must not be overridden). | |
| virtual std::unique_ptr< SharedImageSet > | process (std::unique_ptr< SharedImageSet > input) final |
| Utility function with unique_ptr as input and output to avoid breaking changes (must not be overridden). | |
| Public Member Functions inherited from ImFusion::ML::ImageROISampler | |
| ImageROISampler (std::string name="", PaddingMode paddingMode=PaddingMode::Clamp, std::optional< PaddingMode > labelPaddingMode=PaddingMode::Clamp) | |
| virtual std::shared_ptr< BoundingBoxSet > | processBoxes (std::shared_ptr< BoundingBoxSet > input) const override |
| Virtual function that every subclass should override. | |
| virtual std::shared_ptr< KeypointSet > | processPoints (std::shared_ptr< KeypointSet > input) const override |
| Virtual function that every subclass should override. | |
| virtual std::shared_ptr< SharedImageSet > | processVectors (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. | |
| void | setPaddingMode (PaddingMode paddingMode) |
| PaddingMode | paddingMode () const |
| void | setLabelPaddingMode (PaddingMode labelPaddingMode) |
| PaddingMode | labelPaddingMode () const |
| PaddingMode | paddingModeForImage (const SharedImageSet &image) const |
| virtual bool | requiresLabel () const |
| Public Member Functions inherited from ImFusion::ML::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. | |
| 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::string & | name () 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. | |
| virtual bool | supportsInversion () const |
| Whether the operation supports inversion. Returns False unless the operation derives from InvertibleOperation. | |
| const std::string & | recordIdentifier () const |
| Get the operation's record identifier. | |
| virtual void | setRecordIdentifier (const std::string &recordIdentifier) |
| Set the operation's record identifier. | |
| const std::string & | logDomain () const |
| Log domain for AdvancedParameter. | |
| std::unordered_set< std::string > | selectedFields (const DataItem &item) const |
| Get the fields on which the operation will be applied. | |
Public Attributes | |
| OpParam< vec3i > | p_roiSize = {"roi_size", vec3i::Ones(), this, ParamRequired::Yes} |
| Target size of the ROIs to be extracted as [Width, Height, Slices]. | |
| OpParam< double > | p_patchStepSize = {"patch_step_size", 0.8, this, ParamRequired::No} |
| Controls the step size between ROIs as a fraction of the ROI size. Using nnUnet default value. | |
| OpParam< bool > | p_extractAllPatches = {"extract_all_patches", false, this, ParamRequired::No} |
| When true, returns all possible ROIs. When false, returns a single randomly selected ROI. | |
| 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. | |
| Public Attributes inherited from ImFusion::ML::ImageROISampler | |
| OpParam< PaddingMode > | p_paddingMode = {"padding_mode", PaddingMode::Clamp, this, ParamRequired::No} |
| OpParam< PaddingMode > | p_labelPaddingMode = {"label_padding_mode", PaddingMode::Clamp, this, ParamRequired::No} |
Additional Inherited Members | |
| Public Types inherited from ImFusion::ML::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 ImFusion::ML::ImageROISampler | |
| static std::unique_ptr< SharedImageSet > | padImageToDimensions (const SharedImageSet *image, const vec3i &newDims, ImFusion::PaddingMode paddingMode) |
| static std::unique_ptr< SharedImageSet > | cropImage (const SharedImageSet *image, const RegionOfInterest &roi, ML::ComputingDevice device) |
| static vec3i | preprocessRoiSize (vec3i roiSize, const vec3i &imageDims) |
| Replace -1s with the corresponding image dimension. | |
| static void | checkRoiSize (const SharedImageSet *image, const vec3i &roiSize) |
| Static Public Member Functions inherited from ImFusion::ML::Operation | |
| static std::string | processingPolicyToString (const ProcessingPolicy policy) |
| static ProcessingPolicy | stringToProcessingPolicy (const std::string &s) |
| static std::unique_ptr< Operation > | createFromFactories (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 ImFusion::ML::Operation | |
| virtual std::shared_ptr< TensorSet > | processTensors (std::shared_ptr< TensorSet > input) const |
| Virtual function that every subclass should override. | |
| 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 * > ¶mSelection) 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 ImFusion::ML::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::string > | m_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, ElementType > | m_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< PreProcessHook > | m_preProcessHooks |
| std::vector< PostProcessHook > | m_postProcessHooks |
| std::vector< PreProcessHook > | m_temporaryPreProcessHooks |
| Pre-process hooks that will be used for the next processing call only. | |
| std::vector< PostProcessHook > | m_temporaryPostProcessHooks |
| Post-process hooks that will be used for the next processing call only. | |
|
overridevirtual |
Configure an Operation with the given properties and return whether the configuration was successful.
Reimplemented from ImFusion::ML::Operation.
|
overridevirtual |
Compute the location of the ROI to sample from.
Implements ImFusion::ML::ImageROISampler.
|
overridevirtual |
Extract a patch from input image using a single ROI.
This function allows to split the image elements in the input item in a lazy fashion. The user can precompute the ROIs using computeROIs, and then lazily produce patches by manually specifying the ROI to use for sampling.
Reimplemented from ImFusion::ML::ImageROISampler.
|
overridevirtual |
Sample images from input image.
If p_extractAllPatches is true, returns the set of extracted patches from all possible ROIs. Otherwise, returns a single patch from a randomly selected ROI
Reimplemented from ImFusion::ML::ImageROISampler.
|
overridevirtual |
Sample from input item.
For each ImageElement in the item, the function processImages is applied to the element. All other element types are replicated to match the batch size of the splitted image elements.
Reimplemented from ImFusion::ML::ImageROISampler.
| DataItem ImFusion::ML::SplitROISampler::sampleFromROI | ( | const DataItem & | item, |
| const RegionOfInterest & | roi ) const |
Sample a patch from input item using a single ROI.
This function allows to split the image elements in the input item in a lazy fashion. The user can precompute the ROIs using computeROIs, and then lazily produce patches by manually specifying the ROI to use for sampling. All non-image element types are cloned.
|
virtual |
Utility function with unique_ptr as input and output to avoid breaking changes (must not be overridden).
Reimplemented from ImFusion::ML::Operation.
|
virtual |
Utility function with unique_ptr as input and output to avoid breaking changes (must not be overridden).
Reimplemented from ImFusion::ML::Operation.
|
virtual |
Utility function with unique_ptr as input and output to avoid breaking changes (must not be overridden).
Reimplemented from ImFusion::ML::Operation.
|
finalvirtual |
Utility function with unique_ptr as input and output to avoid breaking changes (must not be overridden).
Reimplemented from ImFusion::ML::Operation.