Skip to content

Commit 6805e7d

Browse files
committed
Updated README
Added series parameter doc. in read_img and other stuff
1 parent 28ebf14 commit 6805e7d

File tree

1 file changed

+32
-18
lines changed

1 file changed

+32
-18
lines changed

README.md

Lines changed: 32 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ https://badge.fury.io/py/medio)
88

99
**Medical images I/O python package**
1010

11-
This package unifies the io engines of itk, nibabel, and pydicom (and dicom-numpy) packages in a
12-
simple and comprehensive interface.
11+
This package unifies the io engines of itk, nibabel, and pydicom (including dicom-numpy) packages
12+
in a simple and comprehensive interface.
1313

1414
It includes conversion between the metadata conventions, reorientations, affine matrix computation
1515
for itk and pydicom and saving dicom series or file.
@@ -57,7 +57,8 @@ channels_axis=-1, coord_sys='itk', **kwargs)`
5757
- `input_path`: *path-like*<br>
5858
Path for the data to be read (str or pathlib.Path object for example). It can be a file or a
5959
folder (in the case of a dicom series). It is the only required parameter.
60-
If the input path is a folder, it should contain a single dicom series.
60+
If the input path is a folder, it should contain a single dicom series.
61+
If there is more than a single series, the optional parameter `series` can help.
6162
- Returns: *array, metadata*<br>
6263
array of type *numpy.ndarray* and metadata of type *medio.MetaData*. The first is a numpy array
6364
of the image, and the second is a metadata object of the image (see [MetaData](#metadata) class
@@ -97,27 +98,37 @@ Optional parameters:
9798
`itk.ctype('unsigned short') == itk.US`
9899
- `fallback_only=True`: *bool*<br>
99100
If True, the pixel type is automatically found and if failed then `pixel_type` is used
100-
(`pixel_type` must be not None in this case).<br>
101+
(`pixel_type` must not be None in this case).<br>
101102
Note: if `itk.imread(input_path)` fails, using `fallback_only=True` will result in a slightly
102-
inferior performance. If you know what is pixel-type of the image, you can set it with
103-
`pixel_type` and use `fallback_only=False`.
103+
inferior performance. If you know what is pixel-type of the image beforehand, you can set it
104+
with `pixel_type` and use `fallback_only=False`.
105+
- `series=None`: *str, int or None*<br>
106+
If `input_path` is a directory that contains multiple dicom series, selecting a specific one is
107+
possible with the `series` argument. It can be the exact series instance UID (str), an int
108+
between 0 and n-1, where n is the number of series in the directory, or None.<br>
109+
If `series` is None and there are multiple series in the directory, a detailed error message
110+
is raised.
104111

105112
- 'pydicom' backend
106113
- `globber='*'`: *str*<br>
107-
Relevant for a directory - glob pattern for selecting the series files (all files by default).
114+
Relevant for a directory - glob pattern for selecting the series files (all the files in the
115+
directory by default).
108116
- `allow_default_affine=False`: *bool*<br>
109-
Relevant for multiframe dicom file - if True and the dicom miss some physical tags for the
117+
Relevant for a multiframe dicom file - if True and the dicom misses some physical tags for the
110118
affine calculation, use a default affine value.
119+
- `series=None`: *str, int or None*<br>
120+
The counterpart of `series` in itk backend, see the explanation above.
111121

112122
### save_img
113123
`medio.save_img(filename, np_image, metadata, use_original_ornt=True, backend=None, dtype=None,
114124
channels_axis=None, mkdir=False, parents=False, **kwargs)`
115125
- `filename`: *path-like*<br>
116-
The file to be saved.
126+
The file to be saved, including the format suffix.
117127
- `np_image`: *numpy.ndarray*<br>
118128
The image array.
119129
- `metadata`: *medio.MetaData*<br>
120-
The corresponding metadata.
130+
The corresponding metadata, from `medio.read_img` for example. In the absence of a known
131+
metadata, a default one can be constructed with `medio.MetaData(np.eye(4))`.
121132

122133
Optional parameters:
123134
- `use_original_ornt`: *bool*<br>
@@ -137,7 +148,7 @@ Optional parameters:
137148
'itk' backend optional parameters (`**kwargs`):
138149
- `allow_dcm_reorient=False`: *bool*<br>
139150
When saving a dicom file ('.dcm' or '.dicom' suffix) the image orientation should be right-handed.
140-
If it is left-handed, the image can be reoriented to a right-handed orientation with setting this
151+
If it is left-handed, the image can be reoriented to a right-handed orientation by setting this
141152
parameter to True, which flips the last axis direction.
142153
- `compression=False`: *bool*<br>
143154
Whether to use compression in itk writer. Using a '.nii.gz' suffix in `filename` also compresses
@@ -151,16 +162,18 @@ Save a 3d numpy array `np_image` as a dicom series of 2d slices in the directory
151162
backend).
152163

153164
- `dirname`: *path-like*<br>
154-
The directory to save the files in (str or pathlib.Path). If it exists - must be empty.
165+
The directory to save the files in (str or pathlib.Path). If it exists, it must be empty (unless
166+
`exist_ok` is True).
155167

156168
The other parameters: `np_image`, `metadata`, `use_original_ornt`, `dtype`, `channels_axis`,
157-
`parents` and `allow_dcm_reorient` are equivalent to those used in [save_img](#save_img).
169+
`parents` and `allow_dcm_reorient` are equivalent to those of [save_img](#save_img).
158170

159171
Additional optional parameters (`**kwargs`):
160172
- `exist_ok`: *bool*<br>
161173
If True, non-empty existing directory will not raise an error.
162174
- `pattern='IM{}.dcm'`: *str*<br>
163175
Pattern for the filenames to save, including a placeholder ('`{}`') for the slice number.
176+
For example, one can use: `pattern={:03d}`.
164177
- `metadata_dict=None`: *dict or None*<br>
165178
Dictionary of metadata for adding tags or overriding the default values. For example,
166179
`metadata_dict={'0008|0060': 'US'}` will override the default 'CT' modality and set it to 'US'
@@ -206,16 +219,16 @@ A MetaData object 'metadata' is mainly comprised of:
206219
- `metadata.coord_sys`: coordinate system ('itk' or 'nib')
207220
- `metadata.orig_ornt`: the original orientation of the image (used for saving)
208221
- `metadata.header`: a dictionary that includes additional metadata properties when `header=True`
209-
in `read_img`
222+
in `read_img`, otherwise None
210223

211224
Other properties of the metadata are derived from the affine:
212225
- `metadata.spacing`: voxels spacing (a reference to `metadata.affine.spacing`)
213-
- `metadata.ornt`: the current image orientation (also depends on the coordinate system)
226+
- `metadata.ornt`: the current image orientation (depends on the coordinate system `coord_sys`)
214227

215228
All these properties can be viewed easily in the console:
216229
```python
217230
>>> import medio
218-
>>> array, metadata = medio.read_img('avg152T1_LR_nifti.nii.gz')
231+
>>> array, metadata = medio.read_img('avg152T1_LR_nifti.nii.gz', header=False)
219232
>>> print(metadata)
220233
Affine:
221234
[[ -2. 0. 0. 90.]
@@ -246,8 +259,9 @@ For example, 'RAS' orientation in itk:
246259
'RAS' in nib - also 'RAS+':
247260
- Left to **R**ight, Posterior to **A**nterior, Inferior to **S**uperior
248261

249-
Note that the conventions are opposite. For stability reasons, we use itk convention
250-
by default for `read_img`'s argument `desired_ornt`.
262+
Note that the conventions are opposite. For stability reasons, we use itk convention by default
263+
for `read_img`'s argument `desired_ornt`, although one can choose otherwise with the parameter
264+
`coord_sys`.
251265

252266
For further discussion see
253267
[NiBabel's image orientation documentation](

0 commit comments

Comments
 (0)