Helper Functions

This module contains a variety of functions for manipulating images in ways do NOT return a modified version of the original image.


Rotates an image to agree with the coordinates used in OpenPNM.


Given a tuple containing bounding box coordinates, return a tuple of slice objects.

tools.extend_slice(slices, shape[, pad])

Adjust slice indices to include additional voxles around the slice.

tools.extract_subsection(im, shape)

Extracts the middle section of a image

tools.extract_regions(regions, labels[, trim])

Combine given regions into a single boolean mask

tools.extract_cylinder(im[, r, axis])

Returns a cylindrical section of the image of specified radius.

tools.extract_subsection(im, shape)

Extracts the middle section of a image

tools.find_outer_region(im[, r])

Finds regions of the image that are outside of the solid matrix.

tools.get_border(shape[, thickness, mode, …])

Creates an array of specified size with corners, edges or faces labelled as True.

tools.get_planes(im[, squeeze])

Extracts three planar images from the volumetric image, one for each principle axis.

tools.insert_cylinder(im, xyz0, xyz1, r)

Inserts a cylinder of given radius onto an image

tools.insert_sphere(im, c, r[, v, overwrite])

Inserts a sphere of a specified radius into a given image

tools.in_hull(points, hull)

Test if a list of coordinates are inside a given convex hull

tools.isolate_object(region, i[, s])

Given an image containing labels, removes all labels except the specified one.

tools.make_contiguous(im[, mode])

Take an image with arbitrary greyscale values and adjust them to ensure all values fall in a contiguous range starting at 0.

tools.marching_map(path, start)

Use the fast marching method to find distance of each voxel from a starting point

tools.mesh_region(region[, strel])

Creates a tri-mesh of the provided region using the marching cubes algorithm

tools.norm_to_uniform(im[, scale])

Take an image with normally distributed greyscale values and convert it to a uniform (i.e.

tools.overlay(im1, im2, c)

Overlays im2 onto im1, given voxel coords of center of im2 in im1.

tools.ps_ball(r[, smooth])

Creates spherical ball structuring element for morphological operations

tools.ps_disk(r[, smooth])

Creates circular disk structuring element for morphological operations

tools.ps_rect(w, ndim)

Creates rectilinear structuring element with the given size and dimensionality

tools.ps_round(r, ndim[, smooth])

Creates round structuring element with the given radius and dimensionality

tools.randomize_colors(im[, keep_vals])

Takes a greyscale image and randomly shuffles the greyscale values, so that all voxels labeled X will be labelled Y, and all voxels labeled Y will be labeled Z, where X, Y, Z and so on are randomly selected from the values in the input image.

tools.recombine(ims, slices, overlap)

Recombines image chunks back into full image of original shape

tools.subdivide(im[, divs, overlap])

Returns slices into an image describing the specified number of sub-arrays.

tools.unpad(im, pad_width)

Remove padding from a previously padded image given original pad widths