cBrainMRIPrePro.utils package
Subpackages
Submodules
cBrainMRIPrePro.utils.files module
- cBrainMRIPrePro.utils.files.check_is_nii_exist(input_file_path)[source]
Check if a directory exist.
- Parameters
input_file_path (
str) – string of the path of the nii or nii.gz.- Return type
str- Returns
string if exist, else raise Error.
- cBrainMRIPrePro.utils.files.check_isdir(input_dir)[source]
Check if a directory exist.
- Parameters
input_dir (
str) – string of the path of the input directory.- Return type
str- Returns
string if exist, else raise NotADirectoryError.
- cBrainMRIPrePro.utils.files.load_nifty_volume_as_array(input_path_file)[source]
Load nifty image into numpy array [z,y,x] axis order. The output array shape is like [Depth, Height, Width].
- Parameters
input_path_file (
str) – input path file, should be ‘.nii’ or ‘.nii.gz’- Return type
Tuple[ndarray,Tuple[Tuple,Tuple,Tuple]]- Returns
a numpy data array, (with header)
- cBrainMRIPrePro.utils.files.safe_file_name(file_name)[source]
Remove any potentially dangerous or confusing characters from the file name by mapping them to reasonable substitutes.
- Parameters
file_name (
str) – name of the file.- Return type
str- Returns
name of the file corrected.
- cBrainMRIPrePro.utils.files.save_to_nii(im, header, output_dir, filename, mode='image', gzip=True)[source]
Save numpy array to nii.gz format to submit.
- Parameters
im (
ndarray) – array numpyheader ((
tuple,tuple,tuple)) – header metadata (origin, spacing, direction).output_dir (
str) – Output directory.filename (
str) – Filename of the output file.mode (
str) – save as ‘image’ or ‘label’gzip (
bool) – zip nii (ie, nii.gz)
- Return type
None
cBrainMRIPrePro.utils.image_processing module
- cBrainMRIPrePro.utils.image_processing.fill_mask(mask_arr)[source]
Fill a 3D mask array. Useful when use a threshold function and need to fill hole
- Parameters
mask_arr (
ndarray) – mask to fill- Return type
ndarray- Returns
mask filled
- cBrainMRIPrePro.utils.image_processing.get_mask(input_array)[source]
Get a (head) mask. Based on Otsu threshold and noise reduced. Then result mask is holes filled.
- Parameters
input_array (
ndarray) – input image array- Return type
ndarray- Returns
binary head mask
- cBrainMRIPrePro.utils.image_processing.invert_min_max_scaling(input_array_scaled, scale_, min_)[source]
Invert min max scaling
- Parameters
input_array_scaled (
ndarray) – input image array scaledscale – Per pixels/voxels relative scaling of the data.
min – Per pixels/voxels minimum seen in the data
- Return type
ndarray- Returns
input image array unscaled
- cBrainMRIPrePro.utils.image_processing.min_max_scaling(input_array, scaling_range=(10, 100))[source]
Transform image input pixels/voxels to a given range. (type min-max scaler)
- Parameters
input_array (
ndarray) – input image arrayscaling_range (
Tuple[int,int]) – min, max = feature_range
- Return type
Tuple[ndarray,float,float]- Returns
image_scaled, min, scale
- cBrainMRIPrePro.utils.image_processing.zscore_normalize(input_array, scaling_factor=1, mask=None)[source]
Function to normalize array with Z-Score. Normalize a target image by subtracting the mean of the whole brain and dividing by the standard deviation.
- Parameters
input_array (
Union[ndarray,str]) – input array image to normalizescaling_factor (
int) – scaling factor to apply to normalizationmask (
Union[ndarray,str,None]) – input mask where to apply the normalization. If not provided default will be in non zero value
- Return type
ndarray- Returns
input array normalize