imaging#

Image processing and analysis

circle

Automatic search of the spinning disk's circle

cells

Segmentation of cells in thresholded image

analysis

Curve fit of cell density versus shear stress

read(source: Path) ndarray[source]#

Reads an image from the given source path into an array.

write(target: Path, image: ndarray | Image, overwrite=False)[source]#

Saves the image as the given target file.

An appropriate compression method is selected depending on the image format of the file, which is inferred from the file’s suffix, e.g. .tif or .jpg. Lossless compression is used for formats that support it, such as .tif and .png. The level of compression we select strikes a balance between small file size and fast output speed.

compress(source: Path, target: Path, grayscale=False)[source]#

Compresses the source image file and saves it as target.

The file format of the target is inferred from the file suffix, for example .tif for the TIFF image format. Optionally, the image can be converted to grayscale, which means averaging over the color channels.

sort_into_grid(folder: Path, suffix='.png') ndarray[Path][source]#

Finds input images in folder and sorts them into the correct grid.

The control software of the spinning-disk microscope outputs partial images acquired while scanning the full area. We need to find those images among other files possibly residing in the same folder and arrange them correctly. The position of an individual image in the scan grid is encoded in its file name.

Note that, in the past, there have been bugs in the acquisition software that resulted in incorrectly names files.

Raises appropriate exceptions if, for whatever reason, the folder does not contain the expected set of input images.

Returns a 2d array of files.

stitch(files: ndarray[Path], target: Path)[source]#

Stitches scan-grid images into the full image.

The files must be passed in as a 2d array, the shape of which determines the grid. That is typically the result returned by sort_into_grid(). The stitched image will be saved as target.

tile(source: Path, target: Path, tile_size: int = 512, overlap: int = 0)[source]#

Creates a tiled zoom-level pyramid from a large image.

The source file is typically a high-resolution image that is intended to be displayed interactively, at various zoom levels. The target must be a .dzi file. The input image will be converted to the DeepZoom format, essentially a collection of small tiles (which may or may not overlap somewhat). Internally, the individual tiles are just .png images that can be quickly loaded from disk for given zoom level and position in the larger image.

rolling_ball(image: ndarray, radius: int = 50) ndarray[source]#

Removes the background from the image using the rolling-ball method.

Returns the image foreground obtained by subtracting the background from the input image.

thresholding_bernsen(image: ndarray, radius: int = 15, contrast: int = 15) ndarray[source]#

Returns the local segmentation thresholds using the Bernsen method.

The parameters window radius and contrast threshold correspond to the ImageJ definitions, though the Python implementation actually uses a square window with a side length corresponding to the diameter.

invert(image: ndarray) ndarray[source]#

Returns the given image with all color values inverted.

white_on_black(image: ndarray) ndarray[source]#

Inverts the image if not white-on-black, or returns the input.

By “white-on-black” we mean that the background is mostly dark with light features on it.

black_on_white(image: ndarray) ndarray[source]#

Inverts the image if not black-on-white, or returns the input.

By “black-on-white” we mean that the background is mostly light with dark features on it.