![]() |
ImFusion SDK 4.3
|
#include <ImFusion/Base/ImageResamplingAlgorithm.h>
Algorithm for resampling an image to a target dimension or resolution, optionally with respect to another image. More...
Algorithm for resampling an image to a target dimension or resolution, optionally with respect to another image.
If a reference image is not provided the size of the output can be either explicitly specified, or implicitly determined by setting a target spacing, binning or relative size w.r.t. the input (in percentage). Only one of these strategies can be active at a time, as specified by the resamplingMode field. The value of the other target fields will be ignored. The algorithm offers convenience methods to jointly update the value of a target field and change the resampling mode accordingly.
In case you provide a reference image it will its pixel grid (dimensions, spacing, pose matrix) for the output. However, the pixel type as well as shift/scale will remain the same as in the input image.
The algorithm supports Linear and Nearest interpolation modes. In the Linear case (default), when accessing the input image at a fractional coordinate, the obtained value will be computed by linearly interpolating between the closest pixels/voxels. In the Nearest case, the value of the closest pixel/voxel will be used instead.
Furthermore, multiple reduction modes are also supported. In contrast to the interpolation mode, which affects how the value of the input image at a given (potentially fractional) coordinate is extracted, this determines what happens when multiple input pixels/voxels contribute to the value of a single output pixel/voxel. In Nearest mode, the value of the closest input pixel/voxel is used as-is. Alternatively, the Minimum, Maximum or Average value of the neighboring pixel/voxels can be used.
By default, the image will be modified in-place; a new one can be created instead by changing the value of the createNewImage parameter.
By default, the resulting image will have an altered physical extent, since the original extent may not be divisible by the target spacing. The algorithm can modify the target spacing to exactly maintain the physical extent, by toggling the preserveExtent parameter.
If the keepZeroValues parameter is set to true, the input pixels/voxels having zero value will not be modified by the resampling process.
Public Types | |
enum | ResamplingMode { TARGET_DIM = 0 , TARGET_PERCENT = 1 , TARGET_SPACING = 2 , TARGET_BINNING = 3 } |
Enum for new dimension computation. More... | |
![]() | |
enum | Status { Unknown = -1 , Success = 0 , Error = 1 , InvalidInput , IncompleteInput , OutOfMemoryHost , OutOfMemoryGPU , UnsupportedGPU , UnknownAction , AbortedByUser , User = 1000 } |
Status codes. More... | |
Public Member Functions | |
ImageResamplingAlgorithm (SharedImageSet *inImages, const SharedImageSet *refImages=nullptr) | |
ImageResamplingAlgorithm (SharedImageSet *inImages, std::vector< ImageDescriptorWorld > refWorldDescriptor) | |
void | compute () override |
Execute the algorithm. | |
OwningDataList | takeOutput () override |
Return any new Data that was created by the Algorithm during the last call to compute(). | |
void | configure (const Properties *p) override |
Configure this object instance by de-serializing the given Properties. | |
void | configuration (Properties *p) const override |
Serialize the current object configuration into the given Properties object. | |
void | setTargetDimensions (const vec3i &newDims) |
Set the desired dimension for the output image - changes the resampling mode to TARGET_DIMS. | |
void | setTargetPercent (const vec3i &newPercent) |
Set the target dimension for the output image as a percentage of the input - changes the resampling mode to TARGET_PERCENT. | |
void | setTargetSpacing (double newSpacing) |
Set an isotropic target spacing - changes the resampling mode to TARGET_SPACING. | |
void | setTargetSpacing (const vec3 &newSpacing) |
Set the target spacing - changes the resampling mode to TARGET_SPACING. | |
bool | setTargetMinSpacing (double minSpacing) |
Set the target spacing with the spacing of the input image, replacing the value in each dimension with the maximum between the original and the provided value. | |
bool | setTargetMinSpacing (const vec3 &minSpacing) |
Set the target spacing with the spacing of the input image, replacing the value in each dimension with the maximum between the original and the provided value. | |
void | setTargetBinning (const vec3i &newBinning) |
Set the binning to be used to create output image and compute its size - changes the resampling mode to TARGET_BINNING. | |
void | setCreateNew (bool createNew) |
void | setCloneDeformation (bool cloneDeformation) |
void | setVerbose (bool newVerbose) |
void | setForceCPU (bool newForceCPU) |
void | setInterpolationMode (InterpolationMode mode) |
void | setKeepZeroValues (bool keepZero) |
void | setReductionMode (ReductionMode mode) |
void | setPreserveExtent (bool presExt) |
bool | resamplingNeeded (int frame=-1) const |
Return whether resampling is needed or the specified settings result in the same image size and spacing. | |
std::unique_ptr< SharedImage > | processImage (int frame, bool always=false) |
Compute resampling on one frame, return resulting image if applicable. | |
std::pair< std::shared_ptr< SharedImage >, DataComponentList > | processImage (const SharedImage &image, const DataComponentList &components) const override |
Compute resampling on one frame, return resulting image if applicable. | |
void | setInput (SharedImageSet *newInImages, const SharedImageSet *newRefImages, bool reconfigureFromNewData) |
Replaces the input of the algorithm If reconfigureFromNewData is true, the algorithm reconfigures itself based on meta data of the new input. | |
void | setInput (SharedImageSet *newInImages, std::vector< ImageDescriptorWorld > worldImageDescriptor, bool reconfigureFromNewData) |
If reconfigureFromNewData is true, the algorithm reconfigures itself based on meta data of the new input. | |
![]() | |
Algorithm () | |
Default constructor will registers a single "compute" action that calls compute() and returns status(). | |
virtual void | setProgress (Progress *progress) |
Sets a Progress interface the algorithm can use to notify observers about its computing progress. | |
Progress * | progress () const |
Returns the progress interface if set. | |
virtual int | status () const |
Indicates the status of the last call to compute(). | |
virtual bool | survivesDataDeletion (const Data *) const |
Indicates whether the algorithm can handle (partial) deletion of the specified data, by default this checks whether the data is in the input list. | |
const FactoryInfo & | factoryInfo () const |
Returns the record describing how this Algorithm was instantiated by the AlgorithmFactory. | |
void | setFactoryInfo (const FactoryInfo &value) |
Sets the record describing how this Algorithm was instantiated by the AlgorithmFactory. | |
Status | runAction (const std::string &id) |
Run the action with name id if it exists. | |
const std::vector< Action > & | actions () |
Get a mapping from Action id to Action as registered in this algorithm. | |
![]() | |
virtual void | configureDefaults () |
Retrieve the properties of this object, replaces values with their defaults and sets it again. | |
void | registerParameter (ParameterBase *param) |
Register the given Parameter or SubProperty, so that it will be configured during configure()/configuration(). | |
void | unregisterParameter (const ParameterBase *param) |
Remove the given Parameter or SubProperty from the list of registered parameters. | |
Configurable (const Configurable &rhs) | |
Configurable (Configurable &&rhs) noexcept | |
Configurable & | operator= (const Configurable &) |
Configurable & | operator= (Configurable &&) noexcept |
![]() | |
virtual void | setSequentialMode (bool b) |
This method should be called to let the algorithm know that it should only run in sequential mode. | |
virtual bool | isSequentialMode () const |
Returns of the algorithm should only run in sequential mode. | |
Static Public Member Functions | |
static bool | createCompatible (const DataList &data, Algorithm **a) |
![]() | |
static bool | createCompatible (const DataList &data, Algorithm **a=nullptr) |
Factory function to check algorithm compatibility with input data and optionally instantiate it. | |
Public Attributes | |
Parameter< bool > | p_createNewImage = {"createNewImage", true} |
Whether to compute the result in-place or in a newly allocated image. | |
Parameter< bool > | p_cloneDeformation = {"cloneDeformation", true, this} |
Whether to clone deformation from original image before attaching to result. | |
Parameter< bool > | p_forceCPU = {"forceCPU", false, this} |
Whether to force the computation on the CPU. | |
Parameter< bool > | p_preserveExtent = {"preserveExtent", false, this} |
Whether to update the target spacing to keep exactly the physical dimensions of the input image. | |
Parameter< bool > | p_keepZeroValues = {"keepZeroValues", false} |
Whether to to interpret 0 values as mask values, discarding its neighbors. | |
Parameter< bool > | p_verbose = {"verbose", false, this} |
Whether to enable advanced logging. | |
Parameter< ReductionMode > | p_reductionMode = {"reductionMode", ReductionMode::Average} |
Mode for image reduction (e.g. downsampling, resampling, binning) | |
Parameter< InterpolationMode > | p_interpolationMode = {"interpolationMode", InterpolationMode::Linear} |
Mode for image interpolation. | |
Parameter< ResamplingMode > | p_resamplingMode = {"resamplingMode", TARGET_PERCENT} |
How the output image size should be obtained (explicit dimensions, percentage relative to the input image, ...) | |
Parameter< vec3i > | p_targetDimensions = {"targetDimensions", vec3i::Zero()} |
Target dimensions for the new image. | |
Parameter< vec3i > | p_targetPercent = {"targetPercent", vec3i{100, 100, 100}} |
Target dimensions for the new image, relatively to the input one. | |
Parameter< vec3 > | p_targetSpacing = {"targetSpacing", vec3::Zero()} |
Target spacing for the new image. | |
Parameter< vec3i > | p_targetBinning = {"targetBinning", vec3i::Ones()} |
How many pixels from the input image should be combined into an output pixel. | |
![]() | |
Signal | signalOutputChanged |
Signal should be emitted by Algorithms when their output/result has changed. | |
Signal | signalParametersChanged |
Signal should be emitted by Algorithms when their parameter configuration has changed. | |
![]() | |
Signal | signalParametersChanged |
Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted. | |
Protected Attributes | |
SharedImageSet * | m_inImages |
std::vector< ImageDescriptorWorld > | m_refDescriptors |
std::unique_ptr< SharedImageSet > | m_outImages |
std::unique_ptr< GL::ImageProgram > | m_program |
std::pair< std::shared_ptr< Mask >, std::shared_ptr< Mask > > | m_masks |
![]() | |
std::string | m_name |
Algorithm name. | |
Progress * | m_progress = nullptr |
Non-owing pointer to a progress interface. May be a nullptr. | |
FactoryInfo | m_factoryInfo = {} |
Record describing how this algorithm was instantiated by the AlgorithmFactory. | |
int | m_status = Status::Unknown |
Algorithm status after last call to compute() | |
std::vector< Action > | m_actions |
Map of key given by the id of the action, of the available actions of this algorithm. | |
![]() | |
std::vector< Param > | m_params |
List of all registered Parameter and SubProperty instances. | |
![]() | |
bool | m_isSequentialMode = false |
Flag to determine if algorithm is running in sequential mode. | |
Additional Inherited Members | |
![]() | |
void | loadDefaults () |
void | registerAction (const std::string &id, const std::string &guiName, const std::function< Algorithm::Status(void)> &action) |
Register an action to be run via runAction. | |
template<typename D> | |
void | registerAction (const std::string &id, const std::string &guiName, Algorithm::Status(D::*action)(void)) |
Template version of runAction that can be used with a pointer to a member function. | |
void | registerAction (const Action &action) |
Register an action. | |
enum ResamplingMode |
Enum for new dimension computation.
|
overridevirtual |
Execute the algorithm.
Implements Algorithm.
|
overridevirtual |
|
overridevirtual |
Configure this object instance by de-serializing the given Properties.
The default implementation will do so automatically for all registered Parameter and SubProperty instances.
Reimplemented from Configurable.
|
overridevirtual |
Serialize the current object configuration into the given Properties object.
The default implementation will do so automatically for all registered Parameter and SubProperty instances.
Reimplemented from Configurable.
bool setTargetMinSpacing | ( | double | minSpacing | ) |
Set the target spacing with the spacing of the input image, replacing the value in each dimension with the maximum between the original and the provided value.
minSpacing | the minimum value that the target spacing should have in each direction |
bool setTargetMinSpacing | ( | const vec3 & | minSpacing | ) |
Set the target spacing with the spacing of the input image, replacing the value in each dimension with the maximum between the original and the provided value.
minSpacing | the minimum value that the target spacing should have in each direction |
std::unique_ptr< SharedImage > processImage | ( | int | frame, |
bool | always = false ) |
Compute resampling on one frame, return resulting image if applicable.
If the always flag is enabled, the output image will always be created even if no resampling would be needed.
|
overridevirtual |
Compute resampling on one frame, return resulting image if applicable.
Implements SequentialImageProcessor.