Collection of helper functions for manipulating images#

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


A minimal class for use when returning multiple values from a function


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_cylinder(im[, r, axis])

Returns a cylindrical section of the image of specified radius.

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

Combine given regions into a single boolean mask

tools.extract_subsection(im, shape)

Extracts the middle section of a image

tools.find_outer_region(im[, r])

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

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

Create an array 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.


Fetches a version of tqdm function that depends on the environment.

tools.in_hull(points, hull)

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

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.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.sanitize_filename(filename, ext[, ...])

Returns a sanitized string in the form of name.extension


Fetches the docstring for a function and returns it in markdown format.

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