How To Create an Ellipsoid in an Image

Summary
This application demonstrates how to create a geometrical shape within an itkImage using Spatial Functions. Specifically, this application will create an itkImage consisting of an ellipsoid using the itkEllipsoidInteriorExteriorSpatialFunction found in the Insight functions module.

Description
First, an itkImage (dimension of 3, size of 50x50x50, spacing of (1,1,1), and origin (0,0,0)) is created and completely filled with pixels of intensity value 128. Then, itkFloodFilledSpatialFunctionConditionalIterator is used to iterate through the image and set pixels to 256 if itkSymmetricEllipsoidInteriorExteriorSpatialFunction returns 1, meaning that it is within the interior of the ellipsoid. The ellipsoid is defined by its axes lengths (from edge-to-edge of the ellipsoid) as well as the orientation of its unique axis. This application is restricted to 3D to allow for the visualization of the resulting image, which is done via a VTK image file. The volume of the ellipsoid is measured by counting the number of interior pixels of the ellipsoid. This measure can be used to verify the resulting ellipsoid by comparing it against the calculated volume (percent difference) of the ellipsoid given by:

Ellipsoid Volume Equation, where a, b, and c are the lengths of the ellipsoid axes.

The ellipsoid is also validated by checking that the center of the ellipsoid has been labeled as an interior pixel (a function value of 1) by evaluating the spatial function at the origin of the ellipsoid.

NOTE: Orientation vectors must be orthogonal to each other and normalized!


To Use this Application
Build and run itkEllipsoidInteriorExteriorSpatialFunctionExample.cxx from the workspace generated from CMake. The resulting VTK image file is stored as:

"InsightApplications\EllipsoidInteriorExteriorSpatialFunction\ellipsoid.vtk"

Default settings should result in an image of an ellipsoid with its axis of length 40 oriented along the (0,1,0) direction, axis of length 30 oriented along the (1,0,0) direction, and axis of length 20 oriented along the (0,0,1) direction. The origin of the ellipsoid is sampled and evaluated by the spatial function and returns function value, which is 1 since the origin of the ellipsoid is within the ellipsoid.

Results Of The Application (With Defaults):
calculated ellipsoid volume 12566.4 pixels
measured ellipsoid volume 12428 pixels pixels
volume error 1.10907%
function value 1

Results of application
Fig. 1: Resulting Image Containing an Ellipsoid From This Application

Insight Classes Used
These are the Insight classes used for this application with a brief description. They appear in order of first use:

  • itkImage.h: generates a physical image.
  • itkImageRegionIterator.h: iterates through the pixels in the physical image and sets them to 128.
  • itkEllipsoidInteriorExteriorSpatialFunction.h: evaluates pixels in the image and determines whether they are within the ellipsoid or not.
  • tkFloodFilledSpatialFunctionConditionalIterator.h: iterates the image and sets them to 256 if they are within the ellipsoid.
Possible Uses of Ellipsoids
The ellipsoid images created by EllipsoidInteriorExteriorSpatialFunction are useful for testing imaging algorithms, pixel-sampling routines, establishing geometric domains of influence, etc.

Non-ITK Requirements
A VTK image viewer is needed to visualize the output file ellipsoid.vtk.


Go to next application.