aicsimageprocessing package¶
Subpackages¶
Submodules¶
aicsimageprocessing.alignMajor module¶
-
aicsimageprocessing.alignMajor.
align_major
(images, angles, reshape=True)[source]¶ Rotates images based on the angles passed in
- Parameters
images – Either a single image or a list of them. Must be at least 3d numpy arrays, ordered as TCZYX
angles – The tuple returned by get_align_angles. Tells the function how to rotate the images
reshape – boolean. If True, the output will be resized to ensure that no data from img is lost. If False, the output will be the same size as the input, with potential to lose data that lies outside of the input shape after rotation. Default is True
- Returns
If a single image was passed in, it will will return a rotated copy of that image.
If a list was passed in, it will return a list of rotated images in the same order
that they were passed in
-
aicsimageprocessing.alignMajor.
angle_between
(v1, v2)[source]¶ Finds angle between two 2d vectors
- Parameters
v1 – first vector as a numpy array
v2 – second vector as a numpy array
- Returns
- Return type
angle between v1 and v2 in degrees
-
aicsimageprocessing.alignMajor.
get_align_angles
(img, axes='zyx')[source]¶ Returns the angles needed to rotate an image to align it with the specified axes
- Parameters
img – A CZYX image as a 4d numpy array. The image that will be measured to get the alignment angles. The image will not be altered by this function
axes – string, that must be an arrangement of ‘xyz’ The major axis will be aligned with the first one, the minor with the last one. ‘zyx’ by default
- Returns
A list of tuple pairs, containing the axis indices and angles to rotate along the
paired axis. Meant to be passed into align_major
aicsimageprocessing.backgroundCrop module¶
-
aicsimageprocessing.backgroundCrop.
crop
(img, bg_val=0, axis=(-3, -2, -1), padding=0, get_slices=False)[source]¶ Crops an image to remove the background color bg_val along arbitrary axis
- Parameters
img – numpy array to crop
bg_val – value to crop out. Default is 0
axis – tuple or list of axis indices to crop along. Can be either positive or negative values. Negative values will be from the end of the array as opposed to the start. By default, it crops along the last three axes
padding – integer. Specifies how much of the background value to leave in the output. Will be applied on all axis that are being cropped
get_slices – boolean. If True, will return the slice indices that were taken out of the original image along with the cropped image. Default is False
- Returns
either the cropped numpy array, or a tuple containing the cropped array and a tuple
of slices taken out of the original data
-
aicsimageprocessing.backgroundCrop.
get_edges
(img, bg_val=0, axis=(-3, -2, -1))[source]¶ Returns the indices of the edges of the structure in the image
- Parameters
img – CZYX image as a 4d numpy array
bg_val – value to use for background
axis – axis to get the edges for. Output length will be equal to axis length. Default is the last three axis
- Returns
tuple of the same length as axis parameter. Contains lists the contain the left and
right edges for each axis specified.
aicsimageprocessing.backgroundSub module¶
-
aicsimageprocessing.backgroundSub.
background_sub
(img, mask=None, method='mean')[source]¶ Performs background subtraction on image using chosen method with optional mask
- Parameters
img – numpy array, image to perform subtraction on
mask – numpy mask, subtraction is calculated and performed on the area specified by the mask i.e. the mask should specify the background of the image
method – string, selects the subtraction method to use. Default is ‘mean’. Options are: mean, median, common.
- Returns
- Return type
numpy array, copy of input image with background subtracted out
aicsimageprocessing.crop_img module¶
aicsimageprocessing.flip module¶
-
aicsimageprocessing.flip.
flip
(images, flips)[source]¶ Flips images based on the calculations from get_flips()
- Parameters
images – Either a single n-dimensional image as a numpy array or a list of them. The images to flip
flips – The output from get_flips(), tells the function which axes to flip the images along. All images will be flipped the same way
- Returns
Either a single flipped copy of the input image, or a list of them in the same
order that they were passed in, depending on whether the ‘images’ parameter was a
single picture or a list
-
aicsimageprocessing.flip.
get_flips
(img, sec, axes=(-3, -2, -1))[source]¶ Calculates which axes to flip in order to have the center of mass of the image be located in the desired sector. Meant to be passed to flip()
- Parameters
img – image as an n-dimensional numpy array to perform the calculations on. The image will not be modified by this function
sec – String containing ‘+’ and ‘-’, same length as ‘axes’. Tells the function which side of each axis the center of mass should be on, ‘+’ meaning the upper half and ‘-’ meaning the lower half
>>> get_flips(img, "++-", axes=(-3, -2, -1)) This, for example, would mean to have the center of mass be on the upper half of the z axis (index -3 for a CZYX image), the upper half of the y axis, and the lower half of the x axis
axes – List or tuple of integers, specifies which axes to calculate the needed flips for. Default is the last three axes, meant to be the 3 spatial dimensions for a ZYX, CZYX, or TCZYX image. Must be the same length as ‘sec’ parameter
- Returns
A list of integers, representing the indices of the axes to flip the image along
Should be passed to flip()
aicsimageprocessing.imgCenter module¶
-
aicsimageprocessing.imgCenter.
center
(images, moves, fill=0)[source]¶ Aligns images based on the center of mass.
- Parameters
images – Either an n-dimensional image as a numpy array or a list of them. All images must be the same shape
moves – List of integers, returned from a previous call to get_center_moves. Tells the function how to center the images
fill – Value to use when adding padding. Default is 0
- Returns
If a single image was passed in, will return a centered copy of the input. If a
list was passed in, it will return a list of centered images in the same order that
they were passed in
-
aicsimageprocessing.imgCenter.
crop_all
(images, axis=(-3, -2, -1))[source]¶ Crop all images by the same amount. The amount to crop will be calculated so that an equal amount is removed on both sides of each axis to keep the center of mass in the center
- Parameters
images – List of images to crop. The images can be any shape or dimensionality but must all have the same shape
axis – List of axis to crop along. Default is the last three axis (meant to correspond to ZYX)
- Returns
- Return type
List of cropped images, in the same order as they were passed in
-
aicsimageprocessing.imgCenter.
get_center_moves
(image, axes=(-3, -2, -1))[source]¶ Calculates moves needed to center an image based on its center of mass. Meant to be passed in to center_image
- Parameters
image – N-dimensional image to be used for calculation. The image will not be altered
axis – Iterable containing the axis to center the image on. Order does not affect the output. Default is the last three axis (meant to be ZYX). Can be positive or negative to index from the front or back
- Returns
- Return type
List of integers, meant to be passed to center_image
aicsimageprocessing.imgToCoords module¶
-
aicsimageprocessing.imgToCoords.
img_to_coords
(im_cell, im_nuc, major_angle_object='cell')[source]¶ Return unit vector of v
- Parameters
im_cell – zyx binary image of a cell shape
im_nuc – zyx binary image of a nuclear shape
major_angle_object – string that specifies from which object the major angle is determined can be ‘cell’ or ‘nuc’
- Returns
im_ratio – channels corresponding to ratio image (1 at cell boundary, 0 on nuclear boundary, -1 inside nucleus)
im_th – spherical coordinate system theta (radians)
im_phi – spherical coordinate system phi (radians)
im_r – radial distance from center of nucleus
major_angle – angle of cell or nuclear shape (radians)
aicsimageprocessing.imgToProjection module¶
-
aicsimageprocessing.imgToProjection.
imgtoprojection
(im1, proj_all=False, proj_method='max', colors=<function <lambda>>, global_adjust=False, local_adjust=False)[source]¶ Outputs projections of a 4d CZYX numpy array into a CYX numpy array, allowing for color masks for each input channel as well as adjustment options
- Parameters
im1 – Either a 4d numpy array or a list of 3D or 2D numpy arrays. The input that will be projected
proj_all – boolean. True outputs XY, YZ, and XZ projections in a grid, False just outputs XY. False by default
proj_method – string. Method by which to do projections. ‘Max’ by default
colors – Can be either a string which corresponds to a cmap function in matplotlib, a function that takes in the channel index and returns a list of numbers, or a list of lists containing the color multipliers.
global_adjust – boolean. If true, scales each color channel to set its max to be 255 after combining all channels. False by default
local_adjust – boolean. If true, performs contrast adjustment on each channel individually. False by default
- Returns
- Return type
a CYX numpy array containing the requested projections
aicsimageprocessing.imshow module¶
aicsimageprocessing.isosurfaceGenerator module¶
-
class
aicsimageprocessing.isosurfaceGenerator.
Mesh
(verts, faces, normals, values)[source]¶ Bases:
object
A cell mesh class contains the necessary information to generate a display a 3D isosurface.
Examples
>>> image = AICSImage("some/bio/image.ome.tif") ... mesh0 = generate_mesh(image.data, isovalue=0, channel=0) ... # will generate a different mesh due to the different isovalue ... mesh1 = generate_mesh(image.data, isovalue=1, channel=0) ... mesh0.save_as_obj("some/bio/image/mesh.obj") ... # mesh.obj can be imported into 3D viewers and represents a 3D rendering of ... # image.ome.tif
-
aicsimageprocessing.isosurfaceGenerator.
generate_mesh
(image, isovalue=0, channel=0)[source]¶ Creates and returns a Mesh object
- Parameters
image – an AICSImage object
isovalue – The value that is used to pick the isosurface returned by the marching cubes algorithm For more info: https://www.youtube.com/watch?v=5fNbCFjqWao @ 40:00 mins
channel – The channel in the image that is used to extract the isosurface
- Returns
- Return type
A Mesh object
aicsimageprocessing.normalization module¶
-
aicsimageprocessing.normalization.
normalize_channel
(img, mask=None, method='img_bg_sub', lower=None, upper=None)[source]¶
aicsimageprocessing.resize module¶
-
aicsimageprocessing.resize.
resize
(orig, factor, method='nearest')[source]¶ Scales a numpy array to a new size using a specified scaling method
- Parameters
orig – n-dimen numpy array to resize
factor – integer, double, or n-tuple to scale orig by
method – string, interpolation method to use when resizing. Options are “nearest”, “bilinear”, and “cubic”. Default is “nearest”
- Returns
- Return type
n-dimen numpy array
-
aicsimageprocessing.resize.
resize_to
(orig, out_size, method='nearest')[source]¶ Scales a numpy array to fit within a specified output size
- Parameters
orig – n-dimen numpy array to resize
out_size – n-tuple, will be the shape of the output array.
method – string, interpolation method to use when resizing. Options are “nearest”, “bilinear”, and “cubic”. Default is “nearest”
- Returns
- Return type
n-dimen numpy array
aicsimageprocessing.rigidAlignment module¶
-
aicsimageprocessing.rigidAlignment.
cell_rigid_deregistration
(img, flipdim_orig, angle_orig, com_orig, imsize_orig, ch_crop=1, ch_com=0)[source]¶
aicsimageprocessing.sdfGenerator module¶
aicsimageprocessing.textureAtlas module¶
-
class
aicsimageprocessing.textureAtlas.
TextureAtlas
(aics_image, pack_order, dims, t=0)[source]¶ Bases:
object
-
class
aicsimageprocessing.textureAtlas.
TextureAtlasGroup
(aics_image, t=0, name='texture_atlas', pack_order=None, max_edge=2048)[source]¶ Bases:
object
-
save
(output_dir, name=None, user_data=None)[source]¶ Saves a TextureAtlasGroup into one json file and 1 to many png files. Files are named with formats name+’_atlas.json’ and name+’_atlas_N.png’
- Parameters
output_dir – directory in which to write the files
name – if not supplied, then use the name given when creating the TextureAtlasGroup
user_data – optional dictionary of additional data to add to json file; to be used by client application
-
-
aicsimageprocessing.textureAtlas.
generate_texture_atlas
(im, name='texture_atlas', max_edge=2048, pack_order=None, t=0)[source]¶ Creates a TextureAtlasGroup object
- Parameters
im – aicsImage object
name – will be stored in metadata and used at save time if no name is supplied at that time
max_edge – this designates the largest side in the texture atlas
pack_order – a 2d list that contains what channel in the image should be saved to the RGBA values in the final png. for example, a 7 channel image might be saved like [[0, 1, 2, 3], [4, 5], [6]] where the first texture atlas will code channel 0 as r, channel 1 as g, and so on.
t – time index, zero by default.
- Returns
- Return type
TextureAtlasGroup object
aicsimageprocessing.thumbnailGenerator module¶
-
class
aicsimageprocessing.thumbnailGenerator.
ThumbnailGenerator
(colors: Sequence[Tuple[float, float, float]] = ((0.0, 1.0, 1.0), (1.0, 0.0, 1.0), (1.0, 1.0, 0.0)), size: int = 128, channel_indices: Sequence[int] = None, channel_thresholds: Sequence[float] = None, channel_multipliers: Sequence[int] = None, mask_channel_index: int = 5, letterbox: bool = True, projection: str = 'max', projection_sections: int = 3, return_rgb: bool = True)[source]¶ Bases:
object
This class is used to generate thumbnails for 4D CZYX images.
Examples
>>> generator = ThumbnailGenerator() ... for image in image_array: ... thumbnail = generator.make_thumbnail(image)
- Parameters
colors – The color palette that will be used to color each channel. The default palette colors are magenta=membrane, nucleus=cyan, structure=yellow. Keep color-blind accessibility in mind.
size – This constrains the image to have the X or Y dims max out at this value, but keep the original aspect ratio of the image.
channel_indices – An array of channel indices to represent the three main channels of the cell
mask_channel_index – The index for the segmentation channel in image that will be used to mask the thumbnail
projection – The method that will be used to generate each channel’s projection. This is done for each pixel, through the z-axis Options: [“max”, “slice”, “sections”] - max will look through each z-slice, and determine the max value for each pixel - slice will take the pixel values from the middle slice of the z-stack - sections will split the zstack into projection_sections number of sections, and take a max projection for each.
projection_sections – The number of sections that will be used to determine projections, if projection=”sections”
return_rgb – Return an array that has been clipped and cast as uint8 to make it RGB compatible. Setting this to False will return the float array that is (generally) bounded between 0 and 1.
-
make_thumbnail
(image: numpy.ndarray, apply_cell_mask: bool = False) → numpy.ndarray[source]¶ This method is the primary interface with the ThumbnailGenerator. It can be used many times with different images in order to save the configuration that was specified at the beginning of the generator.
- Parameters
image – ZCYX image that is the source of the thumbnail
apply_cell_mask – boolean value that designates whether the image is a fullfield or segmented cell False -> fullfield, True -> segmented cell
- Returns
- Return type
a CYX image, scaled down to the size designated in the constructor
-
aicsimageprocessing.thumbnailGenerator.
create_projection
(image: numpy.ndarray, axis: int, method: str = 'max', slice_index: int = 0, sections: int = 3)[source]¶ This function creates a 2D projection out of an n-dimensional image.
- Parameters
image – ZCYX array
axis – the axis that the projection should be performed along
method – the method that will be used to create the projection Options: [“max”, “mean”, “sum”, “slice”, “sections”] - max will look through each axis-slice, and determine the max value for each pixel - mean will look through each axis-slice, and determine the mean value for each pixel - sum will look through each axis-slice, and sum all pixels together - slice will take the pixel values from the middle slice of the stack - sections will split the stack into sections number of sections, and take a max projection for each.
slice_index – index to use for the ‘slice’ projection method
sections – number of sections to select and max-intensity project for the ‘sections’ projection method
- Returns
- Return type
The 2D image projection
-
aicsimageprocessing.thumbnailGenerator.
make_one_thumbnail
(infile: str, outfile: str, channels: List[int], colors: List[Tuple[float, float, float]], size: int, projection: str = 'max', axis: int = 2, apply_mask: bool = False, mask_channel: int = 0, label: str = '', t: int = 0)[source]¶
aicsimageprocessing.transformation module¶
Module contents¶
Top-level package for aicsimageprocessing.