Module iaf.process

Image processing functionalities.

Functions

def sample(image: numpy.ndarray, size: tuple, seed: Optional[int] = None) ‑> numpy.ndarray

Returns a random subset of given shape from the passed 2D image.

Parameters

image : numpy array
Original intensity image.
size : tuple
Size (y, x) of the subset of the image to be randomly extracted.
seed : Optional[int]
Random generator seed to reproduce the sampling. Omit to create a new random sample every time.

Returns

subset : np.ndarray
Subset of the image of given size.
def subtract_background(img: numpy.ndarray, algorithm: str = 'rolling_ball', radius: int = 25, offset: int = 0, down_size_factor: int = 1, return_background: bool = False) ‑> Union[numpy.ndarray, tuple[numpy.ndarray, numpy.ndarray]]

Runs a background subtraction on the given image using the specified algorithm.

See


Parameters

img : np.ndarray
Image to be processed
algorithm : str
Algorithm to be used for the background subtraction. One of {"rolling ball", "morphological_opening", "gaussian"} (Optional, default = "rolling_ball")
radius : int

Radius to be used for the morphological opening structural element, the rolling ball, or the Gaussian kernel. (Optional, default = 25)

The value of radius will be automatically scaled if a down_size_factor != 1.0 is set.

Please also notice: for better results with the Gaussian kernel approach, the sigma of the kernel is set to radius / sqrt(2).

offset : int
Offset to be used to increase or decrease the intensities of the estimated background. (Optional, default = 0)
down_size_factor : int
Tune the accuracy of background estimation by optionally down-sampling the image. The final result will be full sized, no matter the value of down_size_factor. The default down_size_factor value of 1 means that the background estimation is performed on the original image; a value of 2 means rescaling the image by a factor 1/2 in both x and y directions (that is, a 4x smaller image); a value of 4 rescales in x and y directions by a factor of 1/4 (that is, a 16x smaller image); and so on.
return_background : bool
Whether the estimated background should be returned along with the background-subtracted image. (Optional, default = False)

Returns

corr | (corr, background): Union[np.ndarray, tuple[np.ndarray, np.ndarray]]
Single np.ndarray, if return_background = False, or a tuple with two np.ndarrays: background-subtracted image and estimated background.
def tile(image: numpy.ndarray, tile_size: tuple, overlap_pixels: Optional[int] = None, overlap_percent: Optional[None] = None, drop_partial: bool = True) ‑> Tuple[list, int, int]

Breaks a 2D images into a series of tiles of given size and optional overlap.

Parameters

image : numpy array
Original intensity image.
tile_size : tuple
Size (y, x) of each of the tiles.
overlap_pixels : Optional[int]
Size in pixels of the tile overlapping area.
overlap_percent : Optional[float]

Size in percent of the tile overlapping area.

If both overlap and overlap_percent are defined, the value of overlap will be used.

drop_partial : bool
Whether tiles at the borders that are smaller than tile_size should be dropped.

Returns

tile_list : List
List of tiles in row-first order, each of which is an np.ndarray.
n_rows : int
Number of rows
n_cols : int
Number of columns