Skip to content

Commit 706a738

Browse files
committed
Merge branch 'main' of github.com:LOAMRI/asltk
2 parents d7c4c2f + 3360ba8 commit 706a738

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+3763
-1420
lines changed

.github/ISSUE_TEMPLATE/general-improvement.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ about: Propose an improvement for the repo code (e.g. documentation, a module, a
44
testing, etc)
55
title: "[Improvement]"
66
labels: enhancement
7-
assignees: acsenrafilho
87

98
---
109

asltk/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
BIDS_IMAGE_FORMATS = ('.nii', '.nii.gz')
2+
AVAILABLE_IMAGE_FORMATS = ('.nii', '.nii.gz', '.mha', '.nrrd')

asltk/asldata.py

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import numpy as np
44
import SimpleITK as sitk
55

6-
from asltk.utils import load_image, save_image
6+
from asltk.utils import load_image
77

88

99
class ASLData:
@@ -82,13 +82,21 @@ def __init__(
8282
if kwargs.get('dw_values'):
8383
self._parameters['dw'] = kwargs.get('dw_values')
8484

85-
def set_image(self, full_path: str, spec: str):
85+
def set_image(self, image, spec: str):
8686
"""Insert a image necessary to define de ASL data processing.
8787
8888
The `spec` parameters specifies what is the type of image to be used in
8989
ASL processing step. Choose one of the options: `m0` for the M0 volume,
9090
`pcasl` for the pCASL data.
9191
92+
Note:
93+
The image can be a full path to the image file or a numpy array.
94+
In case the image parameter is a path, then the method will load
95+
the image file directly and associate it with the `spec` parameter.
96+
However, if the image is a numpy array, then the method will
97+
pass it to the ASLData object image data regarding the `spec`
98+
parameter as well.
99+
92100
Examples:
93101
>>> data = ASLData()
94102
>>> path_m0 = './tests/files/m0.nii.gz' # M0 file with shape (5,35,35)
@@ -97,13 +105,19 @@ def set_image(self, full_path: str, spec: str):
97105
(5, 35, 35)
98106
99107
Args:
100-
full_path (str): The full path with filename to be loaded
108+
image (str): The image to be used.
101109
spec (str): The type of image being used in the ASL processing.
102110
"""
103-
if spec == 'm0':
104-
self._m0_image = load_image(full_path)
105-
elif spec == 'pcasl':
106-
self._asl_image = load_image(full_path)
111+
if isinstance(image, str) and os.path.exists(image):
112+
if spec == 'm0':
113+
self._m0_image = load_image(image)
114+
elif spec == 'pcasl':
115+
self._asl_image = load_image(image)
116+
elif isinstance(image, np.ndarray):
117+
if spec == 'm0':
118+
self._m0_image = image
119+
elif spec == 'pcasl':
120+
self._asl_image = image
107121

108122
def get_ld(self):
109123
"""Obtain the LD array values"""

asltk/aux_methods.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import warnings
2+
3+
import numpy as np
4+
5+
6+
def _check_mask_values(mask, label, ref_shape):
7+
# Check wheter mask input is an numpy array
8+
if not isinstance(mask, np.ndarray):
9+
raise TypeError(f'mask is not an numpy array. Type {type(mask)}')
10+
11+
# Check whether the mask provided is a binary image
12+
unique_values = np.unique(mask)
13+
if unique_values.size > 2:
14+
warnings.warn(
15+
'Mask image is not a binary image. Any value > 0 will be assumed as brain label.',
16+
UserWarning,
17+
)
18+
19+
# Check whether the label value is found in the mask image
20+
label_ok = False
21+
for value in unique_values:
22+
if label == value:
23+
label_ok = True
24+
break
25+
if not label_ok:
26+
raise ValueError('Label value is not found in the mask provided.')
27+
28+
# Check whether the dimensions between mask and input volume matches
29+
mask_shape = mask.shape
30+
if mask_shape != ref_shape:
31+
raise TypeError(
32+
f'Image mask dimension does not match with input 3D volume. Mask shape {mask_shape} not equal to {ref_shape}'
33+
)

asltk/models/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)