ImFusion SDK 4.3
MemImage Class Referenceabstract

#include <ImFusion/Base/MemImage.h>

Abstract base class for an image residing in main memory. More...

+ Inheritance diagram for MemImage:

Detailed Description

Abstract base class for an image residing in main memory.

Use the templated TypedImage to instantiate a MemImage for a concrete pixel type.

See also
Using Image Data, ImageProcessing
Examples
SqrtAlgorithm.cpp.

Public Types

enum class  Ownership { NotOwning = 0 , Owning = 1 }
 Enumeration to describe image data pointer ownership. More...
 
- Public Types inherited from Image
enum  Type {
  BYTE = static_cast<int>(PixelType::Byte) , UBYTE = static_cast<int>(PixelType::UByte) , SHORT = static_cast<int>(PixelType::Short) , USHORT = static_cast<int>(PixelType::UShort) ,
  INT = static_cast<int>(PixelType::Int) , UINT = static_cast<int>(PixelType::UInt) , FLOAT = static_cast<int>(PixelType::Float) , DOUBLE = static_cast<int>(PixelType::Double) ,
  HFLOAT = static_cast<int>(PixelType::HFloat)
}
 Pixel/voxel data type, equivalent to OpenGL defines. More...
 
enum  Location {
  NONE = 0 , MEMORY = 1 , OPENGL = 2 , OPENCL = 3 ,
  CUSTOM = 6
}
 Location where the data resides. More...
 

Public Member Functions

std::unique_ptr< MemImageclone () const
 Create a deep copy of the image.
 
virtual bool update (const MemImage &img)=0
 Update image data.
 
template<typename T>
TypedImage< T > * typed ()
 Convenience function to perform a dynamic_cast<TypedImage<T>> of this instance.
 
template<typename T>
const TypedImage< T > * typed () const
 
Location location () const override
 Specifies that the image resides in main memory.
 
bool load (const std::string &filename, int64_t offset=0)
 Loads the image content from a file, returns true if successful.
 
bool save (const std::string &filename) const
 Saves the image content to a file, returns true if successful.
 
virtual const void * data () const =0
 Returns a void pointer to the underlying raw pixel buffer of the image.
 
virtual void * data ()=0
 
virtual double valueDouble (size_t index) const =0
 Return the pixel intensity at the given index without interpolation casted to double.
 
virtual double valueDouble (int x, int y, int z=0, int c=0) const =0
 Return the pixel intensity at the coordinate without interpolation casted to double.
 
virtual double valueDouble (double x, double y, double z=0, int c=0, bool clamp=true, bool *valid=nullptr) const =0
 Return the pixel intensity at the given coordinate using linear interpolation casted to double.
 
virtual void setValueDouble (double value, size_t index) const =0
 Set the pixel intensity at the given index to value casted to the underlying type without any clamping or normalization.
 
virtual void setValueDouble (double value, int x, int y, int z=0, int c=0) const =0
 Set the pixel intensity at the given coordinate to value casted to the underlying type without any clamping or normalization.
 
std::pair< double, double > getRangeDouble () const
 Computes the minimum and maximum image intensity of the entire image casted to double.
 
virtual void getRangeDouble (double &minVal, double &maxVal) const =0
 
std::unique_ptr< MemImagegetSliceView (int slice) const
 Extract a MemImage representing a view onto the specified slice of this image.
 
virtual void fillDouble (double value)=0
 Fill image with the given double value for all channels and pixels.
 
virtual void fillDouble (const std::vector< double > &channelValues)=0
 Fill image with the given double channel values for all pixels.
 
- Public Member Functions inherited from Image
 Image (const ImageDescriptor &desc)
 Create a new Image with the given descriptor.
 
 Image (const Image &other)=default
 
Imageoperator= (const Image &other)=default
 
 Image (Image &&other) noexcept=default
 
Imageoperator= (Image &&other) noexcept=default
 
const ImageDescriptordescriptor () const
 Return the image descriptor.
 
void configure (const Properties *p) override
 Configure the image descriptor from properties.
 
void configuration (Properties *p) const override
 Store image descriptor into properties.
 
void setShift (double val)
 Sets the intensity shift value.
 
void setScale (double val)
 Sets the intensity scale value.
 
void setSpacing (double sx, double sy, double sz=1.0)
 Specify pixel/voxel spacing with two or three scalar values.
 
void setSpacing (double sx, double sy, double sz, bool isMetric)
 Convenience function for specifying spacing and metric flag at the same time.
 
void setSpacing (const vec3 &s)
 Specify pixel/voxel spacing using a 3-vector.
 
void setSpacing (const vec3 &s, bool metric)
 Convenience function for specifying spacing and metric flag at the same time.
 
void setMetric (bool val)
 Set data to be metric.
 
double storageToOriginal (double value) const
 Applies the image's shift and scale in order to convert value from storage pixel value domain to original pixel value domain.
 
double originalToStorage (double value) const
 Applies the image's shift and scale in order to convert value from original pixel value domain to storage pixel value domain.
 
PixelType pixelType () const
 Returns the data type of the image.
 
Type type () const
 Returns the data type of the image.
 
int width () const
 Returns the width of the image.
 
int height () const
 Returns the height of the image.
 
int slices () const
 Returns the number of 3D slices of the image.
 
int channels () const
 Returns the number of channels of the image.
 
double shift () const
 Returns the intensity shift.
 
double scale () const
 Returns the intensity scale.
 
vec3 spacing () const
 Returns pointer to the pixel/voxel spacing values.
 
bool isMetric () const
 Returns true if data is metric.
 
vec3 extent () const
 Returns the physical size of the image as a vector.
 
vec3i dimensions () const
 Returns the dimensions of the image in pixels as a vector.
 
vec3 pixelToImage (const vec3 &pixel) const
 Convert a 3D pixel/voxel position to image coordinates.
 
vec3 imageToPixel (const vec3 &world) const
 Convert 3D image coordinates to pixel/voxel position.
 
mat4 pixelToImageMatrix () const
 Returns a 4x4 matrix to transform from image pixel space to image space.
 
mat4 imageToPixelMatrix () const
 Returns a 4x4 matrix to transform from image space to image pixel space.
 
size_t index (int x, int y, int z=0, int c=0) const
 Returns a linear memory index for a pixel or voxel.
 
bool hasIndex (int x, int y, int z=0, int c=0) const
 Returns true if the pixel at (x,y,z) exists, false otherwise.
 
vec4i coord (size_t index) const
 Returns the pixel/voxel coordinate (x,y,z,c) for a given index.
 
size_t size () const
 Returns the size (number of elements) of the image.
 
int typeSize () const
 Return the nominal size in bytes of standard data types, zero if unknown.
 
bool isInteger () const
 Returns whether the image is of an integer data type.
 
bool isSigned () const
 Returns whether the image type supports negative values.
 
size_t byteSize () const
 Returns the size of the image in bytes.
 
int alignment () const
 Returns the byte alignment of an image line (up to 8)
 
int dimension () const
 Returns the spatial dimension of the image.
 
bool compatible (const Image &other, bool ignoreType=false, bool ignore3D=false, bool ignoreChannels=false) const
 Tells if this image is compatible to another one.
 
- Public Member Functions inherited from Configurable
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
 
Configurableoperator= (const Configurable &)
 
Configurableoperator= (Configurable &&) noexcept
 

Static Public Member Functions

static std::unique_ptr< MemImagecreate (const ImageDescriptor &descriptor)
 Factory method to instantiate a MemImage from an ImageDescriptor.
 
static std::unique_ptr< MemImagecreate (const ImageDescriptor &descriptor, void *data, Ownership own=Ownership::NotOwning)
 Factory method to instantiate a MemImage from an ImageDescriptor and pointer to existing image data.
 
static std::unique_ptr< MemImagezeros (const ImageDescriptor &descriptor)
 Factory method to create a zero-initialized image.
 

Protected Member Functions

 MemImage (MemImage &&other) noexcept
 
MemImageoperator= (MemImage &&other) noexcept
 
 MemImage (const MemImage &other)=delete
 
MemImageoperator= (const MemImage &other)=delete
 
 MemImage (const ImageDescriptor &desc)
 
virtual MemImagecloneImpl () const =0
 
virtual std::unique_ptr< MemImagegetSliceViewImpl (int slice) const =0
 
- Protected Member Functions inherited from Image
template<typename T>
bool typeCompatible () const
 

Deprecated Interface

virtual std::unique_ptr< MemImageprepare (bool msb=false, bool shiftOnly=false)=0
 Optimal rescaling and conversion to unsigned data type if applicable.
 
virtual std::unique_ptr< MemImageunscaled () const =0
 Return copy of this image with intensity scale and shift undone, if necessary.
 

Additional Inherited Members

- Public Attributes inherited from Configurable
Signal signalParametersChanged
 Emitted whenever one of the registered Parameters' or SubPropertys' signalValueChanged signal was emitted.
 
- Protected Attributes inherited from Image
ImageDescriptor m_descriptor
 
- Protected Attributes inherited from Configurable
std::vector< Paramm_params
 List of all registered Parameter and SubProperty instances.
 

Member Enumeration Documentation

◆ Ownership

enum class Ownership
strong

Enumeration to describe image data pointer ownership.

Enumerator
NotOwning 

MemImage will not take ownership of the pointer, pointer must remain valid for the lifetime of the image.

Owning 

MemImage will take ownership of the pointer, will delete it on destruction.

Member Function Documentation

◆ create() [1/2]

static std::unique_ptr< MemImage > create ( const ImageDescriptor & descriptor)
static

Factory method to instantiate a MemImage from an ImageDescriptor.

Note
This method does not initialize the underlying buffer Will internally dispatch to TypedImage<T>::create() based on the pixel type of descriptor.

◆ create() [2/2]

static std::unique_ptr< MemImage > create ( const ImageDescriptor & descriptor,
void * data,
Ownership own = Ownership::NotOwning )
static

Factory method to instantiate a MemImage from an ImageDescriptor and pointer to existing image data.

Will internally dispatch to TypedImage<T>::create() based on the pixel type of descriptor.

Parameters
descriptorImageDescriptor of the new image.
dataPointer to image data, must match the descriptor layout.
ownFlag whether the newly created image shall take ownership of data.

◆ update()

virtual bool update ( const MemImage & img)
pure virtual

◆ typed()

template<typename T>
TypedImage< T > * typed ( )

Convenience function to perform a dynamic_cast<TypedImage<T>> of this instance.

Returns nullptr if image is not of type T.

◆ location()

Location location ( ) const
inlineoverridevirtual

Specifies that the image resides in main memory.

Reimplemented from Image.

◆ data()

virtual const void * data ( ) const
pure virtual

Returns a void pointer to the underlying raw pixel buffer of the image.

Note
The TypedImage<T> specialization provides pointer() as type-safe alternative.

Implemented in TypedImage< T >, TypedImage< float >, TypedImage< int >, TypedImage< uint8_t >, TypedImage< unsigned char >, and TypedImage< unsigned short >.

◆ valueDouble() [1/3]

virtual double valueDouble ( size_t index) const
pure virtual

Return the pixel intensity at the given index without interpolation casted to double.

Implemented in TypedImage< T >, TypedImage< float >, TypedImage< int >, TypedImage< uint8_t >, TypedImage< unsigned char >, and TypedImage< unsigned short >.

Examples
SqrtAlgorithm.cpp.

◆ valueDouble() [2/3]

virtual double valueDouble ( int x,
int y,
int z = 0,
int c = 0 ) const
pure virtual

Return the pixel intensity at the coordinate without interpolation casted to double.

Note
Try to avoid calling this function repeatedly because the coordinate-to-index computation is slow. When accessing entire regions of the image prefer use the index-based overload incrementing the index by a suitable stride after each function call instead of always fully recomputing the index.

Implemented in TypedImage< T >, TypedImage< float >, TypedImage< int >, TypedImage< uint8_t >, TypedImage< unsigned char >, and TypedImage< unsigned short >.

◆ valueDouble() [3/3]

virtual double valueDouble ( double x,
double y,
double z = 0,
int c = 0,
bool clamp = true,
bool * valid = nullptr ) const
pure virtual

Return the pixel intensity at the given coordinate using linear interpolation casted to double.

Note
Be aware that this function is rather slow, use it only if you really need interpolation. Consider using the set of free functions in Math::Interpolation as they provide more control on the interpolation behavior.

Implemented in TypedImage< T >, TypedImage< float >, TypedImage< int >, TypedImage< uint8_t >, TypedImage< unsigned char >, and TypedImage< unsigned short >.

◆ setValueDouble() [1/2]

virtual void setValueDouble ( double value,
size_t index ) const
pure virtual

Set the pixel intensity at the given index to value casted to the underlying type without any clamping or normalization.

Implemented in TypedImage< T >, TypedImage< float >, TypedImage< int >, TypedImage< uint8_t >, TypedImage< unsigned char >, and TypedImage< unsigned short >.

Examples
SqrtAlgorithm.cpp.

◆ setValueDouble() [2/2]

virtual void setValueDouble ( double value,
int x,
int y,
int z = 0,
int c = 0 ) const
pure virtual

Set the pixel intensity at the given coordinate to value casted to the underlying type without any clamping or normalization.

Note
Try to avoid calling this function repeatedly because the coordinate-to-index computation is slow. When accessing entire regions of the image prefer use the index-based overload incrementing the index by a suitable stride after each function call instead of always fully recomputing the index.

Implemented in TypedImage< T >, TypedImage< float >, TypedImage< int >, TypedImage< uint8_t >, TypedImage< unsigned char >, and TypedImage< unsigned short >.

◆ getRangeDouble()

virtual void getRangeDouble ( double & minVal,
double & maxVal ) const
pure virtual

◆ getSliceView()

std::unique_ptr< MemImage > getSliceView ( int slice) const

Extract a MemImage representing a view onto the specified slice of this image.

The returned image only points to the data and does not own it. It is therefore only valid as long this image is valid. Returns nullptr if slice is out of range.

◆ fillDouble() [1/2]

virtual void fillDouble ( double value)
pure virtual

Fill image with the given double value for all channels and pixels.

Note
The passed value will be casted to the underlying type of the image.

Implemented in TypedImage< T >, TypedImage< float >, TypedImage< int >, TypedImage< uint8_t >, TypedImage< unsigned char >, and TypedImage< unsigned short >.

◆ fillDouble() [2/2]

virtual void fillDouble ( const std::vector< double > & channelValues)
pure virtual

Fill image with the given double channel values for all pixels.

Note
The passed value will be casted to the underlying type of the image. The number of elements in channelValues must match the number of channels of this image.

Implemented in TypedImage< T >, TypedImage< float >, TypedImage< int >, TypedImage< uint8_t >, TypedImage< unsigned char >, and TypedImage< unsigned short >.

◆ prepare()

virtual std::unique_ptr< MemImage > prepare ( bool msb = false,
bool shiftOnly = false )
pure virtual

Optimal rescaling and conversion to unsigned data type if applicable.

Deprecated
"Use ImageProcessing::createConverted() and/or ImageProcessing::swapEndianness() instead."

Implemented in TypedImage< T >, TypedImage< float >, TypedImage< int >, TypedImage< uint8_t >, TypedImage< unsigned char >, and TypedImage< unsigned short >.

◆ unscaled()

virtual std::unique_ptr< MemImage > unscaled ( ) const
pure virtual

Return copy of this image with intensity scale and shift undone, if necessary.

The method returns a zero pointer if there is no scale and shift and if the image has a floating-point data type.

Deprecated
"Use ImageProcessing::createConverted() instead."

Implemented in TypedImage< T >, TypedImage< float >, TypedImage< int >, TypedImage< uint8_t >, TypedImage< unsigned char >, and TypedImage< unsigned short >.


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