atlannot.utils module

Various utilities. (Refactoring in the near future).

class atlannot.utils.Remapper(*volumes: Sequence[ndarray])[source]

Bases: object

Utility class for remapping of labels.

Parameters:

volumes – Different volumes to consider.

static remap(shape: tuple[int, ...], mapping: dict[int, int], unique: np.ndarray, inv: np.ndarray) np.ndarray[source]

Run the remapping.

remap_new_to_old(volume: ndarray) ndarray[source]

Remap from new labels to old labels.

remap_old_to_new(i: int) ndarray[source]

Remap from old labels to new labels.

atlannot.utils.add_middle_line(image, axis=0, thickness=1, value=1)[source]

Add middle line on a given image.

Parameters:
  • image (np.ndarray) – Input image which needs a middle line along one axis.

  • axis (int) – Axis along which to create the middle line.

  • thickness (int) – Thickness of the middle line.

  • value (float) – Pixel intensity of the middle line.

Returns:

new_image – Image as the input image with the middle line as specified.

Return type:

np.ndarray

atlannot.utils.atlas_symmetry_score(atlas, axis=1)[source]

Compute the symmetric score (in misalignment) of label-based image.

Parameters:
  • atlas (np.ndarray) – Image for which symmetric score is computed.

  • axis (int) – Axis along which the symmetric has to be analyzed.

Returns:

alignment – Alignment between two halfs of the input atlas.

Return type:

float

atlannot.utils.compose(*transforms)[source]

Compose several transformations into one.

Parameters:

transforms (Iterable of np.ndarray) – List of transformations to compose. All the transformations should have the same shape (w, h, 1, 1, 2) for 2D and (w, h, p, 1, 1, 3) for 3D.

Returns:

transform_composed – Resulting composed transformations of the same shape as input ones.

Return type:

np.ndarray

atlannot.utils.create_description(name, args=None)[source]

Create description from name and args.

Parameters:
  • name (str) – Name of the experiment.

  • args (None or argparse.Namespace) – Information of the experiment.

Returns:

description – Entire description of the experiment.

Return type:

str

atlannot.utils.edge_laplacian_thick(img, binary=True)[source]

Apply Laplacian to an image (results in thick border).

Parameters:
  • img (np.ndarray) – Input image for which it is needed to compute a convolution.

  • binary (bool) – If True, the return image has only binary values, otherwise the return image pixel values are results of the convolution.

Returns:

result – Resulting Laplacian convolution.

Return type:

np.ndarray

atlannot.utils.edge_laplacian_thin(img, binary=True)[source]

Apply Laplacian to an image (results in thin border).

Parameters:
  • img (np.ndarray) – Input image for which it is needed to compute a convolution.

  • binary (bool) – If True, the return image has only binary values, otherwise the return image pixel values are results of the convolution.

Returns:

result – Resulting Laplacian convolution.

Return type:

np.ndarray

atlannot.utils.edge_sobel(img, binary=True)[source]

Apply Sobel to an image.

Parameters:
  • img (np.ndarray) – Input image for which it is needed to compute a convolution.

  • binary (bool) – If True, the return image has only binary values, otherwise the return image pixel values are results of the convolution.

Returns:

result – Resulting Sobel convolution.

Return type:

np.ndarray

atlannot.utils.image_convolution(img, kernel, kernel_trans=None, *, binary=True)[source]

Compute convolution of an image.

Parameters:
  • img (np.ndarray) – Input image for which it is needed to compute a convolution.

  • kernel (np.ndarray) – Kernel to apply to the input image.

  • kernel_trans (np.ndarray or None) – If specified, a second kernel is applied to the input image.

  • binary (bool) – If True, the return image has only binary values, otherwise the return image pixel values are results of the convolution.

Returns:

grad – Resulting image after convolution.

Return type:

np.ndarray

atlannot.utils.load_nrrd(path, norm=True)[source]

Load nrrd file.

Parameters:
  • path (pathlib.Path or str) – Path of the file to read (with nrrd format).

  • norm (bool) – If True, intensities of the numpy are normalized between 0 and 1.

Returns:

data – Loaded file.

Return type:

np.ndarray

atlannot.utils.load_volume(volume_path, normalize=True)[source]

Load volume from the given path.

Parameters:
  • volume_path (str or pathlib.Path) – Path of file to load

  • normalize (bool) – If True, the numpy is normalized between 0 and 1.

Returns:

img – Loaded path

Return type:

np.ndarray or None

atlannot.utils.merge(img1, img2, scale1=1.0, scale2=1.0)[source]

Merge two images by taking the maximum intensity.

Parameters:
  • img1 (np.ndarray) – First input image.

  • img2 (np.ndarray) – Second input image. Should have the same shape as img1.

  • scale1 (float) – Value used to multiply all pixels intensities of img1.

  • scale2 (float) – Value used to multiply all pixels intensities of img1.

Returns:

img_res – Resulting image of the same shape as img1 and img2.

Return type:

np.ndarray

atlannot.utils.saving_results(output_dir, img_ref=None, img_mov=None, img_reg=None, df=None, description=None)[source]

Save results under output_dir.

Parameters:
  • output_dir (pathlib.Path) – Output directory where to save all the results.

  • img_ref (np.ndarray) – Image used as reference image during the registration.

  • img_mov (np.ndarray) – Image used as moving image during the registration.

  • img_reg (np.ndarray) – Image resulting after the registration

  • df (np.ndarray) – Displacement computed with the registration.

  • description (str) – Description of the experiment.

atlannot.utils.split_halfs(img, axis)[source]

Split image into two half of it. The right part is flipped.

Parameters:
  • img (np.ndarray) – Input image.

  • axis (int) – Axis along which to cut the image into two.

Returns:

  • half_1 (np.ndarray) – First resulting half of the input image.

  • half_2 (np.ndarray) – Second resulting half of the input image, flipped.

atlannot.utils.stain_symmetry_score(img, axis=1)[source]

Compute the symmetric score (SSIM) of intensity-based image.

Parameters:
  • img (np.ndarray) – Image for which symmetric score is computed.

  • axis (int) – Axis along which the symmetric has to be analyzed.

Returns:

ssmi_value – Structural similarity measure between two halfs of the input image.

Return type:

float

atlannot.utils.write_transform(nii_data, path)[source]

Write transform into file.

Parameters:
  • nii_data (np.ndarray) – Transformation to save.

  • path (str) – Path where to save the transformation.