-import os
-from configparser import ConfigParser
-from functools import cached_property
-from types import SimpleNamespace
+import os
+from configparser import ConfigParser
+from functools import cached_property
+from types import SimpleNamespace
-from pyalfe.data_structure import (
+from pyalfe.data_structure import (
DefaultALFEDataDir ,
BIDSDataDir ,
PatientDicomDataDir ,
Modality ,
)
-from pyalfe.image_processing import Convert3DProcessor , NilearnProcessor
-from pyalfe.image_registration import GreedyRegistration , AntsRegistration
-from pyalfe.inference import NNUnetV2 , SynthSeg
-from pyalfe.models import MODELS_PATH
-from pyalfe.pipeline import PyALFEPipelineRunner , DicomProcessingPipelineRunner
-from pyalfe.tasks.dicom_processing import DicomProcessing
-from pyalfe.tasks.initialization import Initialization
-from pyalfe.tasks.quantification import Quantification
-from pyalfe.tasks.registration import (
+from pyalfe.image_processing import Convert3DProcessor , NilearnProcessor
+from pyalfe.image_registration import GreedyRegistration , AntsRegistration
+from pyalfe.inference import NNUnetV2 , SynthSeg
+from pyalfe.models import MODELS_PATH
+from pyalfe.pipeline import PyALFEPipelineRunner , DicomProcessingPipelineRunner
+from pyalfe.tasks.dicom_processing import DicomProcessing
+from pyalfe.tasks.initialization import Initialization
+from pyalfe.tasks.quantification import Quantification
+from pyalfe.tasks.registration import (
CrossModalityRegistration ,
Resampling ,
T1Registration ,
)
-from pyalfe.tasks.segmentation import (
+from pyalfe.tasks.segmentation import (
TissueWithPriorSegementation ,
SingleModalitySegmentation ,
MultiModalitySegmentation ,
SynthSegTissueSegmentation ,
)
-from pyalfe.tasks.skullstripping import Skullstripping
-from pyalfe.tasks.t1_postprocessing import T1Postprocessing
-from pyalfe.tasks.t1_preprocessing import T1Preprocessing
+from pyalfe.tasks.skullstripping import Skullstripping
+from pyalfe.tasks.t1_postprocessing import T1Postprocessing
+from pyalfe.tasks.t1_preprocessing import T1Preprocessing
[docs]
-
class Config :
+
class Config :
[docs]
-
def from_ini ( self , ini_file ):
+
def from_ini ( self , ini_file ):
if not os . path . exists ( ini_file ):
raise FileNotFoundError ( f 'config file { ini_file } does not exist.' )
config_parser = ConfigParser ()
@@ -415,7 +401,7 @@
Source code for pyalfe.containers
[docs]
-
def from_dict ( self , d ):
+
def from_dict ( self , d ):
for section , key_value in d . items ():
if hasattr ( self , section ):
current = getattr ( self , section )
@@ -429,13 +415,13 @@
Source code for pyalfe.containers
[docs]
-
class DeclarativeContainer :
-
def __init__ ( self ):
+
class DeclarativeContainer :
+
def __init__ ( self ):
self . config = Config ()
[docs]
-
def init_resources ( self ):
+
def init_resources ( self ):
"""This function exists for compatibility reasons"""
pass
@@ -444,13 +430,13 @@ Source code for pyalfe.containers
[docs]
-
class PipelineContainer ( DeclarativeContainer ):
+
class PipelineContainer ( DeclarativeContainer ):
"""
container objects for all the dependencies of the pipeline.
"""
@cached_property
-
def pipeline_dir ( self ):
+
def pipeline_dir ( self ):
if self . config . options . data_dir_structure == 'alfe' :
return DefaultALFEDataDir (
output_dir = self . config . options . output_dir ,
@@ -467,7 +453,7 @@
Source code for pyalfe.containers
)
@cached_property
- def image_processor ( self ):
+ def image_processor ( self ):
if self . config . options . image_processor == 'c3d' :
return Convert3DProcessor ()
elif self . config . options . image_processor == 'nilearn' :
@@ -478,7 +464,7 @@ Source code for pyalfe.containers
)
@property
- def image_registration ( self ):
+ def image_registration ( self ):
if self . config . options . image_registration == 'greedy' :
return GreedyRegistration ()
elif self . config . options . image_registration == 'ants' :
@@ -489,7 +475,7 @@ Source code for pyalfe.containers
)
@cached_property
- def skullstripping_model ( self ):
+ def skullstripping_model ( self ):
return NNUnetV2 (
model_dir = str (
MODELS_PATH . joinpath (
@@ -502,7 +488,7 @@ Source code for pyalfe.containers
)
@cached_property
- def flair_model ( self ):
+ def flair_model ( self ):
return NNUnetV2 (
model_dir = str (
MODELS_PATH . joinpath (
@@ -515,7 +501,7 @@ Source code for pyalfe.containers
)
@cached_property
- def enhancement_model ( self ):
+ def enhancement_model ( self ):
return NNUnetV2 (
model_dir = str (
MODELS_PATH . joinpath (
@@ -528,7 +514,7 @@ Source code for pyalfe.containers
)
@cached_property
- def tissue_model ( self ):
+ def tissue_model ( self ):
if self . config . options . tissue_segmentation == 'prior' :
return NNUnetV2 (
model_dir = str (
@@ -548,7 +534,7 @@ Source code for pyalfe.containers
)
@cached_property
- def initialization ( self ):
+ def initialization ( self ):
return Initialization (
pipeline_dir = self . pipeline_dir ,
modalities = self . config . options . modalities . split ( ',' ),
@@ -556,7 +542,7 @@ Source code for pyalfe.containers
)
@cached_property
- def skullstripping ( self ):
+ def skullstripping ( self ):
return Skullstripping (
inference_model = self . skullstripping_model ,
image_processor = self . image_processor ,
@@ -566,7 +552,7 @@ Source code for pyalfe.containers
)
@cached_property
- def t1_preprocessing ( self ):
+ def t1_preprocessing ( self ):
return T1Preprocessing (
image_processor = self . image_processor ,
pipeline_dir = self . pipeline_dir ,
@@ -574,7 +560,7 @@ Source code for pyalfe.containers
)
@cached_property
- def cross_modality_registration ( self ):
+ def cross_modality_registration ( self ):
return CrossModalityRegistration (
image_registration = self . image_registration ,
pipeline_dir = self . pipeline_dir ,
@@ -584,7 +570,7 @@ Source code for pyalfe.containers
)
@cached_property
- def flair_segmentation ( self ):
+ def flair_segmentation ( self ):
return SingleModalitySegmentation (
inference_model = self . flair_model ,
image_processor = self . image_processor ,
@@ -599,7 +585,7 @@ Source code for pyalfe.containers
)
@cached_property
- def enhancement_segmentation ( self ):
+ def enhancement_segmentation ( self ):
return MultiModalitySegmentation (
inference_model = self . enhancement_model ,
image_processor = self . image_processor ,
@@ -615,7 +601,7 @@ Source code for pyalfe.containers
)
@cached_property
- def tissue_segmentation ( self ):
+ def tissue_segmentation ( self ):
if self . config . options . tissue_segmentation == 'prior' :
return TissueWithPriorSegementation (
inference_model = self . tissue_model ,
@@ -641,7 +627,7 @@ Source code for pyalfe.containers
)
@cached_property
- def t1_postprocessing ( self ):
+ def t1_postprocessing ( self ):
return T1Postprocessing (
image_processor = self . image_processor ,
pipeline_dir = self . pipeline_dir ,
@@ -649,7 +635,7 @@ Source code for pyalfe.containers
)
@cached_property
- def t1_registration ( self ):
+ def t1_registration ( self ):
return T1Registration (
image_processor = self . image_processor ,
image_registration = self . image_registration ,
@@ -658,7 +644,7 @@ Source code for pyalfe.containers
)
@cached_property
- def resampling ( self ):
+ def resampling ( self ):
return Resampling (
image_processor = self . image_processor ,
image_registration = self . image_registration ,
@@ -668,7 +654,7 @@ Source code for pyalfe.containers
)
@cached_property
- def quantification ( self ):
+ def quantification ( self ):
return Quantification (
pipeline_dir = self . pipeline_dir ,
modalities_all = self . config . options . modalities . split ( ',' ),
@@ -677,7 +663,7 @@ Source code for pyalfe.containers
)
@cached_property
- def pyalfe_pipeline_runner ( self ):
+ def pyalfe_pipeline_runner ( self ):
return PyALFEPipelineRunner (
initialization = self . initialization ,
skullstripping = self . skullstripping ,
@@ -696,11 +682,11 @@ Source code for pyalfe.containers
[docs]
-
class DicomProcessingContianer ( DeclarativeContainer ):
+
class DicomProcessingContianer ( DeclarativeContainer ):
"""Contianer for dicom processing pipeline depedencies"""
@cached_property
-
def pipeline_dir ( self ):
+
def pipeline_dir ( self ):
if self . config . options . data_dir_structure == 'alfe' :
return DefaultALFEDataDir (
output_dir = os . devnull , input_dir = self . config . options . nifti_dir
@@ -716,11 +702,11 @@
Source code for pyalfe.containers
)
@cached_property
- def dicom_dir ( self ):
+ def dicom_dir ( self ):
return PatientDicomDataDir ( dicom_dir = self . config . options . dicom_dir )
@cached_property
- def dicom_processing ( self ):
+ def dicom_processing ( self ):
return DicomProcessing (
pipeline_dir = self . pipeline_dir ,
dicom_dir = self . dicom_dir ,
@@ -728,7 +714,7 @@ Source code for pyalfe.containers
)
@cached_property
- def dicom_processing_pipeline_runner ( self ):
+ def dicom_processing_pipeline_runner ( self ):
return DicomProcessingPipelineRunner ( dicom_processing = self . dicom_processing )
@@ -793,8 +779,8 @@
Source code for pyalfe.containers
-
-
+
+
diff --git a/_modules/pyalfe/data_structure.html b/_modules/pyalfe/data_structure.html
index 0f27334..77c1f6b 100644
--- a/_modules/pyalfe/data_structure.html
+++ b/_modules/pyalfe/data_structure.html
@@ -15,19 +15,21 @@
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
+
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
+
@@ -35,10 +37,11 @@
+
+
-
-
-
+
+
@@ -61,6 +64,7 @@
+
@@ -76,19 +80,8 @@
Back to top
-
-
-
-
-
-
-
+
+
@@ -123,7 +115,8 @@
-
@@ -360,26 +346,26 @@
Source code for pyalfe.data_structure
-import collections
-import glob
-import importlib
-import json
-import logging
-import re
-from abc import ABC
-from enum import auto , IntEnum
-import os
-from pathlib import Path
+import collections
+import glob
+import importlib
+import json
+import logging
+import re
+from abc import ABC
+from enum import auto , IntEnum
+import os
+from pathlib import Path
-from bids import BIDSLayout
-import pydicom
+from bids import BIDSLayout
+import pydicom
-from strenum import StrEnum
+from strenum import StrEnum
[docs]
-
class Modality ( StrEnum ):
+
class Modality ( StrEnum ):
T1 = auto ()
T1Post = auto ()
T2 = auto ()
@@ -397,7 +383,7 @@
Source code for pyalfe.data_structure
[docs]
-
class Orientation ( StrEnum ):
+
class Orientation ( StrEnum ):
AXIAL = auto ()
SAGITTAL = auto ()
CORONAL = auto ()
@@ -406,7 +392,7 @@ Source code for pyalfe.data_structure
[docs]
-
class Tissue ( IntEnum ):
+
class Tissue ( IntEnum ):
BACKGROUND = 0
CSF = 1
CORTICAL_GRAY_MATTER = 2
@@ -422,12 +408,12 @@
Source code for pyalfe.data_structure
[docs]
-
class PipelineDataDir ( ABC ):
+
class PipelineDataDir ( ABC ):
"""Abstract PipelineDataDir"""
[docs]
-
def get_output_image (
+
def get_output_image (
self ,
accession ,
modality ,
@@ -472,7 +458,7 @@
Source code for pyalfe.data_structure
[docs]
-
def get_input_image ( self , accession , modality , extension = '.nii.gz' ):
+
def get_input_image ( self , accession , modality , extension = '.nii.gz' ):
"""Generates the path for an input image.
Parameters
@@ -494,7 +480,7 @@
Source code for pyalfe.data_structure
[docs]
-
def get_quantification_file (
+
def get_quantification_file (
self , accession , modality , quantification_file_type , extension = '.csv'
):
"""Generates the path for an output quantification file.
@@ -524,20 +510,20 @@
Source code for pyalfe.data_structure
[docs]
-
class DefaultALFEDataDir ( PipelineDataDir ):
+
class DefaultALFEDataDir ( PipelineDataDir ):
"""
Default implementation of PipelineDataDir
"""
-
def __init__ ( self , output_dir , input_dir ):
+
def __init__ ( self , output_dir , input_dir ):
self . dir_dict = { 'output' : output_dir , 'input' : input_dir }
-
def __call__ ( self , dir_type , accession , * sub_dir_names ):
+
def __call__ ( self , dir_type , accession , * sub_dir_names ):
return os . path . join ( self . dir_dict [ dir_type ], accession , * sub_dir_names )
[docs]
-
def create_dir ( self , dir_type , accession , * sub_dir_names , exists = True ):
+
def create_dir ( self , dir_type , accession , * sub_dir_names , exists = True ):
directory = self ( dir_type , accession , * sub_dir_names )
Path ( directory ) . expanduser () . mkdir ( parents = True , exist_ok = exists )
return directory
@@ -545,7 +531,7 @@
Source code for pyalfe.data_structure
[docs]
-
def get_output_image (
+
def get_output_image (
self ,
accession ,
modality ,
@@ -628,7 +614,7 @@
Source code for pyalfe.data_structure
[docs]
-
def get_input_image ( self , accession , modality , extension = '.nii.gz' ):
+
def get_input_image ( self , accession , modality , extension = '.nii.gz' ):
"""Generate the path for an input image in
ALFE default dir structure format.
@@ -659,7 +645,7 @@
Source code for pyalfe.data_structure
[docs]
-
def get_quantification_file (
+
def get_quantification_file (
self , accession , modality , quantification_file_type , extension = '.csv'
):
"""Generate the path for a quantification file in
@@ -702,14 +688,14 @@
Source code for pyalfe.data_structure
[docs]
-
class BIDSDataDir ( PipelineDataDir ):
+
class BIDSDataDir ( PipelineDataDir ):
"""
BIDS almost-compliant implementation of PipelineDataDir
"""
logger = logging . getLogger ( 'BIDSDataDir' )
-
def __init__ ( self , output_dir , input_dir ):
+
def __init__ ( self , output_dir , input_dir ):
self . input_layout = BIDSLayout ( Path ( input_dir ) . expanduser ())
with open (
@@ -746,7 +732,7 @@
Source code for pyalfe.data_structure
[docs]
-
def get_input_image ( self , accession , modality , extension = '.nii.gz' ):
+
def get_input_image ( self , accession , modality , extension = '.nii.gz' ):
"""Generates the path for an input image in BIDS dir structure format.
Parameters
@@ -824,7 +810,7 @@
Source code for pyalfe.data_structure
[docs]
-
def get_output_image (
+
def get_output_image (
self ,
accession ,
modality ,
@@ -921,7 +907,7 @@
Source code for pyalfe.data_structure
[docs]
-
def get_quantification_file (
+
def get_quantification_file (
self , accession , modality , quantification_file_type , extension = '.csv'
):
"""Generate the path for a quantification file in
@@ -976,7 +962,7 @@
Source code for pyalfe.data_structure
[docs]
-
class PatientDicomDataDir :
+
class PatientDicomDataDir :
"""This class is designed to work with directories containing raw dicom
files for a patient that are organized as:
dicom_dir
@@ -986,12 +972,12 @@
Source code for pyalfe.data_structure
└─ instance_1.dcm
"""
- def __init__ ( self , dicom_dir ) -> None :
+ def __init__ ( self , dicom_dir ) -> None :
self . dicom_dir = dicom_dir
[docs]
-
def is_dicom_file ( self , file ):
+
def is_dicom_file ( self , file ):
"""Function to check if file is a dicom file.
The first 128 bytes are preamble the next 4 bytes should
contain DICM otherwise it is not a dicom file. Adapted from
@@ -1026,7 +1012,7 @@
Source code for pyalfe.data_structure
[docs]
-
def get_all_dicom_series_instances ( self , accession ):
+
def get_all_dicom_series_instances ( self , accession ):
"""This method returns a list of Series each containing a series path
and all of the instances in the series.
@@ -1056,7 +1042,7 @@
Source code for pyalfe.data_structure
[docs]
-
def get_series ( self , accession , series_uid ):
+
def get_series ( self , accession , series_uid ):
"""This method returns the path to a series.
Parameters
@@ -1138,8 +1124,8 @@
Source code for pyalfe.data_structure
-
-
+
+
diff --git a/_modules/pyalfe/image_processing.html b/_modules/pyalfe/image_processing.html
index a5ad038..1985c0f 100644
--- a/_modules/pyalfe/image_processing.html
+++ b/_modules/pyalfe/image_processing.html
@@ -15,19 +15,21 @@
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
+
+
+
+
-
-
-
+
+
-
-
-
-
-
-
-
+
@@ -35,10 +37,11 @@
+
+
-
-
-
+
+
@@ -61,6 +64,7 @@
+
@@ -76,19 +80,8 @@
Back to top
-
-
-
-
-
-
-
+
+
@@ -123,7 +115,8 @@
-
@@ -360,24 +346,24 @@
Source code for pyalfe.image_processing
-import shutil
-from abc import ABC , abstractmethod
-import re
-from collections import defaultdict
+import shutil
+from abc import ABC , abstractmethod
+import re
+from collections import defaultdict
-import nibabel as nib
-import scipy.ndimage
-import nilearn.image
-import nilearn.masking
-import nilearn.regions
-import numpy as np
+import nibabel as nib
+import scipy.ndimage
+import nilearn.image
+import nilearn.masking
+import nilearn.regions
+import numpy as np
-from pyalfe.interfaces.c3d import C3D
+from pyalfe.interfaces.c3d import C3D
[docs]
-
class ImageProcessor ( ABC ):
+
class ImageProcessor ( ABC ):
"""
Abstract class for ImageProcessors.
"""
@@ -386,7 +372,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def threshold (
+ def threshold (
image , output , lower_bound , upper_bound , inside_target , outside_target
):
"""Maps any pixel with value inside
@@ -421,7 +407,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def binarize ( image , output ):
+
def binarize ( image , output ):
"""Converts an image to binary by mapping all non-zero values to 1.
Parameters
@@ -442,7 +428,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def mask ( image , mask , output ):
+ def mask ( image , mask , output ):
"""Masks the input image by setting the pixels outside the mask to zero.
Parameters
@@ -465,7 +451,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def largest_mask_comp ( image , output ):
+ def largest_mask_comp ( image , output ):
"""Finds the largest connected component of an input mask image.
Parameters
@@ -486,7 +472,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def holefill ( binary_image , output ):
+ def holefill ( binary_image , output ):
"""Fills the holes in a binary image.
Parameters
@@ -507,7 +493,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def reslice_to_ref ( ref_image , moving_image , output ):
+ def reslice_to_ref ( ref_image , moving_image , output ):
"""Reslice the moving_image to the ref_image space.
Parameters
@@ -530,7 +516,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def resample_new_dim ( image , output , dim1 , dim2 , dim3 , percent = True ):
+ def resample_new_dim ( image , output , dim1 , dim2 , dim3 , percent = True ):
"""Resample the image to new dimensions keeping the bounding box
the same, but changing the number of voxels in the image.
@@ -566,7 +552,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def get_dims ( image ):
+ def get_dims ( image ):
"""
Parameters
@@ -587,7 +573,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def trim_largest_comp ( image , output , trim_margin_vec ):
+ def trim_largest_comp ( image , output , trim_margin_vec ):
"""Finds the largest component of the image and trims the margins.
This function is usefull for trimming neck.
@@ -613,7 +599,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def set_subtract ( binary_image_1 , binary_image_2 , output ):
+ def set_subtract ( binary_image_1 , binary_image_2 , output ):
"""Performs set subtraction between of second binary image
from the first binary image.
@@ -637,7 +623,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def dilate ( binary_image , rad , output ):
+ def dilate ( binary_image , rad , output ):
"""Dilates binary image by a certain radius given in voxels.
Parameters
@@ -659,7 +645,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def union ( binary_image_1 , binary_image_2 , output ):
+ def union ( binary_image_1 , binary_image_2 , output ):
"""Takes the union of two binary images.
Parameters
@@ -682,7 +668,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def distance_transform ( binary_image , output ):
+ def distance_transform ( binary_image , output ):
"""Computes the distance transform of a binary image.
Parameters
@@ -703,7 +689,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def label_mask_comp ( binary_image , output ):
+ def label_mask_comp ( binary_image , output ):
"""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.
@@ -726,7 +712,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
@abstractmethod
- def remap_labels ( multi_label_image , label_map , output ):
+ def remap_labels ( multi_label_image , label_map , output ):
"""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
@@ -752,11 +738,11 @@ Source code for pyalfe.image_processing
[docs]
-
class Convert3DProcessor ( ImageProcessor ):
+
class Convert3DProcessor ( ImageProcessor ):
[docs]
@staticmethod
-
def threshold (
+
def threshold (
image , output , lower_bound , upper_bound , inside_target , outside_target
):
c3d = C3D ()
@@ -771,7 +757,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def binarize ( image , output ):
+
def binarize ( image , output ):
c3d = C3D ()
c3d . operand ( image ) . binarize () . out ( output ) . run ()
@@ -779,7 +765,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def mask ( image , mask , output ):
+
def mask ( image , mask , output ):
c3d = C3D ()
c3d . operand ( image , mask ) . multiply () . out ( output ) . run ()
@@ -787,7 +773,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def largest_mask_comp ( image , output ):
+
def largest_mask_comp ( image , output ):
c3d = C3D ()
(
c3d . operand ( image )
@@ -807,7 +793,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def holefill ( binary_image , output ):
+
def holefill ( binary_image , output ):
c3d = C3D ()
c3d . operand ( binary_image ) . holefill ( 1 , 0 ) . out ( output ) . run ()
@@ -815,7 +801,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def reslice_to_ref ( ref_image , moving_image , output ):
+
def reslice_to_ref ( ref_image , moving_image , output ):
c3d = C3D ()
c3d . operand ( ref_image , moving_image ) . reslice_identity () . out ( output ) . run ()
@@ -823,7 +809,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def resample_new_dim ( image , output , dim1 , dim2 , dim3 , percent = True ):
+
def resample_new_dim ( image , output , dim1 , dim2 , dim3 , percent = True ):
c3d = C3D ()
reasmple_arg = f ' { str ( dim1 ) } x { str ( dim2 ) } x { str ( dim3 ) } '
if percent :
@@ -834,7 +820,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def get_dims ( image ):
+
def get_dims ( image ):
c3d = C3D ()
output = c3d . operand ( image ) . info () . check_output ()
match_list = re . findall ( r 'dim = \[.*?\]' , output )
@@ -846,7 +832,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def trim_largest_comp ( image , output , trim_margin_vec ):
+
def trim_largest_comp ( image , output , trim_margin_vec ):
c3d = C3D ()
largest_comp_cmd = c3d . operand ( image ) . dup () . comp () . thresh ( 1 , 1 , 1 , 0 ) . multiply ()
trim_cmd = largest_comp_cmd . trim ( * trim_margin_vec ) . out ( output )
@@ -857,7 +843,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def set_subtract ( binary_image_1 , binary_image_2 , output ):
+
def set_subtract ( binary_image_1 , binary_image_2 , output ):
c3d = C3D ()
c3d . operand ( binary_image_1 , binary_image_2 ) . scale ( - 1 ) . add () . thresh (
1 , 1 , 1 , 0
@@ -867,7 +853,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def dilate ( binary_image , rad , output ):
+
def dilate ( binary_image , rad , output ):
c3d = C3D ()
if rad >= 0 :
c3d . operand ( binary_image ) . dilate ( label = 1 , r1 = rad , r2 = rad , r3 = rad ) . out (
@@ -882,7 +868,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def union ( binary_image_1 , binary_image_2 , output ):
+
def union ( binary_image_1 , binary_image_2 , output ):
c3d = C3D ()
c3d . operand ( binary_image_1 , binary_image_2 ) . add () . thresh ( 1 , 2 , 1 , 0 ) . out (
output
@@ -892,7 +878,7 @@
Source code for pyalfe.image_processing
@@ -900,7 +886,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def label_mask_comp ( binary_image , output ):
+
def label_mask_comp ( binary_image , output ):
c3d = C3D ()
c3d . operand ( binary_image ) . comp () . out ( output ) . run ()
@@ -908,7 +894,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def remap_labels ( multi_label_image , label_map , output ):
+
def remap_labels ( multi_label_image , label_map , output ):
reverse_map = defaultdict ( list )
for input_label , output_label in label_map . items ():
reverse_map [ output_label ] . append ( input_label )
@@ -934,18 +920,18 @@
Source code for pyalfe.image_processing
[docs]
-
class NilearnProcessor ( ImageProcessor ):
+
class NilearnProcessor ( ImageProcessor ):
[docs]
@staticmethod
-
def save ( nib_image , file ):
+
def save ( nib_image , file ):
# np.int32 is problematic. 1s can turn into 0.9999999
nib_image . set_data_dtype ( np . float32 )
nib . save ( nib_image , file )
@staticmethod
-
def _crop_img_to ( image , slices , copy = True ):
+
def _crop_img_to ( image , slices , copy = True ):
data = nilearn . image . get_data ( image )
affine = image . affine
@@ -967,7 +953,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def crop_img ( image , rtol = 1e-8 , copy = True , pad = ( 0 , 0 , 0 )):
+
def crop_img ( image , rtol = 1e-8 , copy = True , pad = ( 0 , 0 , 0 )):
data = nilearn . image . get_data ( image )
infinity_norm = max ( - data . min (), data . max ())
@@ -995,7 +981,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def threshold (
+
def threshold (
image , output , lower_bound , upper_bound , inside_target , outside_target
):
nib_image = nilearn . image . load_img ( image )
@@ -1010,7 +996,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def binarize ( image , output ):
+
def binarize ( image , output ):
nib_image = nilearn . image . load_img ( image )
NilearnProcessor . save ( nilearn . image . binarize_img ( nib_image ), output )
@@ -1018,7 +1004,7 @@ Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def mask ( image , mask , output ):
+
def mask ( image , mask , output ):
nib_image = nilearn . image . load_img ( image )
nib_mask = nilearn . image . load_img ( mask )
masked_image = nib . Nifti1Image (
@@ -1030,7 +1016,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def largest_mask_comp ( image , output ):
+
def largest_mask_comp ( image , output ):
try :
nilearn . image . largest_connected_component_img ( image ) . to_filename ( output )
except ValueError as e :
@@ -1043,7 +1029,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def holefill ( binary_image , output ):
+
def holefill ( binary_image , output ):
nib_image = nilearn . image . load_img ( binary_image )
data = nib_image . get_fdata ()
holefilled_data = scipy . ndimage . binary_fill_holes ( data ) . astype ( 'int32' )
@@ -1054,14 +1040,14 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def reslice_to_ref ( ref_image , moving_image , output ):
+
def reslice_to_ref ( ref_image , moving_image , output ):
nilearn . image . resample_to_img ( moving_image , ref_image ) . to_filename ( output )
[docs]
@staticmethod
-
def resample_new_dim ( image , output , dim1 , dim2 , dim3 , percent = True ):
+
def resample_new_dim ( image , output , dim1 , dim2 , dim3 , percent = True ):
nib_image = nilearn . image . load_img ( image )
dims = nib_image . get_fdata () . shape
if percent :
@@ -1086,14 +1072,14 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def get_dims ( image ):
+
def get_dims ( image ):
return nilearn . image . load_img ( image ) . get_fdata () . shape
[docs]
@staticmethod
-
def trim_largest_comp ( image , output , trim_margin_vec ):
+
def trim_largest_comp ( image , output , trim_margin_vec ):
nib_image = nilearn . image . load_img ( image )
largest_comp_mask_image = nilearn . image . largest_connected_component_img (
nib_image
@@ -1111,7 +1097,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def set_subtract ( binary_image_1 , binary_image_2 , output ):
+
def set_subtract ( binary_image_1 , binary_image_2 , output ):
subtract_image = nilearn . image . binarize_img (
nilearn . image . math_img (
'np.maximum(img1 - img2, 0)' , img1 = binary_image_1 , img2 = binary_image_2
@@ -1123,7 +1109,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def dilate ( binary_image , rad , output ):
+
def dilate ( binary_image , rad , output ):
nib_image = nilearn . image . load_img ( binary_image )
data = nib_image . get_fdata ()
if rad >= 0 :
@@ -1141,7 +1127,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def union ( binary_image_1 , binary_image_2 , output ):
+
def union ( binary_image_1 , binary_image_2 , output ):
union_image = nilearn . image . binarize_img (
nilearn . image . math_img (
'img1 + img2' , img1 = binary_image_1 , img2 = binary_image_2
@@ -1153,7 +1139,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def distance_transform ( binary_image , output ):
+
def distance_transform ( binary_image , output ):
nib_image = nilearn . image . load_img ( binary_image )
data = nib_image . get_fdata ()
dist_data = scipy . ndimage . distance_transform_edt ( 1 - data )
@@ -1164,7 +1150,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def label_mask_comp ( binary_image , output ):
+
def label_mask_comp ( binary_image , output ):
nib_image = nilearn . image . load_img ( binary_image )
comp_image = nilearn . regions . connected_label_regions ( nib_image )
comp_image_data = comp_image . get_fdata ()
@@ -1181,7 +1167,7 @@
Source code for pyalfe.image_processing
[docs]
@staticmethod
-
def remap_labels ( multi_label_image , label_map , output ):
+
def remap_labels ( multi_label_image , label_map , output ):
reverse_map = defaultdict ( list )
for input_label , output_label in label_map . items ():
reverse_map [ output_label ] . append ( input_label )
@@ -1255,8 +1241,8 @@
Source code for pyalfe.image_processing
-
-
+
+
diff --git a/_modules/pyalfe/image_registration.html b/_modules/pyalfe/image_registration.html
index ea75fd3..735f6f4 100644
--- a/_modules/pyalfe/image_registration.html
+++ b/_modules/pyalfe/image_registration.html
@@ -15,19 +15,21 @@
document.documentElement.dataset.mode = localStorage.getItem("mode") || "";
document.documentElement.dataset.theme = localStorage.getItem("theme") || "";
-
-
-
-
-
+
+
+
+
-
-
-
-
+
+
+
-
+
@@ -35,10 +37,11 @@
+
+
-
-
-
+
+
@@ -61,6 +64,7 @@
+
@@ -76,19 +80,8 @@
Back to top
-
-
-
-
-
-
-
+
+
@@ -123,7 +115,8 @@
-
@@ -360,26 +346,26 @@
Source code for pyalfe.image_registration
-import logging
-import os
-import shutil
-from abc import ABC , abstractmethod
+import logging
+import os
+import shutil
+from abc import ABC , abstractmethod
-from pyalfe.interfaces.greedy import Greedy
+from pyalfe.interfaces.greedy import Greedy
try :
- import ants
+ import ants
except ImportError :
pass
[docs]
-
class ImageRegistration ( ABC ):
+
class ImageRegistration ( ABC ):
[docs]
@abstractmethod
-
def register_rigid ( self , fixed , moving , transform_output , init_transform = None ):
+
def register_rigid ( self , fixed , moving , transform_output , init_transform = None ):
"""Performs rigid registration (translation and rotation).
Parameters
@@ -404,7 +390,7 @@
Source code for pyalfe.image_registration
[docs]
@abstractmethod
-
def register_affine (
+
def register_affine (
self , fixed , moving , transform_output , init_transform , fast = False
):
"""Performs affine registration (scaling, translation, and rotation)
@@ -434,7 +420,7 @@
Source code for pyalfe.image_registration