![]() |
ImFusion SDK 4.3
|
Plugin for element-wise arithmetic operators with seamless compute dispatching to GPU or CPU. More...
Plugin for element-wise arithmetic operators with seamless compute dispatching to GPU or CPU.
This plugin provides element-wise arithmetic operators for SharedImage, SharedImageSet, and TypedImage.
Just include "ImFusion/ImageMath/SharedImageSetArithmetic.h" and you are good to go. You can also use ImageMath expressions as abstract includes in your own shaders.
In ExprBaseTpl we provide a lot of build-in operators.
Combining channels:
Mask/GlMask values:
You can also use ImageMath expressions to create a GlMask, see OperandMask.h for further information.
Deformations:
You can also use ImageMath expressions to create a Deformation, see OperandDeformation.h for further information.
Regular:
Visitors in max/min reductions:
We support common reductions (sum, product, min, max, length) over channels.
In the following example, si
is e.g. a 3-channel image:
We currently offer Views for block access as well as channel swizzling.
We support broadcasting/streaming in several settings:
You can broadcast a single image to all images in a SharedImageSet.
You can broadcast a single channel to multiple channels.
You can broadcast any dimension using samplers, i.e. boundary conditions. We support clampToEdge (default) or clampToBorder with a specific border color. E.g. you can stream an image of a single slice to all slices of a volume like this:
You can combine channelSwizzle and broadcasting to stream to other slices as well:
You can also define a border color instead of using ClampToEdge. For instance to realize finite differences with zero padding:
Compute 3D finite differences:
We provide the evaluateIntoImage template to conveniently evaluate an expression into a new image:
There are several use-cases where you might want to store the intermediate object, representing an expression. In this example we store the expression representing a gradient descent step to reuse it in each iteration.
This plugin provides element-wise arithmetic operators for SharedImage, SharedImageSet, and TypedImage. The evaluation of an expression is Selection, shift/scale and type aware.
For each expression an binary expression tree gets build. Leaves are values, inner nodes are operators. This either happens at compile time or at runtime (see below for more details).
These leaves are currently supported:
We support compile-time expressions. These expressions need to be fully posed and can be evaluated without the need for any temporary images, i.e. memory, to store intermediate results. In order to enable this we use the curiously recurring template pattern (CRTP) (very similar to how Eigen works). The corresponding base class is ExprBaseTpl. Child classes are for instance the aforementioned expression leaves but also templated implementations of arithmetic operations.
We support the following operators: internal::BinaryOpTpl, internal::UnaryOpTpl, internal::VariableSubstitutionOp, internal::PolyWrapper, internal::DeviceStrategyWrapperTpl, and internal::ChannelSwizzleViewTpl. In almost all cases as a user you do not need these classes but you instead want to use the corresponding methods provided by ExprBaseTpl:
In order to use expression as arguments to methods or functions without the need for templates we also support run-time expressions. The major difference is that these are not compile time optimized and require temporary image allocation in order to store intermediate results while evaluating an expression.
The base class for polymorphic run-time expressions is ExprBase.
Compile-time expressions can be used in run-time expressions as well. For this purpose we offer a wrapper class internal::PolyWrapper for which we also offer the builder method ExprBaseTpl::polyWrapper().
Finally any expression can be used within OpenGL shaders. For this purpose we have the GlExpr which is a specialized GlAbstractInclude.
NOTE: This also supports multiple input and output images. See the documentation of GlExpr.
The DeviceStrategy of the target as well as the source expression will define where the expression gets evaluated. If the DeviceStrategy is set to DeviceStrategy::Auto the expression will be run on the GPU if the target image has a GlImage representation. Otherwise the CPU execution will be used. This can be overridden with ExprBaseTpl::forceCPU() or ExprBaseTpl::forceGPU(). DeviceStrategy::ForceCPU will override DeviceStrategy::ForceGPU and both will override DeviceStrategy::Auto.
Array returns DeviceStrategy::ForceCPU as DeviceStrategy if the image has more than 4 channels or has type double, uint, or int.
Similar to the case above, the type is determined using the target image. The main reason is that you cannot build up the expression for any permutation of types because this will become to complex. Thus, as long as all the images involved have the same type, you do not have to provide any type information. I.e. You can write the expression like this.
However, if you mix types like in the following example you need to provide the type for all images which are not the same type as the target image. Note that the labelMap is a unsigned short image while img1 is float. In such cases you need to provide the type.
Topics | |
Core/Low-level API | |
Low-level data structures for element-wise arithmetic operators. | |
Extending ImageMath | |
How to extend the ImageMath plugin. | |
Pitfalls | |
Common pitfalls. | |
Files | |
file | SharedImageSetArithmetic.h |
This header provides arithmetic operators for TypeImage<>, SharedImage, and SharedImageSet. | |
Namespaces | |
namespace | ImFusion::ImageMath |
Arithmetic operations on images and arrays. | |
Classes | |
class | SharedImageArithmeticAlgorithm |
ImageMath algorithm class. More... | |
class | GlExpr |
Wrapper for using a ExprBase as GlAbstractInclude. More... | |
class | ExprBase |
Base class for expressions (non-templated) (needs to be empty in order to enable empty base class optimization!) More... | |
class | PolyWrapper< ExprT > |
Specialization of ExprBase wrapping a ExprBaseTpl. More... | |
class | Array< T, ImgType, BlockAccessEnabled > |
Specialization of ExprBase for a image leaf, i.e. More... | |
class | ChannelWiseScalar< T, Dim > |
Specialization of ExprBaseTpl for a channel wise scalar value. More... | |
class | ExprBaseTpl< ImplType > |
Base class for compile-time optimized expressions (curiously recurring template pattern (CRTP)) More... | |
class | Scalar< T > |
Specialization of ExprBaseTpl for a single scalar value. More... | |
class | StringLeaf |
Specialization of ExprBaseTpl for a simple leaf representing a string. More... | |
class | Variable |
Specialization of ExprBaseTpl for a variable, e.g. More... | |
Functions | |
template<typename T> | |
auto | makeArray (TypedImage< T > &img, bool ignoreShiftAndScale, MagFilter magFilter, Wrap wrap, const vec4f &borderColor) |
Convenience function to create an array leaf (needed as until c++17 there is no template type deduction from constructor arguments) | |
template<typename T> | |
auto | makeArray (SharedImage &img, bool ignoreShiftAndScale, MagFilter magFilter, Wrap wrap, const vec4f &borderColor) |
Convenience function to create an array leaf (needed as until c++17 there is no template type deduction from constructor arguments) | |
template<typename T> | |
auto | makeArray (SharedImageSet &img, bool ignoreShiftAndScale, MagFilter magFilter, Wrap wrap, const vec4f &borderColor) |
Convenience function to create an array leaf (needed as until c++17 there is no template type deduction from constructor arguments) | |
template<typename T> | |
auto | makeArray (const TypedImage< T > &img, bool ignoreShiftAndScale, MagFilter magFilter, Wrap wrap, const vec4f &borderColor) |
Convenience function to create an array leaf (needed as until c++17 there is no template type deduction from constructor arguments) | |
template<typename T> | |
auto | makeArray (const SharedImage &img, bool ignoreShiftAndScale, MagFilter magFilter, Wrap wrap, const vec4f &borderColor) |
Convenience function to create an array leaf (needed as until c++17 there is no template type deduction from constructor arguments) | |
template<typename T> | |
auto | makeArray (const SharedImageSet &img, bool ignoreShiftAndScale, MagFilter magFilter, Wrap wrap, const vec4f &borderColor) |
Convenience function to create an array leaf (needed as until c++17 there is no template type deduction from constructor arguments) | |
template<typename T, int Dim> | |
ChannelWiseScalar< T, Dim > | makeChannelWiseScalar (Eigen::Matrix< T, Dim, 1 > val) |
Convenience function to create a channel wise scalar leaf (needed as until c++17 there is no template type deduction from constructor arguments) | |
template<typename T> | |
Coordinates< const TypedImage< T > > | makeCoordinates (const TypedImage< T > &img, CoordinateType coordType=CoordinateType::World) |
This function creates a suitable Coordinates object. | |
template<typename T> | |
Noise< const TypedImage< T > > | makeNoise (const TypedImage< T > &img, NoiseType noiseType=NoiseType::Gaussian, float alpha=0.0, float beta=1.0, int seed=0) |
This function creates a suitable Noise object. | |
template<typename T> | |
Scalar< typename std::decay_t< T > > | makeScalar (T &&val) |
Convenience function to create a scalar leaf (needed as until c++17 there is no template type deduction from constructor arguments) | |
template<typename T> | |
Scalar< typename std::decay_t< T > & > | makeScalarWrapper (T &val) |
Convenience function to create a scalar leaf wrapping a scalar variable (needed as until c++17 there is no template type deduction from constructor arguments) | |
Coordinates< const TypedImage< T > > makeCoordinates | ( | const TypedImage< T > & | img, |
CoordinateType | coordType = CoordinateType::World ) |
#include <ImFusion/ImageMath/Tpl/Coordinates.h>
This function creates a suitable Coordinates object.
It is needed, as C++ only allows template deduction from constructor arguments in C++17
Noise< const TypedImage< T > > makeNoise | ( | const TypedImage< T > & | img, |
NoiseType | noiseType = NoiseType::Gaussian, | ||
float | alpha = 0.0, | ||
float | beta = 1.0, | ||
int | seed = 0 ) |
#include <ImFusion/ImageMath/Tpl/Noise.h>
This function creates a suitable Noise object.
It is needed, as C++ only allows template deduction from constructor arguments in C++17