Utils Module

Utility Functions

the Utils module offers a variety of utility functions designed to facilitate image processing tasks in the ExR-Tools package.

exr.utils.utils.calculate_volume_and_surface_area(labeled_image, label=1, spacing=[1, 1, 1])[source]

Calculates the volume and surface area of a specified object within a 3D labeled image.

Parameters:
  • labeled_image (numpy.ndarray) – A 3D array where different objects are distinguished by unique integer labels.

  • label (int) – The specific label of the object for which the volume and surface area are to be calculated.

Returns:

A tuple containing two elements - the volume and the surface area of the specified object.

Return type:

tuple

exr.utils.utils.chmod(path)[source]

Sets permissions so that users and the owner can read, write and execute files at the given path.

Parameters:

path (pathlib.Path) – Path in which privileges should be granted.

Return type:

None

exr.utils.utils.subtract_background_rolling_ball(volume, radius=50, num_threads=40)[source]

Performs background subtraction on a volume image using the rolling ball method.

Parameters:
  • volume (np.ndarray) – The input volume image.

  • radius (int, optional) – The radius of the rolling ball used for background subtraction. Default is 50.

  • num_threads (int, optional) – The number of threads to use for the rolling ball operation. Default is 40.

Returns:

The volume image after background subtraction.

Return type:

np.ndarray

exr.utils.utils.subtract_background_top_hat(volume, radius=50, use_gpu=True)[source]

Performs top-hat background subtraction on a volume image.

Parameters:
  • volume (np.ndarray) – The input volume image.

  • radius (int, optional) – The radius of the disk structuring element used for top-hat transformation. Default is 50.

  • use_gpu (bool, optional) – If True, uses GPU for computation (requires cupy). Default is False.

Returns:

The volume image after background subtraction.

Return type:

np.ndarray

Package Logger

exr.utils.log.configure_logger(name, log_file_name='ExR-Tools_logs.log')[source]

Configures and returns a logger with both stream and file handlers.

This function sets up a logger to send log messages to the console and to a log file. The console will display messages with a level of INFO and higher, while the file will contain messages with a level of DEBUG and higher.

Parameters:
  • name (str) – Name of the logger to configure. Typically, this is the name of the module calling the logger.

  • log_file_name (str) – Name of the log file where logs will be saved. Defaults to ‘ExR-Tools_logs.log’.

Returns:

Configured logger object.

Return type:

logging.Logger

Raises:

OSError – If there is an issue with opening or writing to the log file.