preprocessing module

preprocessing.__assign_to_mask__(cfg, COG_temp: ndarray, trabmask: ndarray, mask_cog: ndarray, dimZ_min_tolerance: float, tolerance: float)[source]

Assigns each point in COG_temp to either trabecular or cortical mask based on whether it is inside trabecular mask or not. Returns the cog_points and indices for trabecular and cortical masks separately.

Parameters:
  • COG_temp (np.ndarray) – Array of center of gravity points

  • trabmask (np.ndarray) – Trabecular mask

  • mask_cog (np.ndarray) – Centers of gravity in x, y, z direction

  • dimZ_min_tolerance (float) – dimZ - tolerance

  • tolerance (float) – Tolerance for z-coordinates

Returns:

cog_points_trab, indices_trab, cog_points_cort, indices_cort

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray, np.ndarray]

preprocessing.__mask_cogs__(COG_temp: ndarray, spacing: ndarray)[source]

Using numpy broadcasting to calculate the mask_cog Speed increased by 25x (POS, 2023-07-06)

Parameters:
  • COG_temp (np.ndarray) – Array of center of gravity points

  • Spacing (np.ndarray) – SCANCO image spacing

Returns:

Centers of gravity in x, y, z direction

Return type:

Tuple[np.ndarray, np.ndarray, np.ndarray]

preprocessing.calculate_bvtv(scaling, slope, intercept, BMD_array, CORTMASK_array, TRABMASK_array, cfg, IMTYPE: str)[source]

Calculates BVTV and mask images.

Parameters:
  • scaling (float) – Scaling factor for the image.

  • slope (float) – Slope used in the image.

  • intercept (float) – Intercept used in the image.

  • BMD_array (numpy.ndarray) – Array containing BMD values.

  • CORTMASK_array (numpy.ndarray) – Array containing cortical mask values.

  • TRABMASK_array (numpy.ndarray) – Array containing trabecular mask values.

  • cfg (dict) – Configuration object containing image processing settings.

  • IMTYPE (str) – String defining the type of image (“BMD” or “NATIVE”).

Returns:

A tuple containing the following elements:
  • BVTVscaled (numpy.ndarray): Scaled BVTV values.

  • BMDscaled (numpy.ndarray): Scaled BMD values.

  • BVTVraw (numpy.ndarray): Raw BVTV values.

Return type:

tuple

This function performs the following operations: 1. Calculates BVTVraw based on the image type (BMD or NATIVE). 2. Applies BVTV scaling if specified in the configuration. 3. Creates a mask by combining cortical and trabecular masks. 4. Applies the mask to BVTVscaled, BMDscaled, and BVTVraw.

preprocessing.compute_msl_spline(bone: dict, cfg: dict) dict[source]

Computes the mean surface length (MSL) for a given bone image and configuration.

Parameters:
  • bone (dict) – A dictionary containing bone data, including spacing, segmentation arrays, and masks.

  • cfg (dict) – A configuration dictionary containing homogenization parameters.

Returns:

The updated bone dictionary with computed MSL spline values.

Return type:

dict

preprocessing.fmt_sanity_check(in_file)[source]
preprocessing.set_summary_variables(bone)[source]

Computes variables for summary file

preprocessing.smooth_kernel(MSL: ndarray, ROI_kernel_size: int) ndarray[source]

Applies a smoothing kernel to a 3D numpy array.

Parameters:
  • MSL (np.ndarray) – A 3D numpy array representing the input data.

  • ROI_kernel_size (int) – The size of the smoothing kernel.

Returns:

A 3D numpy array representing the smoothed data.

Return type:

np.ndarray

Examples

>>> data = np.random.rand(10, 10, 10)
>>> smoothed_data = smooth_kernel(data, 3)