# Image Processing¶

Image Processing modules apply an operation to an image and output a new image.

## Align¶

Align aligns images relative to each other, for example, to correct shifts in the optical path of a microscope in each channel of a multi-channel set of images.

For two or more input images, this module determines the optimal alignment among them. Aligning images is useful to obtain proper measurements of the intensities in one channel based on objects identified in another channel, for example. Alignment is often needed when the microscope is not perfectly calibrated. It can also be useful to align images in a time-lapse series of images. The module stores the amount of shift between images as a measurement, which can be useful for quality control purposes.

Note that the second image (and others following) is always aligned with respect to the first image. That is, the X/Y offsets indicate how much the second image needs to be shifted by to match the first.

This module does not perform warping or rotation, it simply shifts images in X and Y. For more complex registration tasks, you might preprocess images using a plugin for that purpose in FIJI/ImageJ.

Supports 2D? Supports 3D? Respects masks?
YES NO YES

### Measurements made by this module¶

• Xshift, Yshift: The pixel shift in X and Y of the aligned image with respect to the original image.

### References¶

• Lewis JP. (1995) “Fast normalized cross-correlation.” Vision Interface, 1-7.

## ColorToGray¶

ColortoGray converts an image with multiple color channels to one or more grayscale images.

This module converts color and channel-stacked images to grayscale. All channels can be merged into one grayscale image (Combine), or each channel can be extracted into a separate grayscale image (Split). If you use Combine, the relative weights you provide allow adjusting the contribution of the colors relative to each other. Note that all Identify modules require grayscale images.

Supports 2D? Supports 3D? Respects masks?
YES NO NO

## CorrectIlluminationApply¶

CorrectIlluminationApply applies an illumination function, usually created by CorrectIlluminationCalculate, to an image in order to correct for uneven illumination/lighting/shading or to reduce uneven background in images.

This module applies a previously created illumination correction function, either loaded by the Images module, a Load module, or created by CorrectIlluminationCalculate. This module corrects each image in the pipeline using the function specified.

Supports 2D? Supports 3D? Respects masks?
YES NO NO

## CorrectIlluminationCalculate¶

CorrectIlluminationCalculate calculates an illumination function that is used to correct uneven illumination/lighting/shading or to reduce uneven background in images.

This module calculates an illumination function that can either be saved to the hard drive for later use or immediately applied to images later in the pipeline. This function will correct for the uneven illumination in images. Use the CorrectIlluminationApply module to apply the function to the image to be corrected. Use SaveImages to export an illumination function to the hard drive using the “npy” file format.

Warning: illumination correction is a challenge to do properly; please see the examples and tutorials pages on the CellProfiler website for further advice.

Supports 2D? Supports 3D? Respects masks?
YES NO YES

### References¶

• J Lindblad and E Bengtsson (2001) “A comparison of methods for estimation of intensity nonuniformities in 2D and 3D microscope images of fluorescence stained cells.”, Proceedings of the 12th Scandinavian Conference on Image Analysis (SCIA), pp. 264-271

## Crop¶

Crop crops or masks an image.

This module crops images into a rectangle, ellipse, an arbitrary shape provided by you, the shape of object(s) identified by an Identify module, or a shape created using a previous Crop module in the pipeline.

Keep in mind that cropping changes the size of your images, which may have unexpected consequences. For example, identifying objects in a cropped image and then trying to measure their intensity in the original image will not work because the two images are not the same size.

Supports 2D? Supports 3D? Respects masks?
YES NO YES

### Measurements made by this module¶

• AreaRetainedAfterCropping: The area of the image left after cropping.
• OriginalImageArea: The area of the original input image.

Special note on saving images: You can save the cropping shape that you have defined in this module (e.g., an ellipse you drew) so that you can use the Image option in future analyses. To do this, save either the mask or cropping in SaveImages. See the SaveImages module help for more information on saving cropping shapes.

## EnhanceEdges¶

EnhanceEdges enhances or identifies edges in an image, which can improve object identification or other downstream image processing.

This module enhances the edges (gradients - places where pixel intensities change dramatically) in a grayscale image. All methods other than Canny produce a grayscale image that can be used in an Identify module or thresholded using the Threshold module to produce a binary (black/white) mask of edges. The Canny algorithm produces a binary (black/white) mask image consisting of the edge pixels.

Supports 2D? Supports 3D? Respects masks?
YES NO YES

## EnhanceOrSuppressFeatures¶

EnhanceOrSuppressFeatures enhances or suppresses certain image features (such as speckles, ring shapes, and neurites), which can improve subsequent identification of objects.

This module enhances or suppresses the intensity of certain pixels relative to the rest of the image, by applying image processing filters to the image. It produces a grayscale image in which objects can be identified using an Identify module.

Supports 2D? Supports 3D? Respects masks?
YES YES YES

## FlipAndRotate¶

FlipAndRotate flips (mirror image) and/or rotates an image

Supports 2D? Supports 3D? Respects masks?
YES NO NO

### Measurements made by this module¶

• Rotation: Angle of rotation for the input image.

## GrayToColor¶

GrayToColor takes grayscale images and produces a color image from them.

This module takes grayscale images as input and assigns them to colors in a red, green, blue (RGB) image or a cyan, magenta, yellow, black (CMYK) image. Each color’s brightness can be adjusted independently by using relative weights.

Supports 2D? Supports 3D? Respects masks?
YES NO NO

## ImageMath¶

ImageMath performs simple mathematical operations on image intensities.

This module can perform addition, subtraction, multiplication, division, or averaging of two or more image intensities, as well as inversion, log transform, or scaling by a constant for individual image intensities.

Keep in mind that after the requested operations are carried out, the final image may have a substantially different range of pixel intensities than the original. CellProfiler assumes that the image is scaled from 0 – 1 for object identification and display purposes, so additional rescaling may be needed. Please see the RescaleIntensity module for more scaling options.

Supports 2D? Supports 3D? Respects masks?
YES YES YES

## InvertForPrinting¶

InvertForPrinting inverts fluorescent images into brightfield-looking images for printing.

This module turns a single or multi-channel immunofluorescent-stained image into an image that resembles a brightfield image stained with similarly colored stains, which generally prints better. You can operate on up to three grayscale images (representing the red, green, and blue channels of a color image) or on an image that is already a color image. The module can produce either three grayscale images or one color image as output. If you want to invert the grayscale intensities of an image, use ImageMath.

Supports 2D? Supports 3D? Respects masks?
YES NO NO

## MakeProjection¶

MakeProjection combines two or more two-dimensional images of the same field of view into a single two-dimensional image.

This module combines a set of images by performing a mathematical operation of your choice at each pixel position; please refer to the settings help for more information on the available operations. The process of averaging or summing a Z-stack (3D image stack) is known as making a projection.

This module will create a projection of all images specified in the Input modules; most commonly you will want to use grouping to select subsets of images to be combined into each projection. To achieve per-folder projections (i.e., creating a single projection for each set of images in a folder, for all input folders), make the following setting selections:

1. In the Images module, drag-and-drop the parent folder containing the sub-folders.
2. In the Metadata module, enable metadata extraction and extract metadata from the folder name by using a regular expression to capture the subfolder name, e.g., .*[\\/](?P<Subfolder>.*)\$
3. In the NamesAndTypes module, specify the appropriate names for any desired channels.
4. In the Groups module, enable image grouping, and select the metadata tag representing the sub-folder name as the metadata category.

Keep in mind that the projection image is not immediately available in subsequent modules because the output of this module is not complete until all image processing cycles have completed. Therefore, the projection should be created with a separate pipeline from your analysis pipeline.

MakeProjection currently only works on single image Z-slices across image cycles; it will not work on images that have been loaded as 3D volumes in NamesAndTypes so be sure Process as 3D is set to No in that module. For more information on loading image stacks and movies, see Help > Creating a Project > Loading Image Stacks and Movies.

Supports 2D? Supports 3D? Respects masks?
YES NO YES

MaskImage hides certain portions of an image (based on previously identified objects or a binary image) so they are ignored by subsequent mask-respecting modules in the pipeline.

Supports 2D? Supports 3D? Respects masks?
YES YES YES

## Morph¶

Morph performs low-level morphological operations on binary or grayscale images.

This module performs a series of morphological operations on a binary image or grayscale image, resulting in an image of the same type. Many require some image processing knowledge to understand how best to use these morphological filters in order to achieve the desired result. Note that the algorithms minimize the interference of masked pixels; for instance, the dilate operation will only consider unmasked pixels in the neighborhood of a pixel when determining the maximum within that neighborhood.

Supports 2D? Supports 3D? Respects masks?
YES NO YES

The following operations are available:

Operation Description Input image type allowed
Branchpoints

Removes all pixels except those that are the branchpoints of a skeleton. This operation should be applied to an image after skeletonizing. It leaves only those pixels that are at the intersection of branches.

 1 0 0 0 0 → ? 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 0 1 0 0 0 1 ? 0 0 0 ?
Binary
Bridge

Sets a pixel to 1 if it has two non-zero neighbors that are on opposite sides of this pixel:

 1 0 0 → 1 0 0 0 0 0 0 1 0 0 0 1 0 0 1
Binary
Clean

Removes isolated pixels:

 0 0 0 → 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
Binary
Convex hull Finds the convex hull of a binary image. The convex hull is the smallest convex polygon that fits around all foreground pixels of the image: it is the shape that a rubber band would take if stretched around the foreground pixels. The convex hull can be used to regularize the boundary of a large, single object in an image, for instance, the edge of a well. Binary
Diag

Fills in pixels whose neighbors are diagnonally connected to 4-connect pixels that are 8-connected:

 0 1 → 1 1 1 0 1 1
 0 1 → 1 1 1 1 1 1
Binary
Distance Computes the distance transform of a binary image. The distance of each foreground pixel is computed to the nearest background pixel. The resulting image is then scaled so that the largest distance is 1. Binary
Endpoints

Removes all pixels except the ones that are at the end of a skeleton:

 0 0 0 0 0 → 0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 1 0 ? 0 0 ?
Binary
Fill

Sets a pixel to 1 if all of its neighbors are 1:

 1 1 1 → 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1
Binary
Hbreak

Removes pixels that form vertical bridges between horizontal lines:

 1 1 1 → 1 1 1 0 1 0 0 0 0 1 1 1 1 1 1
Binary
Life Applies the interaction rules from the Game of Life, an example of a cellular automaton. Binary
Majority

Each pixel takes on the value of the majority that surround it (keep pixel value to break ties):

 1 1 1 → 1 1 1 1 0 1 1 1 1 0 0 0 0 0 0
Binary
OpenLines Performs an erosion followed by a dilation using rotating linear structural elements. The effect is to return parts of the image that have a linear intensity distribution and suppress dots of the same size. Binary, grayscale
Remove

Removes pixels that are otherwise surrounded by others (4 connected). The effect is to leave the perimeter of a solid object:

 0 1 0 → 0 1 0 1 1 1 1 0 1 0 1 0 0 1 0
Binary
Shrink Performs a thinning operation that erodes unless that operation would change the image’s Euler number. This means that blobs are reduced to single points and blobs with holes are reduced to rings if shrunken indefinitely. Binary
SkelPE Performs a skeletonizing operation using the metric, PE * D to control the erosion order. PE is the Poisson Equation (see Gorelick, “Shape representation and classification using the Poisson Equation”, IEEE Transactions on Pattern Analysis and Machine Intelligence V28, # 12, 2006) evaluated within the foreground with the boundary condition that the background is zero. D is the distance transform (distance of a pixel to the nearest edge). The resulting skeleton has fewer spurs but some bit of erosion at the endpoints in the binary image. Binary
Spur

Removes spur pixels, i.e., pixels that have exactly one 8-connected neighbor. This operation essentially removes the endpoints of lines.

 0 0 0 0 → 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 1 1 1 1 1 1 1 1
Binary
Thicken Dilates the exteriors of objects where that dilation does not 8-connect the object with another. The image is labeled and the labeled objects are filled. Unlabeled points adjacent to uniquely labeled points change from background to foreground. Binary
Thin Thin lines preserving the Euler number using the thinning algorithm # 1 described in Guo, “Parallel Thinning with Two Subiteration Algorithms”, Communications of the ACM, Vol 32 #3, page 359. The result generally preserves the lines in an image while eroding their thickness. Binary
Vbreak

Removes pixels that form horizontal bridges between vertical lines:

 1 0 1 → 1 0 1 1 1 1 1 0 1 1 0 1 1 0 1
Binary

The following Morph operations have been extracted to separate modules in CellProfiler 3.0. Use the table below to update your pipeline to use the corresponding module and, where appropriate, setting and value.

Morph operation Module Setting Value
bothat TopHatTransform* Operation Black top-hat transform
close Closing
dilate Dilation
erode Erosion
fill small holes RemoveHoles
invert ImageMath Operation Invert
open Opening
skel MorphologicalSkeleton
tophat TopHatTransform* Operation White top-hat transform

* Available as a CellProfiler plugin.

Create an RGB image with color-coded labels overlaid on a grayscale image.

## OverlayOutlines¶

OverlayOutlines places outlines of objects over a desired image.

This module places outlines of objects on any desired image (grayscale, color, or blank). The resulting image can be saved using the SaveImages module.

Supports 2D? Supports 3D? Respects masks?
YES YES NO

## RescaleIntensity¶

RescaleIntensity changes the intensity range of an image to your desired specifications.

This module lets you rescale the intensity of the input images by any of several methods. You should use caution when interpreting intensity and texture measurements derived from images that have been rescaled because certain options for this module do not preserve the relative intensities from image to image.

Supports 2D? Supports 3D? Respects masks?
YES YES YES

## Resize¶

Resize resizes images (changes their resolution).

This module is compatible with 2D and 3D/volumetric images.

Images are resized (made smaller or larger) based on your input. You can resize an image by applying a resizing factor or by specifying the desired dimensions, in pixels. You can also select which interpolation method to use.

Supports 2D? Supports 3D? Respects masks?
YES YES YES

## Smooth¶

Smooth smooths (i.e., blurs) images.

This module allows you to smooth (blur) images, which can be helpful to remove small artifacts. Note that smoothing can be a time-consuming process.

Supports 2D? Supports 3D? Respects masks?
YES NO YES

## Threshold¶

Threshold produces a binary, or black and white, image based on a threshold that can be pre-selected or calculated automatically using one of many methods. After the threshold value has been determined, the Threshold module will set pixel intensities below the value to zero (black) and above the value to one (white).

Supports 2D? Supports 3D? Respects masks?
YES YES YES

## Tile¶

Tile tiles images together to form large montage images.

This module allows more than one image to be placed next to each other in a grid layout you specify. It might be helpful, for example, to place images adjacent to each other when multiple fields of view have been imaged for the same sample. Images can be tiled either across cycles (multiple fields of view, for example) or within a cycle (multiple channels of the same field of view, for example).

Supports 2D? Supports 3D? Respects masks?
YES NO NO

Tiling images to create a montage with this module generates an image that is roughly the size of all the images’ sizes added together. For large numbers of images, this may cause memory errors, which might be avoided by the following suggestions:

• Resize the images to a fraction of their original size, using the Resize module prior to this module in the pipeline.
• Rescale the images to 8-bit using the RescaleIntensity module, which diminishes image quality by decreasing the number of graylevels in the image (that is, bit depth) but also decreases the size of the image.

Please also note that this module does not perform image stitching (i.e., intelligent adjustment of the alignment between adjacent images). For image stitching, you may find the following list of software packages useful:

Other packages are referenced here.

Supports 2D? Supports 3D?
YES NO

## UnmixColors¶

UnmixColors creates separate images per dye stain for histologically stained images.

This module creates separate grayscale images from a color image stained with light-absorbing dyes. Dyes are assumed to absorb an amount of light in the red, green and blue channels that increases proportionally in each channel with increasing amounts of stain; the hue does not shift with increasing staining. The module separates two or more stains from a background, producing grayscale images. There are several pre-set dye combinations as well as a custom mode that allows you to calibrate using two images stained with a single dye each. Some commonly known stains must be specified by the individual dye components. For example:

• Azan-Mallory: Anilline Blue + Azocarmine + Orange-G
• Giemsa: Methylene Blue or Eosin
• Masson Trichrome: Methyl blue + Ponceau-Fuchsin

If there are non-stained cells/components that you also want to separate by color, choose the stain that most closely resembles the color you want, or enter a custom value. Please note that if you are looking to simply split a color image into red, green and blue components, use the ColorToGray module rather than UnmixColors.

Supports 2D? Supports 3D? Respects masks?
YES NO NO

### Technical notes¶

This code is adapted from the ImageJ plugin, Colour_Deconvolution.java written by A.C. Ruifrok, whose paper forms the basis for this code.

### References¶

• Ruifrok AC, Johnston DA. (2001) “Quantification of histochemical staining by color deconvolution.” Analytical & Quantitative Cytology & Histology, 23: 291-299.