Skip to content

Commit 49e4ada

Browse files
author
Jakub Kaczmarzyk
committed
clean up documentation + only conform 3D
1 parent 9895eb0 commit 49e4ada

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

nibabel/processing.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ def smooth_image(img,
314314

315315

316316
def _transform_range(x, new_min, new_max):
317-
"""Transform data to a new range, while maintaining ratios.
317+
""" Transform data to a new range, while maintaining ratios.
318318
319319
Parameters
320320
----------
@@ -335,7 +335,7 @@ def _transform_range(x, new_min, new_max):
335335
"""
336336
x = np.asarray(x)
337337
x_min, x_max = x.min(), x.max()
338-
return (((x - x_min) * (new_max - new_min)) / (x_max - x_min)) + new_min
338+
return (x - x_min) * (new_max - new_min) / (x_max - x_min) + new_min
339339

340340

341341
def conform(from_img,
@@ -347,8 +347,13 @@ def conform(from_img,
347347
""" Resample image to ``out_shape`` with voxels of size ``voxel_size``.
348348
349349
Using the default arguments, this function is meant to replicate most parts
350-
of FreeSurfer's ``mri_convert --conform`` command. The output image is also
351-
reoriented to RAS.
350+
of FreeSurfer's ``mri_convert --conform`` command. Specifically, this
351+
function:
352+
- Resamples data to ``output_shape``
353+
- Resamples voxel sizes to ``voxel_size``
354+
- Transforms data to range [0, 255] (while maintaining ratios)
355+
- Casts to unsigned eight-bit integer
356+
- Reorients to RAS (``mri_convert --conform`` reorients to LIA)
352357
353358
Parameters
354359
----------
@@ -364,10 +369,6 @@ def conform(from_img,
364369
order : int, optional
365370
The order of the spline interpolation, default is 3. The order has to
366371
be in the range 0-5 (see ``scipy.ndimage.affine_transform``)
367-
mode : str, optional
368-
Points outside the boundaries of the input are filled according
369-
to the given mode ('constant', 'nearest', 'reflect' or 'wrap').
370-
Default is 'constant' (see ``scipy.ndimage.affine_transform``)
371372
cval : scalar, optional
372373
Value used for points outside the boundaries of the input if
373374
``mode='constant'``. Default is 0.0 (see
@@ -382,6 +383,8 @@ def conform(from_img,
382383
resampling `from_img` into axes aligned to the output space of
383384
``from_img.affine``
384385
"""
386+
if from_img.ndim != 3:
387+
raise ValueError("Only 3D images are supported.")
385388
# Create fake image of the image we want to resample to.
386389
hdr = Nifti1Header()
387390
hdr.set_data_shape(out_shape)

0 commit comments

Comments
 (0)