foa3d.utils

foa3d.utils.ceil_to_multiple(number, multiple)

Round up number to the nearest multiple.

Parameters
  • number – number to be rounded

  • multiple – the input number will be rounded to the nearest multiple higher than this value

Returns

rounded up number

Return type

rounded

foa3d.utils.create_background_mask(img, method='yen', black_bg=False)

Compute background mask.

Parameters
  • img (numpy.ndarray (axis order=(Z,Y,X))) – 3D microscopy image

  • method (str) – image thresholding method

  • black_bg (bool) – generate foreground mask

Returns

bg_msk – boolean background mask

Return type

numpy.ndarray (axis order=(Z,Y,X), dtype=bool)

foa3d.utils.create_memory_map(shape, dtype, name='tmp', tmp=None, arr=None, mmap_mode='w+')

Create a memory-map to an array stored in a binary file on disk.

Parameters
  • shape (tuple) – shape of the stored array

  • dtype – data-type used to interpret the file contents

  • name (str) – optional temporary filename

  • tmp (str) – temporary file directory

  • arr (numpy.ndarray) – array to be mapped

  • mmap_mode (str) – file opening mode

Returns

mmap – memory-mapped array

Return type

NumPy memory map

foa3d.utils.delete_tmp_data(tmp_dir, tmp_data)

Delete temporary folder.

Parameters
  • tmp_dir (str) – path to temporary folder to be removed

  • tmp_data (tuple) – temporary data dictionaries

Return type

None

foa3d.utils.detect_ch_axis(img)

Detect image channel axis.

Parameters

img (numpy.ndarray) – 3D microscopy image

Returns

ch_ax – channel axis (either 1 or 3)

Return type

int

foa3d.utils.divide_nonzero(nd_array1, nd_array2, new_val=1e-10)

Divide two arrays handling zero denominator values.

Parameters
Returns

divided – divided array

Return type

numpy.ndarray

foa3d.utils.elapsed_time(start_time)

Compute elapsed time from input start reference.

Parameters

start_time (float) – start time reference

Returns

  • tot (float) – total time [s]

  • hrs (int) – hours

  • mins (int) – minutes

  • secs (int) – seconds

foa3d.utils.fwhm_to_sigma(fwhm)

Compute the standard deviation of a Gaussian distribution from its FWHM value.

Parameters

fwhm (float) – full width at half maximum

Returns

sigma – standard deviation

Return type

float

foa3d.utils.get_available_cores()

Return the number of available logical cores.

Returns

num_cpu – number of available cores

Return type

int

foa3d.utils.get_config_label(cli_args)

Generate the output filename prefix including pipeline configuration information.

Parameters

cli_args (see ArgumentParser.parse_args) – updated namespace of command line arguments

Returns

cfg_lbl – Frangi filter configuration label

Return type

str

foa3d.utils.get_item_bytes(data)

Retrieve data item size in bytes.

Parameters

data (numpy.ndarray or HDF5 dataset) – input data

Returns

bts – item size in bytes

Return type

int

foa3d.utils.get_item_size(dtype)

Get the item size in bytes of a data type.

Parameters

dtype (str) – data type identifier

Returns

item_sz – item size in bytes

Return type

int

foa3d.utils.hsv_orient_cmap(vec_img)

Compute HSV colormap of vector orientations from 3D vector field.

Parameters

vec_img (numpy.ndarray (axis order=(Z,Y,X,C), dtype=float)) – orientation vectors

Returns

rgb_map – orientation color map

Return type

numpy.ndarray (axis order=(Z,Y,X,C), dtype=uint8)

foa3d.utils.normalize_angle(angle, lower=0.0, upper=360.0, dtype=None)

Normalize angle to [lower, upper) range.

Parameters
  • angle (numpy.ndarray (dtype=float)) – angular values to be normalized (in degrees)

  • lower (float) – lower limit (default: 0.0)

  • upper (float) – upper limit (default: 360.0)

  • dtype – output data type

Returns

angle – angular values (in degrees) normalized within [lower, upper)

Return type

numpy.ndarray (dtype=float)

Raises

ValueError – if lower >= upper

foa3d.utils.normalize_image(img, min_val=None, max_val=None, max_out_val=255.0, dtype=<class 'numpy.uint8'>)

Normalize image data.

Parameters
  • img (numpy.ndarray) – input image

  • min_val (float) – minimum input value

  • max_val (float) – maximum input value

  • max_out_val (float) – maximum output value

  • dtype – output data type

Returns

norm_img – normalized image

Return type

numpy.ndarray

foa3d.utils.rgb_orient_cmap(vec_img, minimum=0, stretch=1, q=8)

Compute RGB colormap of orientation vector components from 3D vector field.

Parameters
  • vec_img (numpy.ndarray (axis order=(Z,Y,X,C), dtype=float)) – n-dimensional array of orientation vectors

  • minimum (int) – intensity that should be mapped to black (a scalar or array for R, G, B)

  • stretch (int) – linear stretch of the image

  • q (int) – asinh softening parameter

Returns

rgb_map – orientation color map

Return type

numpy.ndarray (axis order=(Z,Y,X,C), dtype=uint8)

foa3d.utils.transform_axes(nd_array, flipped=None, swapped=None, expand=None)

Manipulate axes and dimensions of the input array. The transformation sequence is: axes flip >>> axes swap >>> dimensions expansion.

Parameters
  • nd_array (numpy.ndarray) – input data array

  • swapped (tuple (dtype=int)) – axes to be swapped

  • flipped (tuple (dtype=int)) – axes to be flipped

  • expand (int) – insert new axis at this position

Returns

nd_array – transformed data array

Return type

numpy.ndarray