Public Member Functions | Protected Attributes | List of all members
mirtk::ImageRegion Class Reference

#include <ImageRegion.h>

Collaboration diagram for mirtk::ImageRegion:
Collaboration graph

Public Member Functions

int BeginT () const
 Get start of image region to iterate over in t dimension.
 
int BeginX () const
 Get start of image region to iterate over in x dimension.
 
int BeginY () const
 Get start of image region to iterate over in y dimension.
 
int BeginZ () const
 Get start of image region to iterate over in z dimension.
 
int ColumnStride () const
 Get stride between columns in number of voxels.
 
int EndT () const
 Get end of image region to iterate over in t dimension.
 
int EndX () const
 Get end of image region to iterate over in x dimension.
 
int EndY () const
 Get end of image region to iterate over in y dimension.
 
int EndZ () const
 Get end of image region to iterate over in z dimension.
 
int FrameStride () const
 Get stride between frames in number of voxels.
 
template<class VoxelType >
const VoxelType * GetPointerToBegin (const BaseImage &) const
 Get raw image pointer to first voxel of of region.
 
template<class VoxelType >
const VoxelType * GetPointerToBegin (const BaseImage *) const
 Get raw image pointer to first voxel of of region.
 
template<class VoxelType >
const VoxelType * GetPointerToBegin (const GenericImage< VoxelType > &) const
 Get raw image pointer to first voxel of of region.
 
template<class VoxelType >
VoxelType * GetPointerToBegin (GenericImage< VoxelType > &) const
 Get raw image pointer to first voxel of of region.
 
template<class VoxelType >
const VoxelType * GetPointerToBegin (const GenericImage< VoxelType > *) const
 Get raw image pointer to first voxel of of region.
 
template<class VoxelType >
VoxelType * GetPointerToBegin (GenericImage< VoxelType > *) const
 Get raw image pointer to first voxel of of region.
 
template<class VoxelType >
const VoxelType * GetPointerToEnd (const BaseImage &) const
 Get raw image pointer to last voxel image of region.
 
template<class VoxelType >
const VoxelType * GetPointerToEnd (const BaseImage *) const
 Get raw image pointer to last voxel image of region.
 
template<class VoxelType >
const VoxelType * GetPointerToEnd (const GenericImage< VoxelType > &) const
 Get raw image pointer to last voxel image of region.
 
template<class VoxelType >
VoxelType * GetPointerToEnd (GenericImage< VoxelType > &) const
 Get raw image pointer to last voxel image of region.
 
template<class VoxelType >
const VoxelType * GetPointerToEnd (const GenericImage< VoxelType > *) const
 Get raw image pointer to last voxel image of region.
 
template<class VoxelType >
VoxelType * GetPointerToEnd (GenericImage< VoxelType > *) const
 Get raw image pointer to last voxel image of region.
 
 ImageRegion (const ImageAttributes &)
 Constructor.
 
 ImageRegion (const ImageAttributes &, const blocked_range2d< int > &)
 Constructor.
 
 ImageRegion (const ImageAttributes &, const blocked_range3d< int > &)
 Constructor.
 
 ImageRegion (const BaseImage &)
 Constructor.
 
 ImageRegion (const BaseImage &, const blocked_range2d< int > &)
 Constructor.
 
 ImageRegion (const BaseImage &, const blocked_range3d< int > &)
 Constructor.
 
 ImageRegion (const BaseImage *)
 Constructor.
 
 ImageRegion (const BaseImage *, const blocked_range2d< int > &)
 Constructor.
 
 ImageRegion (const BaseImage *, const blocked_range3d< int > &)
 Constructor.
 
 ImageRegion (const ImageRegion &)
 Copy constructor.
 
void Initialize ()
 
bool IsImageSequence () const
 
bool IsScalar () const
 
bool IsScalarImage () const
 
bool IsSequence () const
 
int LineStride () const
 Get stride between rows/lines in number of voxels.
 
int MaxNumberOfChannels () const
 Get number of channels in set image region.
 
int MaxNumberOfComponents () const
 Get number of vector components in set image region.
 
int MaxNumberOfFrames () const
 Get number of frames in set image region.
 
int MaxNumberOfVoxels () const
 Number of voxels in set image region.
 
int NumberOfChannels () const
 Get number of channels in overlap of set image region and image domain.
 
int NumberOfComponents () const
 Get number of vector components in overlap of set image region and image domain.
 
int NumberOfFrames () const
 Get number of frames in overlap of set image region and image domain.
 
int NumberOfImageChannels () const
 
int NumberOfImageVoxels () const
 Number of voxels in the entire image.
 
int NumberOfSequenceFrames () const
 
int NumberOfVectorComponents () const
 
int NumberOfVoxels () const
 Number of voxels in overlap of set image region and image domain.
 
ImageRegionoperator= (const ImageRegion &)
 Assignment operator.
 
void SetCenter (int, int, int=0, int=-1)
 Set center of image region.
 
void SetChannel (int)
 Set temporal region.
 
void SetChannel (int, int)
 Set temporal region.
 
void SetChannel (const blocked_range< int > &)
 Set temporal region.
 
void SetComponent (int)
 Set temporal region.
 
void SetComponent (int, int)
 Set temporal region.
 
void SetComponent (const blocked_range< int > &)
 Set temporal region.
 
void SetFrame (int)
 Set temporal region.
 
void SetFrame (int, int)
 Set temporal region.
 
void SetFrame (const blocked_range< int > &)
 Set temporal region.
 
void SetNeighborhood (int, int, int, int)
 Set 2D neighborhood.
 
void SetNeighborhood (int, int, int, int, int, int)
 Set 3D neighborhood.
 
void SetNeighborhood (int, int, int, int, int, int, int, int)
 Set 4D neighborhood.
 
void SetRadius (int)
 Set radius of image region.
 
void SetRadius (int, int, int=0, int=0)
 Set radius of image region.
 
void SetRegion (int, int, int, int)
 Set 2D image region.
 
void SetRegion (const blocked_range2d< int > &)
 Set 2D image region.
 
void SetRegion (int, int, int, int, int, int)
 Set 3D image region.
 
void SetRegion (const blocked_range3d< int > &)
 Set 3D image region.
 
void SetRegion (int, int, int, int, int, int, int, int)
 Set 4D image region.
 
void SetSize (int)
 Set size of image region.
 
void SetSize (int, int, int=1, int=1)
 Set size of image region.
 
void SetStart (int, int, int=0, int=-1)
 Set start of image region.
 
int SliceStride () const
 Get stride between slices in number of voxels.
 
 ~ImageRegion ()
 Destructor.
 

Protected Attributes

Vector4D< int > _Begin
 First index of actual image region.
 
Vector4D< int > _DataSize
 Size of the entire image.
 
Vector4D< int > _End
 Last index of actual image region.
 
int _FrameStride
 Increment at end of frame in number of voxels.
 
Vector4D< int > _Index
 Start of set image region.
 
bool _IsImageSequence
 Whether the image is a sequence.
 
int _LineStride
 Increment at end of line in number of voxels.
 
Vector4D< int > _Size
 Size of set image region.
 
int _SliceStride
 Increment at end of slice in number of voxels.
 

Detailed Description

Helper for iterating over an image region using raw image pointers

This class makes it convenient to set a specific image region using one or more of the many available setter methods and calculates the start and end index of the first and last voxel in the region. Moreover, it computes how many voxels have to be skipped when moving from one line of the image to another, from one slice to another, or from one frame of an image sequence to another. It therefore helps to iterate over the set image region using a pointer to the image data. This makes the low-level iteration of an image using such fast image pointers more convenient to implement.

An instance of this class does not keep track of the current position of the image pointer. It can therefore not tell when it reached the end of a line, slice, or image frame/channel. This lies yet in the responsibility of the user.

Note that a single instance can (and for the sake of speed should be) used to move pointers to more than one image if needed. Herefore, all images must have the same size, however. Otherwise, use different instances.

The following example demonstrates how to iterate over a 5x5x3 neighborhood of a 3D image centered at voxel (128, 128, 64).

GreyImage im(256, 256, 128);
ImageRegion it(image);
// Set image region to iterate over
it.SetCenter(128, 128, 64);
it.SetRadius( 5, 5, 3);
// Get pointer to start of image region
GreyPixel *p = it.GetPointerToBegin(image);
// Use image iterator to advance pointer from one voxel to the other
// while iterating over the voxels of the set image region
GreyPixel min = MIRTK_MAX_GREY;
GreyPixel max = MIRTK_MIN_GREY;
for (int k = it.BeginZ(); k != it.EndZ(); ++k) {
for (int j = it.BeginY(); j != it.EndY(); ++j) {
for (int i = it.BeginX(); i != it.EndX(); ++i) {
if (*p < min) min = *p;
if (*p > max) max = *p;
it.ToNextColumn(p);
}
it.ToNextLine(p);
}
it.ToNextSlice(p);
}
See also
See ConstImageIterator, ImageIterator, ConstGenericImageIterator, and GenericImageIterator for more advanced image iterators which do not require the use of up to four for-loops, but only one while-loop as these keep track of the position of the iterator themselves and decide with each increment whether to move the iterator to the next column, line, slice, or frame/channel. This, however, comes with the expense of more decisions and operations to be made per voxel and results in a noticeably slower iteration.
ForEachVoxel template functions for another convenient and fast way of performing a single operation per voxel. An example of such operation is the GetMin class which can be used as Operation template argument of the ForEachVoxel functions. These template functions and basic voxel-wise operators are defined in the mirtkVoxelFunction.h header file.

Definition at line 180 of file ImageRegion.h.

Member Function Documentation

§ Initialize()

void mirtk::ImageRegion::Initialize ( )
inline

Initialize iteration range and calculate strides

This method determines the begin and end indices of the image region and reduces the size of the region in each dimension individually if it is outside the image domain. Use IsOutside to check if the resulting image region is completely outside the image domain and NumberOfVoxels to get the actual number of voxels that are within the overlap of the set image region and the image domain.

The Initialize method is called by GetPointerToBegin or GetPointerToEnd when necessary, i.e., when the image region has been modified. If the image pointer is initialized otherwise, the Initialize method has to be called explicitly after the region has been specified. Note that the constructor initializes the iterator already. Thus, if the region is not adjusted after construction of the iterator, there is no need to re-initialize it.

Definition at line 526 of file ImageRegion.h.

§ IsImageSequence()

bool mirtk::ImageRegion::IsImageSequence ( ) const
inline

Whether the image is a 3D+t image sequence (i.e., number of voxels in t dimension > 1 and dt > 0)

Definition at line 554 of file ImageRegion.h.

§ IsScalar()

bool mirtk::ImageRegion::IsScalar ( ) const
inline

Whether the image region is scalar (i.e., number of voxels in t dimension is 1)

Definition at line 600 of file ImageRegion.h.

§ IsScalarImage()

bool mirtk::ImageRegion::IsScalarImage ( ) const
inline

Whether the image is a scalar image (i.e., number of voxels in t dimension is 1)

Definition at line 560 of file ImageRegion.h.

§ IsSequence()

bool mirtk::ImageRegion::IsSequence ( ) const
inline

Whether the image region is a 3D+t image sequence (i.e., number of voxels in t dimension > 1 and dt > 0)

Definition at line 594 of file ImageRegion.h.

§ NumberOfImageChannels()

int mirtk::ImageRegion::NumberOfImageChannels ( ) const
inline

Get number of image channels (i.e., number of voxels in t dimension if dt <= 0 or 1 otherwise)

Definition at line 572 of file ImageRegion.h.

§ NumberOfSequenceFrames()

int mirtk::ImageRegion::NumberOfSequenceFrames ( ) const
inline

Get number of iterated frames (i.e., number of voxels in t dimension if dt > 0 or 1 otherwise)

Definition at line 584 of file ImageRegion.h.

§ NumberOfVectorComponents()

int mirtk::ImageRegion::NumberOfVectorComponents ( ) const
inline

Get number of vector components (i.e., number of voxels in t dimension if dt <= 0 or 1 otherwise)

Definition at line 578 of file ImageRegion.h.


The documentation for this class was generated from the following file: