Skip to content

shapeworks::Image

Module: Image Classes

More...

#include <Image.h>

Public Types

Name
enum InterpolationType
using float PixelType
using itk::Image< PixelType, 3 > ImageType
using itk::StatisticsImageFilter< ImageType >::Pointer StatsPtr
using itk::ImageRegionIterator< ImageType > ImageIterator
using itk::LinearInterpolateImageFunction< ImageType > InterpolatorType

Public Functions

Name
Image(const Dims dims)
Image(const std::string & pathname)
Image(ImageType::Pointer imagePtr)
Image(const vtkSmartPointer< vtkImageData > vtkImage)
Image(Image && img)
Image(const Image & img)
Image & operator=(const Image & img)
Image & operator=(Image && img)
lvalue assignment operator
operator ImageType::Pointer()
rvalue assignment operator
ImageType::Pointer getITKImage() const
vtkSmartPointer< vtkImageData > getVTKImage() const
creates a VTK filter for the given image
Image & operator-()
negation operator
Image operator+(const Image & other) const
plus operator to add two images
Image & operator+=(const Image & other)
Image operator-(const Image & other) const
minus operator to add two images
Image & operator-=(const Image & other)
Image operator*(const Image & other) const
multiply operator to multiply two images
Image operator*(const PixelType x) const
multiply operator to scale contents of an image
Image & operator*=(const PixelType x)
Image operator/(const PixelType x) const
divide operator to scale contents of an image
Image & operator/=(const PixelType x)
Image operator+(const PixelType x) const
plus operator to shift contents of an image
Image & operator+=(const PixelType x)
Image operator-(const PixelType x) const
minus operator to shift contents of an image
Image & operator-=(const PixelType x)
Image & antialias(unsigned iterations =50, double maxRMSErr =0.01f, int layers =3)
antialiases image
Image & recenter()
Image & resample(const TransformPtr transform, const Point3 origin, const Dims dims, const Vector3 spacing, const ImageType::DirectionType direction, InterpolationType interp =NearestNeighbor)
Image & resample(const Vector & physicalSpacing, InterpolationType interp =Linear)
resamples image using new physical spacing, updating logical dims to keep all image data for this spacing
Image & resample(double isoSpacing =1.0, InterpolationType interp =Linear)
resamples image using isotropic physical spacing
Image & resize(Dims logicalDims, InterpolationType interp =Linear)
Image & pad(int padding, PixelType value =0.0)
pads an image by same number of voxels in all directions with constant value
Image & pad(int padx, int pady, int padz, PixelType value =0.0)
pads an image by desired number of voxels in each direction with constant value
Image & pad(IndexRegion & region, PixelType value =0.0)
pads an image to include the given region with constant value
Image & translate(const Vector3 & v)
helper to simply translate image
Image & scale(const Vector3 & v)
helper to simply scale image around center (not origin)
Image & rotate(const double angle, const Vector3 & axis)
helper to simply rotate around axis through center (not origin) by given angle (in radians)
Image & rotate(const double angle, Axis axis)
helper to simply rotate around axis through center (not origin) by given angle (in radians)
TransformPtr createCenterOfMassTransform()
creates a transform that translates center of mass to center of image
TransformPtr createRigidRegistrationTransform(const Image & target_dt, float isoValue =0.0, unsigned iterations =20)
Image & applyTransform(const TransformPtr transform, InterpolationType interp =Linear)
applies the given transformation to the image by using resampling filter
Image & applyTransform(const TransformPtr transform, const Point3 origin, const Dims dims, const Vector3 spacing, const ImageType::DirectionType direction, InterpolationType interp =NearestNeighbor)
Image & applyTransform(const TransformPtr transform, const Image & referenceImage, InterpolationType interp =Linear)
applies the given transformation to the image by using resampling filter with reference image
Image & extractLabel(const PixelType label =1.0)
Image & closeHoles(const PixelType foreground =0.0)
closes holes in a given volume, default foreground value assumes a binary volume
Image & binarize(PixelType minVal =0.0, PixelType maxVal =std::numeric_limits< PixelType >::max(), PixelType innerVal =1.0, PixelType outerVal =0.0)
threholds image into binary label based on upper and lower intensity bounds given by user
Image & computeDT(PixelType isoValue =0.0)
computes distance transform volume from a (preferably antialiased) binary image using the specified isovalue
Image & applyCurvatureFilter(unsigned iterations =10)
denoises an image using curvature driven flow using curvature flow image filter
Image & applyGradientFilter()
computes gradient magnitude at each pixel using gradient magnitude filter
Image & applySigmoidFilter(double alpha =10.0, double beta =10.0)
computes sigmoid function pixel-wise using sigmoid image filter
Image & applyTPLevelSetFilter(const Image & featureImage, double scaling =20.0)
segements structures in images using topology preserving geodesic active contour level set filter
Image & topologyPreservingSmooth(float scaling =20.0, float sigmoidAlpha =10.5, float sigmoidBeta =10.0)
Image & applyIntensityFilter(double minVal, double maxVal)
applies intensity windowing image filter
Image & gaussianBlur(double sigma =0.0)
applies gaussian blur with given sigma
Image & crop(PhysicalRegion region, const int padding =0)
crops the image down to the given region, with optional padding added
Image & fitRegion(PhysicalRegion region, const PixelType value =0.0)
crops (or pads) the image to fit the given region
Image & clip(const Plane plane, const PixelType val =0.0)
clips an image using a cutting plane
Image & reflect(const Axis & axis)
Image & setOrigin(Point3 origin =Point3({0, 0, 0}))
sets the image origin in physical space to the given value
Image & setSpacing(Vector3 spacing)
sets the image spacing to the given value
Image & setCoordsys(ImageType::DirectionType coordsys)
sets the coordinate system in which this image lives in physical space
Image & isolate()
isolate the largest object in a binary segmentation
Dims dims() const
logical dimensions of the image
Point3 size() const
physical dimensions of the image (dims * spacing)
double get_largest_dimension_size() const
largest dimension size
Vector spacing() const
physical spacing of the image
double get_minimum_spacing() const
minimum physical spacing of the image
Point3 origin() const
physical coordinates of image origin
Point3 center() const
physical coordinates of center of this image
ImageType::DirectionType coordsys() const
return coordinate system in which this image lives in physical space
Point3 centerOfMass(PixelType minVal =0.0, PixelType maxVal =1.0) const
returns average physical coordinate of pixels in range (minval, maxval]
PixelType min()
minimum of image
PixelType max()
maximum of image
PixelType mean()
mean of image
PixelType std()
standard deviation of image
IndexRegion logicalBoundingBox() const
bounding box of complete image in logical (index) space
PhysicalRegion physicalBoundingBox() const
bounding box of complete image in physical space
PhysicalRegion physicalBoundingBox(PixelType isovalue) const
bounding box of largest region of data >= the given isoValue in physical space
PhysicalRegion logicalToPhysical(IndexRegion region) const
converts a bounding box in logical (index) space to this image's index coordinates
IndexRegion physicalToLogical(PhysicalRegion region) const
converts a bounding box in physical space to this image's logical (index) coordinates
Point3 logicalToPhysical(const Coord & c) const
converts from pixel coordinates to physical space
Coord physicalToLogical(const Point3 & p) const
converts from a physical coordinate to a logical coordinate
bool isInside(const Point3 & p) const
checks if a given point is inside the image
ImageIterator iterator()
creates an image iterator and returns it
bool compare(const Image & other, bool verifyall =true, double tolerance =0.0, double precision =1e-6) const
compares this with another image using the region of interest filter
bool operator==(const Image & other) const
compares this with another image using the region of interest filter
Image & write(const std::string & filename, bool compressed =true)
writes image, format specified by filename extension
Mesh toMesh(PixelType isovalue) const
converts image to mesh
Image::PixelType evaluate(Point p)
Evaluates the image at a given position.
void paintSphere(Point p, double radius, PixelType value)
Paints a sphere in the image.
void paintCircle(Point p, double radius, unsigned int axis, PixelType value)
Paints a circle in the image.
bool isPainted() const
Returns if the image has been painted.
Image & fill(PixelType value)
fill with value
bool isDistanceTransform() const
Return if the image is a distance transform.
std::vector< std::string > getSupportedTypes()
Return supported file types.
bool isSupportedType(const std::string & filename)
Return if the file type is supported.

Friends

Name
struct SharedCommandData

Detailed Description

cpp class shapeworks::Image;

This class represents a 3D image volume and operations that can be performed on images.

Public Types Documentation

enum InterpolationType

Enumerator Value Description
Linear
NearestNeighbor

using PixelType

cpp using shapeworks::Image::PixelType = float;

using ImageType

cpp using shapeworks::Image::ImageType = itk::Image<PixelType, 3>;

using StatsPtr

cpp using shapeworks::Image::StatsPtr = itk::StatisticsImageFilter<ImageType>::Pointer;

using ImageIterator

cpp using shapeworks::Image::ImageIterator = itk::ImageRegionIterator<ImageType>;

using InterpolatorType

cpp using shapeworks::Image::InterpolatorType = itk::LinearInterpolateImageFunction<ImageType>;

Public Functions Documentation

function Image

cpp explicit Image( const Dims dims )

function Image

cpp inline explicit Image( const std::string & pathname )

function Image

cpp inline explicit Image( ImageType::Pointer imagePtr )

function Image

cpp explicit Image( const vtkSmartPointer< vtkImageData > vtkImage )

function Image

cpp inline Image( Image && img )

function Image

cpp inline Image( const Image & img )

function operator=

cpp Image & operator=( const Image & img )

function operator=

cpp Image & operator=( Image && img )

lvalue assignment operator

function operator ImageType::Pointer

cpp inline operator ImageType::Pointer()

rvalue assignment operator

return this as an ITK image

function getITKImage

cpp inline ImageType::Pointer getITKImage() const

function getVTKImage

cpp vtkSmartPointer< vtkImageData > getVTKImage() const

creates a VTK filter for the given image

function operator-

cpp Image & operator-()

negation operator

function operator+

cpp Image operator+( const Image & other ) const

plus operator to add two images

function operator+=

cpp Image & operator+=( const Image & other )

function operator-

cpp Image operator-( const Image & other ) const

minus operator to add two images

function operator-=

cpp Image & operator-=( const Image & other )

function operator*

cpp Image operator*( const Image & other ) const

multiply operator to multiply two images

function operator*

cpp Image operator*( const PixelType x ) const

multiply operator to scale contents of an image

function operator*=

cpp Image & operator*=( const PixelType x )

function operator/

cpp Image operator/( const PixelType x ) const

divide operator to scale contents of an image

function operator/=

cpp Image & operator/=( const PixelType x )

function operator+

cpp Image operator+( const PixelType x ) const

plus operator to shift contents of an image

function operator+=

cpp Image & operator+=( const PixelType x )

function operator-

cpp Image operator-( const PixelType x ) const

minus operator to shift contents of an image

function operator-=

cpp Image & operator-=( const PixelType x )

function antialias

cpp Image & antialias( unsigned iterations =50, double maxRMSErr =0.01f, int layers =3 )

antialiases image

function recenter

cpp Image & recenter()

helper identical to setOrigin(image.center()) changing origin (in the image header) to physcial center of the image

function resample

cpp Image & resample( const TransformPtr transform, const Point3 origin, const Dims dims, const Vector3 spacing, const ImageType::DirectionType direction, InterpolationType interp =NearestNeighbor )

resamples by applying transform then sampling from given origin along direction axes at spacing physical units per pixel for dims pixels using specified interpolator

function resample

cpp Image & resample( const Vector & physicalSpacing, InterpolationType interp =Linear )

resamples image using new physical spacing, updating logical dims to keep all image data for this spacing

function resample

cpp Image & resample( double isoSpacing =1.0, InterpolationType interp =Linear )

resamples image using isotropic physical spacing

function resize

cpp Image & resize( Dims logicalDims, InterpolationType interp =Linear )

changes logical image size, computing new physical spacing based on this size (i.e., physical image size remains the same)

function pad

cpp Image & pad( int padding, PixelType value =0.0 )

pads an image by same number of voxels in all directions with constant value

function pad

cpp Image & pad( int padx, int pady, int padz, PixelType value =0.0 )

pads an image by desired number of voxels in each direction with constant value

function pad

cpp Image & pad( IndexRegion & region, PixelType value =0.0 )

pads an image to include the given region with constant value

function translate

cpp Image & translate( const Vector3 & v )

helper to simply translate image

function scale

cpp Image & scale( const Vector3 & v )

helper to simply scale image around center (not origin)

function rotate

cpp Image & rotate( const double angle, const Vector3 & axis )

helper to simply rotate around axis through center (not origin) by given angle (in radians)

function rotate

cpp Image & rotate( const double angle, Axis axis )

helper to simply rotate around axis through center (not origin) by given angle (in radians)

function createCenterOfMassTransform

cpp TransformPtr createCenterOfMassTransform()

creates a transform that translates center of mass to center of image

function createRigidRegistrationTransform

cpp TransformPtr createRigidRegistrationTransform( const Image & target_dt, float isoValue =0.0, unsigned iterations =20 )

creates transform to target image using iterative closest point (ICP) registration; images MUST be distance transforms; isovalue is used to create meshes from these distance transform images, which are then passed to ICP for the given number of iterations

function applyTransform

cpp Image & applyTransform( const TransformPtr transform, InterpolationType interp =Linear )

applies the given transformation to the image by using resampling filter

function applyTransform

cpp Image & applyTransform( const TransformPtr transform, const Point3 origin, const Dims dims, const Vector3 spacing, const ImageType::DirectionType direction, InterpolationType interp =NearestNeighbor )

applies the given transformation to the image by using resampling filter with new origin, dims, spacing and direction values

function applyTransform

cpp Image & applyTransform( const TransformPtr transform, const Image & referenceImage, InterpolationType interp =Linear )

applies the given transformation to the image by using resampling filter with reference image

function extractLabel

cpp Image & extractLabel( const PixelType label =1.0 )

extracts/isolates a specific voxel label from a given multi-label volume and outputs the corresponding binary image

function closeHoles

cpp Image & closeHoles( const PixelType foreground =0.0 )

closes holes in a given volume, default foreground value assumes a binary volume

function binarize

cpp Image & binarize( PixelType minVal =0.0, PixelType maxVal =std::numeric_limits< PixelType >::max(), PixelType innerVal =1.0, PixelType outerVal =0.0 )

threholds image into binary label based on upper and lower intensity bounds given by user

function computeDT

cpp Image & computeDT( PixelType isoValue =0.0 )

computes distance transform volume from a (preferably antialiased) binary image using the specified isovalue

function applyCurvatureFilter

cpp Image & applyCurvatureFilter( unsigned iterations =10 )

denoises an image using curvature driven flow using curvature flow image filter

function applyGradientFilter

cpp Image & applyGradientFilter()

computes gradient magnitude at each pixel using gradient magnitude filter

function applySigmoidFilter

cpp Image & applySigmoidFilter( double alpha =10.0, double beta =10.0 )

computes sigmoid function pixel-wise using sigmoid image filter

function applyTPLevelSetFilter

cpp Image & applyTPLevelSetFilter( const Image & featureImage, double scaling =20.0 )

segements structures in images using topology preserving geodesic active contour level set filter

function topologyPreservingSmooth

cpp Image & topologyPreservingSmooth( float scaling =20.0, float sigmoidAlpha =10.5, float sigmoidBeta =10.0 )

creates a feature image (by applying gradient then sigmoid filters), then passes it to the TPLevelSet filter [curvature flow filter is often applied to the image before this filter]

function applyIntensityFilter

cpp Image & applyIntensityFilter( double minVal, double maxVal )

applies intensity windowing image filter

function gaussianBlur

cpp Image & gaussianBlur( double sigma =0.0 )

applies gaussian blur with given sigma

function crop

cpp Image & crop( PhysicalRegion region, const int padding =0 )

crops the image down to the given region, with optional padding added

function fitRegion

cpp Image & fitRegion( PhysicalRegion region, const PixelType value =0.0 )

crops (or pads) the image to fit the given region

function clip

cpp Image & clip( const Plane plane, const PixelType val =0.0 )

clips an image using a cutting plane

function reflect

cpp Image & reflect( const Axis & axis )

reflect image around the plane specified by the logical center and the given normal (ex: <1,0,0> reflects across YZ-plane).

function setOrigin

cpp Image & setOrigin( Point3 origin =Point3({0, 0, 0}) )

sets the image origin in physical space to the given value

function setSpacing

cpp Image & setSpacing( Vector3 spacing )

sets the image spacing to the given value

function setCoordsys

cpp Image & setCoordsys( ImageType::DirectionType coordsys )

sets the coordinate system in which this image lives in physical space

function isolate

cpp Image & isolate()

isolate the largest object in a binary segmentation

function dims

cpp inline Dims dims() const

logical dimensions of the image

function size

cpp inline Point3 size() const

physical dimensions of the image (dims * spacing)

function get_largest_dimension_size

cpp double get_largest_dimension_size() const

largest dimension size

function spacing

cpp inline Vector spacing() const

physical spacing of the image

function get_minimum_spacing

cpp double get_minimum_spacing() const

minimum physical spacing of the image

function origin

cpp inline Point3 origin() const

physical coordinates of image origin

function center

cpp inline Point3 center() const

physical coordinates of center of this image

function coordsys

cpp inline ImageType::DirectionType coordsys() const

return coordinate system in which this image lives in physical space

function centerOfMass

cpp Point3 centerOfMass( PixelType minVal =0.0, PixelType maxVal =1.0 ) const

returns average physical coordinate of pixels in range (minval, maxval]

function min

cpp PixelType min()

minimum of image

function max

cpp PixelType max()

maximum of image

function mean

cpp PixelType mean()

mean of image

function std

cpp PixelType std()

standard deviation of image

function logicalBoundingBox

cpp IndexRegion logicalBoundingBox() const

bounding box of complete image in logical (index) space

function physicalBoundingBox

cpp PhysicalRegion physicalBoundingBox() const

bounding box of complete image in physical space

function physicalBoundingBox

cpp PhysicalRegion physicalBoundingBox( PixelType isovalue ) const

bounding box of largest region of data >= the given isoValue in physical space

function logicalToPhysical

cpp PhysicalRegion logicalToPhysical( IndexRegion region ) const

converts a bounding box in logical (index) space to this image's index coordinates

function physicalToLogical

cpp IndexRegion physicalToLogical( PhysicalRegion region ) const

converts a bounding box in physical space to this image's logical (index) coordinates

function logicalToPhysical

cpp Point3 logicalToPhysical( const Coord & c ) const

converts from pixel coordinates to physical space

function physicalToLogical

cpp Coord physicalToLogical( const Point3 & p ) const

converts from a physical coordinate to a logical coordinate

function isInside

cpp bool isInside( const Point3 & p ) const

checks if a given point is inside the image

function iterator

cpp ImageIterator iterator()

creates an image iterator and returns it

function compare

cpp bool compare( const Image & other, bool verifyall =true, double tolerance =0.0, double precision =1e-6 ) const

compares this with another image using the region of interest filter

function operator==

cpp inline bool operator==( const Image & other ) const

compares this with another image using the region of interest filter

function write

cpp Image & write( const std::string & filename, bool compressed =true )

writes image, format specified by filename extension

function toMesh

cpp Mesh toMesh( PixelType isovalue ) const

converts image to mesh

function evaluate

cpp Image::PixelType evaluate( Point p )

Evaluates the image at a given position.

function paintSphere

cpp void paintSphere( Point p, double radius, PixelType value )

Paints a sphere in the image.

function paintCircle

cpp void paintCircle( Point p, double radius, unsigned int axis, PixelType value )

Paints a circle in the image.

function isPainted

cpp inline bool isPainted() const

Returns if the image has been painted.

function fill

cpp Image & fill( PixelType value )

fill with value

function isDistanceTransform

cpp bool isDistanceTransform() const

Return if the image is a distance transform.

function getSupportedTypes

cpp static inline std::vector< std::string > getSupportedTypes()

Return supported file types.

function isSupportedType

cpp static inline bool isSupportedType( const std::string & filename )

Return if the file type is supported.

Friends

friend SharedCommandData

cpp friend struct SharedCommandData( SharedCommandData );


Updated on 2026-03-31 at 16:02:10 +0000