The OrientedROISampler samples m_numSamples samples of size m_roiSize from each dataset with an efficient GPU sampler.
All samples are gathered together in one SharedImageSet in an ImageElement. In most usecases, the images should be split into individual data items, with the SplitDataLoader (typically a simple '- split: {}' in your training pipeline).
The OrientedROISampler supports random sampling and target-guided sampling from label maps or keypoints. For target-guided sampling make sure to set the sample target with a MarkAsTargetOperation. sample_from_labels_proportion controls the expected fraction of ROI centers drawn from the target instead of uniformly from the full image; the actual number of target-guided samples is binomially distributed around that proportion. For targets of type Modality::LABEL, centers are drawn with class-agnostic foreground sampling by default: every non-zero voxel has equal probability regardless of label value, so larger structures dominate the draw. Setting equalize_label_classes to true switches to class-balanced sampling: a present label value is first picked uniformly at random and then a voxel of that class is picked uniformly at random, so small and large structures are centered with equal probability. For other target image modalities, target values act as relative heatmap weights: zero-valued voxels are never selected, larger values are sampled more often, values do not need to sum to 1, and negative values are not supported. If no valid target voxels are present, target-guided slots fall back to uniform random sampling.
Various augmentations can be used, including random rotation, flipping, shearing, scaling and center position jitter. These operations directly alter the sampling matrix, such that they can then be efficiently sampled. The matrices are retained in the resulting crops, and are not guaranteed to be affine and can be in left- or right-handed orientation systems. Use the SetMatrixToIdentityOperation to set the matrix to identity if required.
- Note
- For legacy reasons, the default padding mode of this sampler is set to Zero.
|
|
| OrientedROISampler (vec3i roiSize=vec3i(1, 1, 1), vec3 roiSpacing=vec3(1, 1, 1), int numSamples=1, vec3 randomRotationRange=vec3::Zero(), vec3 randomFlippingProbability=vec3::Zero(), vec3 randomShearingRange=vec3::Zero(), vec3 randomScalingRange=vec3::Zero(), vec3 randomJitterRange=vec3::Zero(), double sampleFromLabelsProportion=0.0, bool avoidBorders=false, bool alignCrop=false, std::optional< std::vector< vec3 > > centers={}, bool randomScalingLogarithmic=false, float randomRotationProbability=1.f, float randomShearingProbability=1.f, float randomScalingProbability=1.f, bool yAxisDown=false, bool squeeze=false, Distribution randomRotationDistribution=Distribution::Normal, Distribution randomShearingDistribution=Distribution::Normal, Distribution randomJitterDistribution=Distribution::Normal, bool equalizeLabelClasses=false) |
|
void | setCenters (std::vector< vec3 > centers) |
| std::optional< RegionOfInterest > | computeROI (const SharedImageSet *image) const override |
| std::unique_ptr< SharedImageSet > | extractROI (const SharedImageSet *image, std::optional< RegionOfInterest > precomputedRoi={}) const override |
|
std::shared_ptr< SharedImage > | sample (SharedImageSet const &source, mat4 sourceMatix, mat4 targetMatrix, vec3i targetSize, vec3 targetSpacing, InterpolationMode interpolationMode, PaddingMode paddingMode) const |
| bool | requiresLabel () const override |
|
std::vector< mat4 > & | sampleMatrices () |
| void | process (DataItem &item) override |
| | 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.
|
|
| ImageROISampler (std::string name="", PaddingMode paddingMode=PaddingMode::Clamp, std::optional< PaddingMode > labelPaddingMode=PaddingMode::Clamp) |
| virtual std::shared_ptr< SharedImageSet > | processImages (std::shared_ptr< SharedImageSet > input) const override |
| | Virtual function that every subclass should override.
|
| 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 |
|
| 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 std::shared_ptr< SharedImageSet > | process (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< KeypointSet > | process (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< BoundingBoxSet > | process (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< 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).
|
| 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 bool | configure (const Properties &properties) |
| | Configure an Operation with the given properties and return whether the configuration was successful.
|
| 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.
|
|
|
OpParam< vec3i > | m_roiSize = {"roi_size", vec3i::Ones(), this, ParamRequired::Yes} |
| | Fixed size of the ROI to sample.
|
|
OpParam< vec3 > | m_roiSpacing = {"roi_spacing", vec3::Ones(), this, ParamRequired::Yes} |
| | Voxel spacing for resampling of the ROI to sample.
|
|
OpParam< int > | m_numSamples = {"num_samples", 1, this, ParamRequired::No} |
| | Number of crops to generate from an image.
|
|
OpParam< float > | m_randomRotationProbability = {"random_rotation_probability", 1.f, this, ParamRequired::No, "random_rotation_chance"} |
| | Probability to apply a random rotation.
|
|
OpParam< vec3 > | m_randomRotationRange = {"random_rotation_range", vec3::Zero(), this, ParamRequired::No} |
| | Per-axis rotation magnitude. Standard deviation in degrees for "normal"; half-range in degrees for "uniform".
|
| OpParam< Distribution > | m_randomRotationDistribution |
| | Sampling distribution for random_rotation_range.
|
| OpParam< vec3 > | m_randomFlippingProbability |
| | Probability to flip image over corresponding dimension.
|
|
OpParam< float > | m_randomShearingProbability = {"random_shearing_probability", 1.f, this, ParamRequired::No, "random_shearing_chance"} |
| | Probability to apply a random shearing.
|
|
OpParam< vec3 > | m_randomShearingRange = {"random_shearing_range", vec3::Zero(), this, ParamRequired::No} |
| | Per-axis shearing magnitude. Standard deviation for "normal"; half-range for "uniform".
|
| OpParam< Distribution > | m_randomShearingDistribution |
| | Sampling distribution for random_shearing_range.
|
|
OpParam< float > | m_randomScalingProbability = {"random_scaling_probability", 1.f, this, ParamRequired::No, "random_scaling_chance"} |
| | Probability to apply a random scaling.
|
| OpParam< vec3 > | m_randomScalingRange = {"random_scaling_range", vec3::Zero(), this, ParamRequired::No} |
| | Defines the range for random scaling along each dimension.
|
| OpParam< bool > | m_randomScalingLogarithmic = {"random_scaling_logarithmic", false, this, ParamRequired::No} |
| | Enables logarithmic sampling for scale factors.
|
|
OpParam< vec3 > | m_randomJitterRange = {"random_jitter_range", vec3::Zero(), this, ParamRequired::No} |
| | Per-axis jitter added to label-guided sample centers. Standard deviation in mm for "normal"; half-range in mm for "uniform".
|
| OpParam< Distribution > | m_randomJitterDistribution |
| | Sampling distribution for random_jitter_range.
|
| OpParam< double > | m_sampleFromLabelsProportion = {"sample_from_labels_proportion", 0.0, this, ParamRequired::No} |
| | Fraction of ROI centers sampled from the target instead of uniformly from the full image.
|
| OpParam< bool > | m_equalizeLabelClasses = {"equalize_label_classes", false, this, ParamRequired::No} |
| | Switch to class-balanced sampling when drawing target-guided centers from a Modality::LABEL target.
|
|
OpParam< bool > | m_avoidBorders = {"avoid_borders", false, this, ParamRequired::No} |
| | Try to create crops that do not sample outside the border of the image.
|
|
OpParam< bool > | m_yAxisDown = {"y_axis_down", false, this, ParamRequired::No} |
| | Flip Y-axis of the crop (used for certain legacy training pipelines).
|
|
OpParam< bool > | m_squeeze = {"squeeze", false, this, ParamRequired::No} |
| | Squeeze crops to a 2D representation; requires that one of the dimensions in roi_size is 1. Used for 2D training pipelines to get rid of the 'flat' 3rd dimension.
|
|
OpParam< bool > | m_alignCrop = {"align_crop", false, this, ParamRequired::No} |
| | Align crops with voxel grid (before applying random operations).
|
|
OpParam< PaddingMode > | p_paddingMode = {"padding_mode", PaddingMode::Clamp, this, ParamRequired::No} |
|
OpParam< PaddingMode > | p_labelPaddingMode = {"label_padding_mode", PaddingMode::Clamp, this, ParamRequired::No} |