iaf.process¶
Image processing functionalities.
- iaf.process.sample(image: ndarray, size: tuple, seed: int | None = None) ndarray[source]¶
Returns a random subset of given shape from the passed 2D image.
- Parameters:
- Returns:
subset – Subset of the image of given size.
- Return type:
np.ndarray
- iaf.process.subtract_background(img: ndarray, algorithm: str = 'rolling_ball', radius: int = 25, offset: int = 0, down_size_factor: int = 1, return_background: bool = False) ndarray | tuple[ndarray, ndarray][source]¶
Runs a background subtraction on the given image using the specified algorithm.
See¶
https://scikit-image.org/docs/dev/api/skimage.restoration.html#rolling-ball
https://scikit-image.org/docs/dev/api/skimage.morphology.html#opening
https://scikit-image.org/docs/dev/api/skimage.filters.html#gaussian
- param img:
Image to be processed
- type img:
np.ndarray
- param algorithm:
Algorithm to be used for the background subtraction. One of {“rolling ball”, “morphological_opening”, “gaussian”} (Optional, default = “rolling_ball”)
- type algorithm:
str
- param radius:
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).
- type radius:
int
- param offset:
Offset to be used to increase or decrease the intensities of the estimated background. (Optional, default = 0)
- type offset:
int
- param down_size_factor:
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.
- type down_size_factor:
int
- param return_background:
Whether the estimated background should be returned along with the background-subtracted image. (Optional, default = False)
- type return_background:
bool
- returns:
corr | (corr, background) – Single np.ndarray, if return_background = False, or a tuple with two np.ndarrays: background-subtracted image and estimated background.
- rtype:
Union[np.ndarray, tuple[np.ndarray, np.ndarray]]
- iaf.process.tile(image: ndarray, tile_size: tuple, overlap_pixels: int | None = None, overlap_percent: float | None = None, drop_partial: bool = True) Tuple[list, int, int][source]¶
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