@@ -314,7 +314,7 @@ def smooth_image(img,
314
314
315
315
316
316
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.
318
318
319
319
Parameters
320
320
----------
@@ -335,7 +335,7 @@ def _transform_range(x, new_min, new_max):
335
335
"""
336
336
x = np .asarray (x )
337
337
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
339
339
340
340
341
341
def conform (from_img ,
@@ -347,8 +347,13 @@ def conform(from_img,
347
347
""" Resample image to ``out_shape`` with voxels of size ``voxel_size``.
348
348
349
349
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)
352
357
353
358
Parameters
354
359
----------
@@ -364,10 +369,6 @@ def conform(from_img,
364
369
order : int, optional
365
370
The order of the spline interpolation, default is 3. The order has to
366
371
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``)
371
372
cval : scalar, optional
372
373
Value used for points outside the boundaries of the input if
373
374
``mode='constant'``. Default is 0.0 (see
@@ -382,6 +383,8 @@ def conform(from_img,
382
383
resampling `from_img` into axes aligned to the output space of
383
384
``from_img.affine``
384
385
"""
386
+ if from_img .ndim != 3 :
387
+ raise ValueError ("Only 3D images are supported." )
385
388
# Create fake image of the image we want to resample to.
386
389
hdr = Nifti1Header ()
387
390
hdr .set_data_shape (out_shape )
0 commit comments