util
Author: Chris Dijkstra Date: 11/10/2023
Utility functions for image analysis
- lettuceSee.util.crop_region(image, centre, shape)
Crops an image area of specified width and height around a central point
- Parameters:
image (
ndarray) – matrix representing the imagecentre (
tuple[int,int]) – x and y coordinate of the centre as integersshape (
tuple[int,int]) – contains the height and width of the subregion in pixels as integers
- Return type:
ndarray- Returns:
The cropped region of the original image
- lettuceSee.util.read_fimg(filename)
Reads a fimg image from a file and outputs the corresponding np.ndarray
- Parameters:
filename (
str) – name of the file that is to be opened- Return type:
ndarray- Returns:
2D array representing the fimg image
- lettuceSee.util.scale_zero_to_one(im_channel)
Takes a 2d array and makes its values range from 0 to 1
- Parameters:
im_channel (
ndarray) – numpy array with 2 dimensions- Return type:
ndarray- Returns:
input channel scaled from 0 to 1.
- lettuceSee.util.multichannel_mask(image, mask)
Takes an image and applies a mask to every channel
- Parameters:
image (
ndarray) – 3 dimensional array representing an imagemask (
ndarray) – 2d binary mask
- Return type:
ndarray- Returns:
masked input image
- lettuceSee.util.paint_col(image, mask, color_tuple)
Makes masked area the specified color
- Parameters:
image (
ndarray) – 3d array representing an RGB imagemask (
ndarray) – 2d binary maskcolor_tuple (
tuple[int,int,int]) – contains the values in integer of the R, G and B channel that you want to paint
- Return type:
ndarray- Returns:
same as input image but with the masked area painted in the specified color
- lettuceSee.util.threshold_between(image, x_low=None, x_high=None, y_low=None, y_high=None, z_low=None, z_high=None, and_mask=True)
Thresholds an image array for being between two values for each channels
- Parameters:
image (
ndarray) – 3d matrix representing the imagex_low (
float|int) – low boundary for channel 1. Defaults to minimum of channel 1.x_high (
float|int) – high boundary for channel 1. Defaults to maximum of channel 1.y_low (
float|int) – low boundary for channel 2. Defaults to minimum of channel 2.y_high (
float|int) – high boundary for channel 2. Defaults to maximum of channel 2.z_low (
float|int) – low boundary for channel 3. Defaults to minimum of channel 3.z_high (
float|int) – high boundary for channel 3. Defaults to maximum of channel 3.and_mask (
bool) – if true returned mask is only true when all thresholds apply. If false returned mask is true if at least one of the thresholds apply.
- Return type:
ndarray- Returns:
binary mask
- lettuceSee.util.label_horizontally(mask, left_right=True)
Labels images from left to right
- Parameters:
mask (
ndarray) – Binary mask of objects that need to be labelledleft_right (
bool) – If true labels left to right, if false right to left
- Return type:
ndarray- Returns:
Mask of labelled objects
- lettuceSee.util.parse_coord_file(filename)
Parser for ImageJ xy.txt output files
- Parameters:
filename (
str) – The input file- Return type:
list[tuple[int,int]]- Returns:
List where each element is a tuple of ints in form (x, y)