Image Processing
Collection of image processing algorithms and techniques that could be used and widely applied to many of our datasets.
Functions:
|
Bins a 2d array by a square kernel length (bin_size*2 + 1). |
|
Fills and labels ROI outlines using unique ints for each region. |
|
Converts a n-labeled image to an up to 4 color image. |
|
Converts an n-label image into a |
|
Given an image, this function will apply k-means clustering and return the mask that includes the n brightest clusters :param im: intensity image. |
|
Normalizes an image to 0 and 1 by subtrating min value and dividing by new max value. |
|
This function removes horizontal or vertical edges in the image. |
|
Function was created to clean up masks that may have stray pixels or regions. |
|
# RGB to Grayscale ## Code logic: - Essentially, read in mask only image (not composite) and figure out unique tuples that represent singular RGB values. |
|
Converts a 3ch rgb mask image into a 1ch uint16 mask image. |
|
Sums the pixel intensity by a given kernel, reducing output image dimensions. |
- cell_analysis_tools.image_processing.bin_2d(im, bin_size, stride=1, pad_value=0, debug=False)[source]
Bins a 2d array by a square kernel length (bin_size*2 + 1).
- Parameters:
im (ndarray) – 3d ndarray containing FLIM data (x,y,t).
bin_size (int) – number of pixels to look before and after center pixel. kernel = bin_size + 1 + bin_size
stride (int, optional) – Number of pixels to move when raster scanning the image. The default is 1.
pad_value (int, optional) – value to pad the image with. The default is 0.
debug (bool, optional) – Show debugging output. The default is False.
- Returns:
im_binned – binned 3d array of decays
- Return type:
ndarray
- cell_analysis_tools.image_processing.fill_and_label_rois(curr_nuclei)[source]
Fills and labels ROI outlines using unique ints for each region.
- Parameters:
curr_nucelei (param) – Current image to process
- Returns:
output – ROIs filled and labeled with unique int representations
- Return type:
ndarray
- cell_analysis_tools.image_processing.four_color_theorem(mask: ndarray) ndarray[source]
Converts a n-labeled image to an up to 4 color image.
- Parameters:
mask (np.ndarray) – labeled mask with unique rois.
- Returns:
four_color_mask (np.ndarray) – returns a labeled image that uses up to 4 colors.
solution_nodes (dict) – dictionary of {value : color} for each unique roi value
- cell_analysis_tools.image_processing.four_color_to_unique(mask: ndarray, debug: bool = False) ndarray[source]
Converts an n-label image into a
- Parameters:
mask (np.ndarray) – labeled mask.
debug (bool, optional) – show output re-labeled mask. The default is False.
- Returns:
output_mask – Mask relabeled to have unique roi values for each connected component
- Return type:
np.ndarray
- cell_analysis_tools.image_processing.kmeans_threshold(im, k, n_brightest_clusters, show_image=False)[source]
Given an image, this function will apply k-means clustering and return the mask that includes the n brightest clusters :param im: intensity image. :type im: array-like :param k: number of clusters for k means algorithm :type k: int, :param n_brightest_clusters: number of brightest clusers to keep. Must be < k. :type n_brightest_clusters: int, :param show_image: When debugging,this will display the original image next to the k means thresholded image. The default is False. :type show_image: bool, optional
- Returns:
mask – binary mask
- Return type:
int
- cell_analysis_tools.image_processing.normalize(im)[source]
Normalizes an image to 0 and 1 by subtrating min value and dividing by new max value.
- Parameters:
im (array-like) – intensity image.
- Returns:
array normalized to 0 and 1.
- Return type:
array-like
- cell_analysis_tools.image_processing.remove_horizontal_vertical_edges(im, disk_size=20, debug=False)[source]
This function removes horizontal or vertical edges in the image. Designed for removing grid patterns in PDMS scaffolds during time lapse imaging.
- Parameters:
im (ndarray) – intensit image with grid pattern
disk_size (int) – size of filter used to filter low frequency components of 2d image
debug (bool, optional) – output intermediate images , by default False
- Returns:
filtered image with grid pattern removed
- Return type:
np.ndarray
- cell_analysis_tools.image_processing.remove_small_areas_fill_regions(mask: array, region_min_size: int = 100, footprint_area_closing: int = 2, debug=False)[source]
Function was created to clean up masks that may have stray pixels or regions.
- Parameters:
mask (np.array) – original mask.
region_min_size (int, optional) – minimum size of connected component to be removed. The default is 100.
footprint_area_closing (int, optional) – When merging images radius of disk to use. The default is 2.
debug (TYPE, optional) – Enable/Disable display of intermediate images for debugging function. The default is False.
- Return type:
np.array of revised mask
- cell_analysis_tools.image_processing.rgb2gray(mask_rgb, debug=False)[source]
# RGB to Grayscale ## Code logic: - Essentially, read in mask only image (not composite) and figure out unique tuples that represent singular RGB values. - A typical RBG value to produce a color value can be broken up into (R, G, B) insity values. - Tuples are preferable over numpy arrays as they can be easily condensed into unique elemnts using a set and then converted back into a list (they are hashable). - After uniques are found, build a dictionary with values from 1 to number of unique RGB values in the images. These will become the grayscale int values that we then plot. The resulting array should automatically upscale from 8-bit integer if needed (>256 unique elements). - This only works for mask images, NOT overlays!
- Parameters:
mask_rgb (np.ndarray) – rgb image.
debug (bool, optional) – Enable debugging output. The default is False.
- Returns:
result – Grayscale image.
- Return type:
np.ndarray
- cell_analysis_tools.image_processing.rgb2labels(im, debug=False)[source]
Converts a 3ch rgb mask image into a 1ch uint16 mask image.
- Parameters:
im (ndarray) – input 3ch RGB image of rois.
debug (bool, optional) – Enable display of intermediates. The default is False.
- Returns:
mask – labels mask from RGB image.
- Return type:
ndarray
- cell_analysis_tools.image_processing.sum_pool_3d(im, bin_size, stride=1, pad_value=0, debug=False)[source]
Sums the pixel intensity by a given kernel, reducing output image dimensions.
- Parameters:
im (ndarray) – 3d array containig FLIM data (x,y,t).
bin_size (int) – number of pixels to select before and after, bin of 3 is a 7x7 kernel
stride (int, optional) – number of pixels to advance when doing raster calculations. The default is 1.
pad_value (int, optional) – Value to pad the edges with if kernel needs it. The default is 0.
debug (bool , optional) – Show debugging output. The default is False.
- Returns:
im_sum_pool – 3d ndarray that holds a summed version of the image resized image.
- Return type:
ndarray