Example a/segmentation_3d: 3D Segmentation of blood vessels

This example demonstrates how to use 3D segmentation to extract 3D regions from image based computed fields. In this case we use it to extract a particular set of blood vessels from MR images.

Cmgui implements segmentation via computed fields, using the Insight Tookit (ITK) library code. These routines can be used for both 2D and 3D segmentation. Example a/segmentation introduces some of the basic concepts and shows how to use computed fields to perform 2D segmentation. This example demonstrates how the same concepts can be applied in 3D. Isosurfaces are used to view the results.

The connected threshold image filter is used to segment out a particular set of vessels from the image. A seed point is given and the surrounding voxels are added to the region if they are within a particular intensity range. The region grows using a flood fill iterator, adding connected voxels within the specified range until no more can be added. This region growing algorithm works well with the branching structure of the vessels.

The fast marching image filter can also be applied in 3D but uses a very different method to segment out regions. Seed points planted within the vessel structure do not handle branching as well as the region growing methods, hence why only the connected threshold image filter has been used.

The input images for this example produce very nice isosurfaces, shown below in blue. Notice how several different vessel structures have been picked out. We wish to use segmentation to pick out just the main vessel structure. By growing a region from a seed point placed in the main vessel structure we can segment out just these vessels, shown below in gold. The gold vessels have a lower resolution, as they are based on a binary image, where voxels are either in or out of the region. This results in boxy image artefacts, which become even more noticable if the general discretisation is increased. The segmented region is still useful though and could even by applied as an image mask to the original data.
Original vessels Segmented vessels Blue and gold vessels
Original vessels Segmented vessels Original and segmented vessels overlayed

Created by Peter Bier, July 2007.

Screenshot of example a/segmentation_3d


The comfile run by this example is as follows:

# This example demonstrates how to segment out some blood vessels
# from MR images.  The vessels are segmented in 3d using a region
# growing algorithm (the connected threshold image filter).
# A seed point within the vessel of interest is defined and the
# region grows from there, with voxels being added to the region
# if the image intensity falls within the prescribed range.

# Note that fast marching segmentation can also be used in 3d
# but the vessel segmentation problem is ideally suited to a
# region growing method.

# read in MR images and create a volume texture
gfx create texture vessel image png:$example/images/sequence.XX.png number_pattern XX number_series 00 51 1 width 1 height 1 depth 1 distortion 0 0 0 colour 0 0 0 alpha 0 decal linear_filter resize_nearest_filter clamp_wrap compress;
# use linear interpolation
gfx modify texture vessel linear

# create a material containing the texture based on the input images
gfx create material vessel texture vessel

# Set the directory with the exnode and exelem files 
# for the block that holds the texture
$block_dir="$example/block";

# read in a block to view the texture in
gfx read nodes $block_dir/vessel_block.exnode
gfx read elements $block_dir/vessel_block.exelem

# define the texture coordinates which vary from 0 to 1 along the axes
# this defines how the texture is oriented with respect to the texture block
gfx read nodes $block_dir/tex_coords.exnode
gfx read elements $block_dir/tex_coords.exelem

# Define the components of the coordinate field as individual scalar
# fields for defining slice planes
# these slice planes can be used to view the input or output images
# at different slices through the texture
gfx define field x component coordinates.x;
gfx define field y component coordinates.y;
gfx define field z component coordinates.z;

# create a gray_spectrum spectrum
gfx cre spectrum gray_spectrum clear;
gfx modify spectrum gray_spectrum linear range 0 1 extend_above extend_below red colour_range 0 1 ambient diffuse component 1
gfx modify spectrum gray_spectrum linear range 0 1 extend_above extend_below green colour_range 0 1 ambient diffuse component 1
gfx modify spectrum gray_spectrum linear range 0 1 extend_above extend_below blue colour_range 0 1 ambient diffuse component 1

# create a texture coordinate field which can be evaluated using only 
# coordinates.  This is required if we wish to sample the texture on an 
# arbitrary plane and then print the image out to a file. 
# For display purposes we only require the tex_coords field but I have 
# used the lookup_tex_coords to make this example more extensible.
# For more information on this field see example a/create_slices
gfx define field lookup_tex_coords compose texture_coordinates coordinates group texture_block element_dimension 3 find_element_xi coordinates calculate_values_field tex_coords;

# create a sample texture field which we can use to evaluate the texture
# values for each plane 
gfx define field input_image sample_texture field vessel coordinates lookup_tex_coords;

# Smooth the input image field  using anisotropic diffusion with 5 iterations
gfx define field smoothed curvature_anisotropic_diffusion_filter field input_image num_iterations 5 time_step 0.0625 conductance 2;

# Segment the image using the connected threshold filter
# The seed point is defined in terms of its position within the texture
# described by normalised coordinates (0.5, 0.6111, 0.3889)
gfx define field segmented_field connected_threshold_filter field smoothed num_seed_points 1 dimension 3 seed_points 0.5 0.6111 0.3889 lower_threshold 0.2 upper_Threshold 1.0

# create a texture based on the segmented image field
# note that we specify the the texture dimensions to be the same as the 
# texture created by reading in the input images
# This way, no information is lost due to downsampling.
gfx create texture segmented width 1 height 1 depth 1 clamp_wrap decal;
gfx modify texture segmented linear;
gfx modify texture segmented specify_width 109 specify_height 101 specify_depth 52 specify_format i evaluate element_group texture_block element_dimension 3 field segmented_field spectrum gray_spectrum texture_coordinates lookup_tex_coords;

# create a material to view the segmented texture
gfx create material segmented texture segmented alpha 0.8;

# To visualise the result of the segmentation is is useful to create
# an isosurface based on the segmented field.  We cannot do this directly
# using the segmented_field as it will result in the error:
# ERROR: GT_object_normalise_GT_voltex_normals.  Graphics object does not contain a voltex
# We get around this problem by creating a new field based on sampling the 
# segmented texture
gfx define field segmented_image sample_texture field segmented coordinates lookup_tex_coords;

# Create a 3d window with white background and a nice viewpoint
gfx create window 1
gfx modify window 1 background colour 1 1 1;
gfx modify window 1 view parallel eye_point 218.411 103.418 298.452 interest_point 42.5824 29.968 39.9395 up_vector -0.128289 0.973495 -0.189338 view_angle 19.774 near_clipping_plane 3.21153 far_clipping_plane 1147.69 relative_viewport ndc_placement -1 1 2 2 viewport_coordinates 0 0 1 1;
gfx modify window 1 set transform_tool current_pane 1 std_view_angle 40 normal_lines no_antialias depth_of_field 0.0 slow_transparency blend_normal;


# Increase the element discretisation to give higher res isosurfaces
gfx modify g_element texture_block general clear circle_discretization 6 default_coordinate coordinates element_discretization "64*64*64" native_discretization none;

# draw 3 isoplanes for reference to check the isosurfaces are located correctly
gfx modify g_element texture_block iso_surfaces iso_scalar x iso_value 0 use_elements select_on material segmented texture_coordinates lookup_tex_coords selected_material default_selected render_shaded;
gfx modify g_element texture_block iso_surfaces iso_scalar y iso_value 0 use_elements select_on material segmented texture_coordinates lookup_tex_coords selected_material default_selected render_shaded;
gfx modify g_element texture_block iso_surfaces iso_scalar z iso_value 0 use_elements select_on material segmented texture_coordinates lookup_tex_coords selected_material default_selected render_shaded;

# display an isosurfaces based on the original smoothed image
gfx modify g_element texture_block iso_surfaces iso_scalar input_image iso_value 0.2 use_elements select_on material blue texture_coordinates lookup_tex_coords selected_material default_selected render_shaded;

# display an isosurfaces based on the segmented image
gfx modify g_element texture_block iso_surfaces iso_scalar segmented_image iso_value 0.2 use_elements select_on material gold texture_coordinates lookup_tex_coords selected_material default_selected render_shaded;




Files used by this example are:

Name                 Modified     Size

segmentation_3d.com 17-Mar-2014 6.7k COPYRIGHT 17-Mar-2014 504 block/ 18-Mar-2014 - images/ 18-Mar-2014 -

Download the entire example:

Name                               Modified     Size

examples_a_segmentation_3d.tar.gz 09-Mar-2016 1.5M

Testing status by version:

StatusTestedReal time (s)
i686-linux
cmgui-wxFailureSun Mar 6 00:23:23 20167
last breakTue Feb 24 03:25:00 20157
cmgui-wx-debugFailureSun Mar 6 00:29:19 201616
last breakTue Feb 24 03:29:00 201512
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:28:49 201613
last breakTue Feb 24 03:28:00 201513
cmgui-wx-debug-valgrindFailureSun Mar 6 02:54:42 2016702
last breakSun Mar 6 02:42:00 2016702
x86_64-linux
cmgui-wxFailureSun Mar 6 00:01:33 20161
last breakSun Mar 6 00:01:00 20161
cmgui-wx-debugFailureSun Mar 6 00:01:33 20161
last breakSun Mar 6 00:01:00 20161
cmgui-wx-debug-memorycheckFailureSun Mar 6 00:01:33 20161
last breakSun Mar 6 00:01:00 20161
cmgui-wx-debug-valgrindFailureSun Mar 6 00:03:20 20169
last breakSun Mar 6 00:03:00 20169
cmgui-wx-gcc-cad-debug-valgrindSuccessThu Jan 7 00:02:10 20166

Testing status by file:


Html last generated: Wed Mar 9 16:02:38 2016

Input last modified: Wed Mar 9 15:49:37 2016


CMISS Help / Examples / a / segmentation_3d