pyalfe.image_processing#
- class pyalfe.image_processing.ImageProcessor[source]#
Bases:
ABC
Abstract class for ImageProcessors.
- abstract static threshold(image, output, lower_bound, upper_bound, inside_target, outside_target)[source]#
Maps any pixel with value inside
[lower_bound , upper_bound]
toinside_target
and any other pixel is mapped tooutsize_target
. The thresholded image is written to output path.- Parameters:
image (str or Path) – Path to the input image.
output (str or Path) – Path to the output image.
lower_bound (int or float) – The lower_bound for the threshold.
upper_bound (int or float) – The upper_bound for the threshold.
inside_target (int or float) –
- The target value for pixels that are inside
[lower_bound , upper_bound]
.
outside_target (int or float) –
- The target value for the pixels that are not inside
[lower_bound , upper_bound]
.
- static binarize(image, output)[source]#
Converts an image to binary by mapping all non-zero values to 1.
- Parameters:
image (str or Path) – Path to the input image.
output (str or Path) – Path to the output image.
- abstract static mask(image, mask, output)[source]#
Masks the input image by setting the pixels outside the mask to zero.
- Parameters:
image (str or Path) – Path to the input image.
mask (str or Path) – Path to the mask.
output (str or Path) – Path to the output image.
- abstract static largest_mask_comp(image, output)[source]#
Finds the largest connected component of an input mask image.
- Parameters:
image (str or Path) – Path to the input image.
output (str or Path) – Path to the output image.
- abstract static holefill(binary_image, output)[source]#
Fills the holes in a binary image.
- Parameters:
binary_image (str or Path) – Path to the input binary image.
output (str or Path) – Path to the output image.
- abstract static reslice_to_ref(ref_image, moving_image, output)[source]#
Reslice the moving_image to the ref_image space.
- Parameters:
ref_image (str or Path) – Path to the reference image.
moving_image (str or Path) – Path to the moving image.
output (str or Path) – Path to the output image.
- abstract static resample_new_dim(image, output, dim1, dim2, dim3, percent=True)[source]#
- Resample the image to new dimensions keeping the bounding box
the same, but changing the number of voxels in the image.
- Parameters:
image (str or Path) – Path to the reference image.
output (str or Path) – Path to the output image.
dim1 (int) – By default the percentage of the original number of voxels along the first dimension. For example, to double the number of voxel along the first dimension, set
dim1 = 200
. Ifpercent
is False, thendim1
is interpreted as the number of voxels in the output image.dim2 (int) – Similar to
dim1
but for the second axis.dim3 (int) – Similar to
dim1
but for the third axis.percent (bool) – If True, the
dim1
,dim2
, anddim3
will be interpreted as percentages of the original dimensions instead of raw dimensions.
- abstract static get_dims(image)[source]#
- Parameters:
image (str or Path) – The path to the image.
- Returns:
Returns a list containing the dimensions of the image.
- Return type:
list
- abstract static trim_largest_comp(image, output, trim_margin_vec)[source]#
Finds the largest component of the image and trims the margins. This function is usefull for trimming neck.
- Parameters:
image (str or Path) – The path to the image.
output (str or Path) – Path to the output image.
trim_margin_vec (tuple or list) – The trim margins along the three dimensions in voxels. For example, (5, 5, 5) means 5 voxels of background are kept in each side of each dimension.
- abstract static set_subtract(binary_image_1, binary_image_2, output)[source]#
Performs set subtraction between of second binary image from the first binary image.
- Parameters:
binary_image_1 (str or Path) – The path to the first image.
binary_image_2 (str or Path) – The path to the second image.
output (str or Path) – Path to the output image.
- abstract static dilate(binary_image, rad, output)[source]#
Dilates binary image by a certain radius given in voxels.
- Parameters:
binary_image (str or Path) – The path to the binary image.
rad (int) – The dilation radius in voxels.
output
- abstract static union(binary_image_1, binary_image_2, output)[source]#
Takes the union of two binary images.
- Parameters:
binary_image_1 (str or Path) – The path to the first image.
binary_image_2 (str or Path) – The path to the second image.
output (str or Path) – Path to the output image.
- abstract static distance_transform(binary_image, output)[source]#
Computes the distance transform of a binary image.
- Parameters:
binary_image (str or Path) – The path to the binary image.
output (str or Path) – Path to the output image.
- abstract static label_mask_comp(binary_image, output)[source]#
Assigns discrete labels to the connected component of a 1 region in a binary image. The largest region is assigned label 1, the second largest is assigned label 2 and so forth.
- Parameters:
binary_image (str or Path) – The path to the binary image.
output (str or Path) – Path to the output image.
- abstract static remap_labels(multi_label_image, label_map, output)[source]#
Maps all the labels if a multi label image according to a label map the label_map is a dictionary that maps input labels to output label. For example, {1: 1, 2: 1, 3: 2} maps labels 1 and 2 in the input to label 1 in the output and label 3 in the input to label 2 in the output. Any other label is mapped to 0.
- Parameters:
multi_label_image (str or Path) – The path to the multi label image
label_map (dict) – The label map
output (str or Path) – Path to the output image.
- class pyalfe.image_processing.Convert3DProcessor[source]#
Bases:
ImageProcessor
- static threshold(image, output, lower_bound, upper_bound, inside_target, outside_target)[source]#
Maps any pixel with value inside
[lower_bound , upper_bound]
toinside_target
and any other pixel is mapped tooutsize_target
. The thresholded image is written to output path.- Parameters:
image (str or Path) – Path to the input image.
output (str or Path) – Path to the output image.
lower_bound (int or float) – The lower_bound for the threshold.
upper_bound (int or float) – The upper_bound for the threshold.
inside_target (int or float) –
- The target value for pixels that are inside
[lower_bound , upper_bound]
.
outside_target (int or float) –
- The target value for the pixels that are not inside
[lower_bound , upper_bound]
.
- static binarize(image, output)[source]#
Converts an image to binary by mapping all non-zero values to 1.
- Parameters:
image (str or Path) – Path to the input image.
output (str or Path) – Path to the output image.
- static mask(image, mask, output)[source]#
Masks the input image by setting the pixels outside the mask to zero.
- Parameters:
image (str or Path) – Path to the input image.
mask (str or Path) – Path to the mask.
output (str or Path) – Path to the output image.
- static largest_mask_comp(image, output)[source]#
Finds the largest connected component of an input mask image.
- Parameters:
image (str or Path) – Path to the input image.
output (str or Path) – Path to the output image.
- static holefill(binary_image, output)[source]#
Fills the holes in a binary image.
- Parameters:
binary_image (str or Path) – Path to the input binary image.
output (str or Path) – Path to the output image.
- static reslice_to_ref(ref_image, moving_image, output)[source]#
Reslice the moving_image to the ref_image space.
- Parameters:
ref_image (str or Path) – Path to the reference image.
moving_image (str or Path) – Path to the moving image.
output (str or Path) – Path to the output image.
- static resample_new_dim(image, output, dim1, dim2, dim3, percent=True)[source]#
- Resample the image to new dimensions keeping the bounding box
the same, but changing the number of voxels in the image.
- Parameters:
image (str or Path) – Path to the reference image.
output (str or Path) – Path to the output image.
dim1 (int) – By default the percentage of the original number of voxels along the first dimension. For example, to double the number of voxel along the first dimension, set
dim1 = 200
. Ifpercent
is False, thendim1
is interpreted as the number of voxels in the output image.dim2 (int) – Similar to
dim1
but for the second axis.dim3 (int) – Similar to
dim1
but for the third axis.percent (bool) – If True, the
dim1
,dim2
, anddim3
will be interpreted as percentages of the original dimensions instead of raw dimensions.
- static get_dims(image)[source]#
- Parameters:
image (str or Path) – The path to the image.
- Returns:
Returns a list containing the dimensions of the image.
- Return type:
list
- static trim_largest_comp(image, output, trim_margin_vec)[source]#
Finds the largest component of the image and trims the margins. This function is usefull for trimming neck.
- Parameters:
image (str or Path) – The path to the image.
output (str or Path) – Path to the output image.
trim_margin_vec (tuple or list) – The trim margins along the three dimensions in voxels. For example, (5, 5, 5) means 5 voxels of background are kept in each side of each dimension.
- static set_subtract(binary_image_1, binary_image_2, output)[source]#
Performs set subtraction between of second binary image from the first binary image.
- Parameters:
binary_image_1 (str or Path) – The path to the first image.
binary_image_2 (str or Path) – The path to the second image.
output (str or Path) – Path to the output image.
- static dilate(binary_image, rad, output)[source]#
Dilates binary image by a certain radius given in voxels.
- Parameters:
binary_image (str or Path) – The path to the binary image.
rad (int) – The dilation radius in voxels.
output
- static union(binary_image_1, binary_image_2, output)[source]#
Takes the union of two binary images.
- Parameters:
binary_image_1 (str or Path) – The path to the first image.
binary_image_2 (str or Path) – The path to the second image.
output (str or Path) – Path to the output image.
- static distance_transform(binary_image, output)[source]#
Computes the distance transform of a binary image.
- Parameters:
binary_image (str or Path) – The path to the binary image.
output (str or Path) – Path to the output image.
- static label_mask_comp(binary_image, output)[source]#
Assigns discrete labels to the connected component of a 1 region in a binary image. The largest region is assigned label 1, the second largest is assigned label 2 and so forth.
- Parameters:
binary_image (str or Path) – The path to the binary image.
output (str or Path) – Path to the output image.
- static remap_labels(multi_label_image, label_map, output)[source]#
Maps all the labels if a multi label image according to a label map the label_map is a dictionary that maps input labels to output label. For example, {1: 1, 2: 1, 3: 2} maps labels 1 and 2 in the input to label 1 in the output and label 3 in the input to label 2 in the output. Any other label is mapped to 0.
- Parameters:
multi_label_image (str or Path) – The path to the multi label image
label_map (dict) – The label map
output (str or Path) – Path to the output image.
- class pyalfe.image_processing.NilearnProcessor[source]#
Bases:
ImageProcessor
- static threshold(image, output, lower_bound, upper_bound, inside_target, outside_target)[source]#
Maps any pixel with value inside
[lower_bound , upper_bound]
toinside_target
and any other pixel is mapped tooutsize_target
. The thresholded image is written to output path.- Parameters:
image (str or Path) – Path to the input image.
output (str or Path) – Path to the output image.
lower_bound (int or float) – The lower_bound for the threshold.
upper_bound (int or float) – The upper_bound for the threshold.
inside_target (int or float) –
- The target value for pixels that are inside
[lower_bound , upper_bound]
.
outside_target (int or float) –
- The target value for the pixels that are not inside
[lower_bound , upper_bound]
.
- static binarize(image, output)[source]#
Converts an image to binary by mapping all non-zero values to 1.
- Parameters:
image (str or Path) – Path to the input image.
output (str or Path) – Path to the output image.
- static mask(image, mask, output)[source]#
Masks the input image by setting the pixels outside the mask to zero.
- Parameters:
image (str or Path) – Path to the input image.
mask (str or Path) – Path to the mask.
output (str or Path) – Path to the output image.
- static largest_mask_comp(image, output)[source]#
Finds the largest connected component of an input mask image.
- Parameters:
image (str or Path) – Path to the input image.
output (str or Path) – Path to the output image.
- static holefill(binary_image, output)[source]#
Fills the holes in a binary image.
- Parameters:
binary_image (str or Path) – Path to the input binary image.
output (str or Path) – Path to the output image.
- static reslice_to_ref(ref_image, moving_image, output)[source]#
Reslice the moving_image to the ref_image space.
- Parameters:
ref_image (str or Path) – Path to the reference image.
moving_image (str or Path) – Path to the moving image.
output (str or Path) – Path to the output image.
- static resample_new_dim(image, output, dim1, dim2, dim3, percent=True)[source]#
- Resample the image to new dimensions keeping the bounding box
the same, but changing the number of voxels in the image.
- Parameters:
image (str or Path) – Path to the reference image.
output (str or Path) – Path to the output image.
dim1 (int) – By default the percentage of the original number of voxels along the first dimension. For example, to double the number of voxel along the first dimension, set
dim1 = 200
. Ifpercent
is False, thendim1
is interpreted as the number of voxels in the output image.dim2 (int) – Similar to
dim1
but for the second axis.dim3 (int) – Similar to
dim1
but for the third axis.percent (bool) – If True, the
dim1
,dim2
, anddim3
will be interpreted as percentages of the original dimensions instead of raw dimensions.
- static get_dims(image)[source]#
- Parameters:
image (str or Path) – The path to the image.
- Returns:
Returns a list containing the dimensions of the image.
- Return type:
list
- static trim_largest_comp(image, output, trim_margin_vec)[source]#
Finds the largest component of the image and trims the margins. This function is usefull for trimming neck.
- Parameters:
image (str or Path) – The path to the image.
output (str or Path) – Path to the output image.
trim_margin_vec (tuple or list) – The trim margins along the three dimensions in voxels. For example, (5, 5, 5) means 5 voxels of background are kept in each side of each dimension.
- static set_subtract(binary_image_1, binary_image_2, output)[source]#
Performs set subtraction between of second binary image from the first binary image.
- Parameters:
binary_image_1 (str or Path) – The path to the first image.
binary_image_2 (str or Path) – The path to the second image.
output (str or Path) – Path to the output image.
- static dilate(binary_image, rad, output)[source]#
Dilates binary image by a certain radius given in voxels.
- Parameters:
binary_image (str or Path) – The path to the binary image.
rad (int) – The dilation radius in voxels.
output
- static union(binary_image_1, binary_image_2, output)[source]#
Takes the union of two binary images.
- Parameters:
binary_image_1 (str or Path) – The path to the first image.
binary_image_2 (str or Path) – The path to the second image.
output (str or Path) – Path to the output image.
- static distance_transform(binary_image, output)[source]#
Computes the distance transform of a binary image.
- Parameters:
binary_image (str or Path) – The path to the binary image.
output (str or Path) – Path to the output image.
- static label_mask_comp(binary_image, output)[source]#
Assigns discrete labels to the connected component of a 1 region in a binary image. The largest region is assigned label 1, the second largest is assigned label 2 and so forth.
- Parameters:
binary_image (str or Path) – The path to the binary image.
output (str or Path) – Path to the output image.
- static remap_labels(multi_label_image, label_map, output)[source]#
Maps all the labels if a multi label image according to a label map the label_map is a dictionary that maps input labels to output label. For example, {1: 1, 2: 1, 3: 2} maps labels 1 and 2 in the input to label 1 in the output and label 3 in the input to label 2 in the output. Any other label is mapped to 0.
- Parameters:
multi_label_image (str or Path) – The path to the multi label image
label_map (dict) – The label map
output (str or Path) – Path to the output image.