intensity_normalization.util package¶
Submodules¶
intensity_normalization.util.coregister module¶
Co-register images with ANTsPy.
- class intensity_normalization.util.coregister.Registrator(template: nib.nifti1.Nifti1Image | ants.ANTsImage = None, *, type_of_transform: str = 'Affine', interpolator: str = 'bSpline', metric: str = 'mattes', initial_rigid: bool = True)[source]¶
Bases:
SingleImageCLI- classmethod from_argparse_args(args: Namespace) Registrator[source]¶
- classmethod get_parent_parser(desc: str, valid_modalities: frozenset[str] = frozenset({'flair', 'md', 'other', 'pd', 't1', 't2'}), **kwargs: Any) ArgumentParser[source]¶
- intensity_normalization.util.coregister.register(image: ValidImage, /, template: Optional[ValidImage] = None, *, type_of_transform: str = 'Affine', interpolator: str = 'bSpline', metric: str = 'mattes', initial_rigid: bool = True, template_mask: Optional[ValidImage] = None) nib.nifti1.Nifti1Image | ants.ANTsImage[source]¶
intensity_normalization.util.histogram_tools module¶
Process the histograms of MR (brain) images
- intensity_normalization.util.histogram_tools.get_first_tissue_mode(image: ImageLike, /, *, remove_tail: bool = True, tail_percentage: float = 99.0) float[source]¶
Mode of the lowest-intensity tissue class
- Parameters:
image – array of image data (like an np.ndarray)
remove_tail – remove tail from histogram
tail_percentage – if remove_tail, use the histogram below this percentage
- Returns:
mode of the lowest-intensity tissue class
- Return type:
first_tissue_mode
- intensity_normalization.util.histogram_tools.get_largest_tissue_mode(image: ImageLike, /) float[source]¶
Mode of the largest tissue class
- Parameters:
image – array of image data (like an np.ndarray)
- Returns:
value of the largest tissue mode
- Return type:
largest_tissue_mode
- intensity_normalization.util.histogram_tools.get_last_tissue_mode(image: ImageLike, /, *, remove_tail: bool = True, tail_percentage: float = 96.0) float[source]¶
Mode of the highest-intensity tissue class
- Parameters:
image – array of image data (like an np.ndarray)
remove_tail – remove tail from histogram
tail_percentage – if remove_tail, use the histogram below this percentage
- Returns:
mode of the highest-intensity tissue class
- Return type:
last_tissue_mode
- intensity_normalization.util.histogram_tools.get_tissue_mode(image: ImageLike, /, *, modality: Modality) float[source]¶
Find the appropriate tissue mode given a modality
- intensity_normalization.util.histogram_tools.smooth_histogram(image: ImageLike, /) tuple[ImageLike, ImageLike][source]¶
Use kernel density estimate to get smooth histogram
- Parameters:
image – array of image data (like an np.ndarray)
- Returns:
domain of the pdf pdf: kernel density estimate of the pdf of data
- Return type:
grid
intensity_normalization.util.io module¶
Input/output utilities for the project
- intensity_normalization.util.io.gather_images(dirpath: str | PathLike, *, ext: str = 'nii*', exclude: Sequence[str] = ()) list[pymedio.image.Image][source]¶
return all images of extension ext from a directory
- intensity_normalization.util.io.gather_images_and_masks(image_dir: intnormt.PathLike, mask_dir: intnormt.PathLike | None = None, *, ext: str = 'nii*', exclude: collections.abc.Sequence[str] = ()) tuple[PymedioImageList, PymedioMaskListOrNone][source]¶
- intensity_normalization.util.io.glob_ext(dirpath: str | PathLike, *, ext: str = 'nii*', exclude: Sequence[str] = ()) list[Path][source]¶
return a sorted list of ext files for a given directory path
- intensity_normalization.util.io.split_filename(filepath: str | PathLike, /, *, resolve: bool = False) SplitFilename[source]¶
split a filepath into the directory, base, and extension .. rubric:: Examples
>>> split_filename("path/base.ext") SplitFilename(path=PosixPath('path'), base='base', ext='.ext')
intensity_normalization.util.preprocess module¶
Preprocess MR images for image processing.
Preprocess MR images according to a simple scheme: 1) N4 bias field correction 2) resample to X mm x Y mm x Z mm 3) reorient images to specification
- class intensity_normalization.util.preprocess.Preprocessor(*, resolution: tuple[float, ...] | None = None, orientation: str = 'RAI', n4_convergence_options: dict[str, Any] | None = None, interp_type: str = 'linear', second_n4_with_smoothed_mask: bool = True)[source]¶
Bases:
SingleImageCLI- classmethod from_argparse_args(args: Namespace) Preprocessor[source]¶
- intensity_normalization.util.preprocess.preprocess(image: intnormt.ImageLike, /, mask: intnormt.ImageLike | None = None, *, resolution: tuple[float, ...] | None = None, orientation: str = 'RAS', n4_convergence_options: dict[str, Any] | None = None, interp_type: str = 'linear', second_n4_with_smoothed_mask: bool = True) tuple[mioi.Image, mioi.Image][source]¶
Preprocess an MR image
Preprocess an MR image according to a simple scheme: 1) N4 bias field correction 2) resample to X mm x Y mm x … 3) reorient images to RAI
- Parameters:
image – image to preprocess
mask – mask covering the brain of image (none if already skull-stripped)
resolution – resolution for resampling. None for no resampling.
orientation – reorient the image according to this. See ANTsPy for details.
n4_convergence_options – n4 processing options. See ANTsPy for details.
interp_type – interpolation type for resampling choices: linear, nearest_neighbor, gaussian, windowed_sinc, bspline
second_n4_with_smoothed_mask – do a second N4 with a smoothed mask often improves the bias field correction in the image
- Returns:
preprocessed image and corresponding foreground mask
intensity_normalization.util.tissue_membership module¶
Find the tissue-membership of a T1-w brain image.
- class intensity_normalization.util.tissue_membership.TissueMembershipFinder(hard_segmentation: bool = False)[source]¶
Bases:
SingleImageCLI- classmethod from_argparse_args(args: Namespace) TissueMembershipFinder[source]¶
- intensity_normalization.util.tissue_membership.find_tissue_memberships(image: intnormt.ImageLike, /, mask: intnormt.ImageLike | None = None, *, hard_segmentation: bool = False, n_classes: int = 3) mioi.Image[source]¶
Tissue memberships for a T1-w brain image with fuzzy c-means
- Parameters:
image – image to find tissue masks for (must be T1-w)
mask – mask covering the brain of image (none if already skull-stripped)
hard_segmentation – pick the maximum membership as the true class in output
n_classes – number of classes (usually three for CSF, GM, WM)
- Returns:
- membership values for each of three classes in the image
(or class determinations w/ hard_seg)
- Return type:
tissue_mask