unravel.core.img_tools module#

This module contains functions processing 3D images:
  • resample: Resample a 3D ndarray.

  • reorient_for_raw_to_nii_conv: Reorient an ndarray for registration or warping to atlas space

  • pixel_classification: Segment tif series with Ilastik.

  • pad: Pad an ndarray by a specified percentage.

  • reorient_ndarray: Reorient a 3D ndarray based on the 3 letter orientation code (using the letters RLAPSI).

  • reorient_ndarray2: Reorient a 3D ndarray based on the 3 letter orientation code (using the letters RLAPSI).

  • rolling_ball_subtraction_opencv_parallel: Subtract background from a 3D ndarray using OpenCV.

  • cluster_IDs: Prints cluster IDs for clusters > minextent voxels.

  • find_bounding_box: Finds the bounding box of all clusters or a specific cluster in a cluster index ndarray and optionally writes to file.

unravel.core.img_tools.resample(ndarray, xy_res, z_res, target_res, zoom_order=1)[source]#

Resample a 3D ndarray

Parameters:
  • ndarray – 3D ndarray to resample

  • xy_res – x/y voxel size in microns (for the original image)

  • z_res – z voxel size in microns

  • res – resolution in microns for the resampled image

  • zoom_order – SciPy zoom order for resampling the native image. Default: 1 (bilinear interpolation)

unravel.core.img_tools.resample_nii(nii, target_res, zoom_order)[source]#

Resample the input NIfTI image to the target resolution.

Parameters:#

niinibabel.nifti1.Nifti1Image

NIfTI image object to resample.

target_resfloat

Target resolution in micrometers for resampling.

zoom_orderint

SciPy zoom order. Default: 0 (nearest-neighbor). Use 1 for linear interpolation.

Returns:#

resampled_niinibabel.nifti1.Nifti1Image

Resampled NIfTI image object.

unravel.core.img_tools.reorient_for_raw_to_nii_conv(ndarray)[source]#

Reorient resampled ndarray for registration or warping to atlas space (legacy mode mimics MIRACL’s tif to .nii.gz conversion)

unravel.core.img_tools.reverse_reorient_for_raw_to_nii_conv(ndarray)[source]#

After warping to native space, reorients image to match tissue

unravel.core.img_tools.pixel_classification(tif_dir, ilastik_project, output_dir, ilastik_executable=None)[source]#

Segment tif series with Ilastik using pixel classification.

unravel.core.img_tools.pad(ndarray, pad_width=0.15)[source]#

Pads ndarray by 15% of voxels on all sides

unravel.core.img_tools.reorient_ndarray(data, orientation_string)[source]#

Reorient a 3D ndarray based on the 3 letter orientation code (using the letters RLAPSI). Assumes initial orientation is RAS (NIFTI convention).

unravel.core.img_tools.reorient_ndarray2(ndarray, orientation_string)[source]#

Reorient a 3D ndarray based on the 3 letter orientation code (using the letters RLAPSI). Assumes initial orientation is RAS (NIFTI convention).

unravel.core.img_tools.process_slice(slice, struct_element)[source]#

Subtract background from <slice> using OpenCV.

unravel.core.img_tools.rolling_ball_subtraction_opencv_parallel(ndarray, radius, threads=8)[source]#

Subtract background from <ndarray> using OpenCV. Uses multiple threads to process slices in parallel. Radius is the radius of the rolling ball in pixels. Returns ndarray with background subtracted.

unravel.core.img_tools.cluster_IDs(ndarray, min_extent=1, print_IDs=False, print_sizes=False)[source]#

Gets unique intensities [and sizes] for regions/clusters > minextent voxels and prints them in a string-separated list.

Parameters:
  • ndarray

  • min_extent (int, optional) – _description_. Defaults to 1.

  • print_IDs (bool, optional) – _description_. Defaults to False.

  • print_sizes (bool, optional) – _description_. Defaults to False.

Returns:

list of unique intensities

Return type:

list of ints

unravel.core.img_tools.find_bounding_box(ndarray, cluster_ID=None, output_file_path=None)[source]#

Finds the bounding box of all clusters or a specific cluster in a cluster index ndarray and optionally writes to file.

Parameters:
  • ndarray – 3D numpy array to search within.

  • cluster_ID (int) – Cluster intensity to find bbox for. If None, return bbox for all clusters.

  • output_file_path (str) – File path to write the bounding box.

unravel.core.img_tools.crop(ndarray, bbox)[source]#

Crop an ndarray to the specified bounding box (xmin:xmax, ymin:ymax, zmin:zmax)

Parameters:

bbox (str)