@@ -87,8 +87,7 @@ def volume_per_brain_region(input_file, include_labels=[], exclude_labels=[],
87
87
88
88
# Load labeled image volumes:
89
89
img = nb .load (input_file )
90
- hdr = img .get_header ()
91
- volume_per_voxel = np .product (hdr .get_zooms ())
90
+ volume_per_voxel = np .product (img .header .get_zooms ())
92
91
labels = img .get_data ().ravel ()
93
92
94
93
unique_labels , counts = count_per_label (labels , include_labels ,
@@ -370,28 +369,34 @@ def thickinthehead(segmented_file, labeled_file, cortex_value=2,
370
369
# ------------------------------------------------------------------------
371
370
if resize :
372
371
rescale = 2.0
372
+ maxdim = 257
373
373
else :
374
374
rescale = 1.0
375
- compute_real_volume = True
376
- if compute_real_volume :
377
- img = nb .load (cortex )
378
- hdr = img .get_header ()
379
- vv_orig = np .prod (hdr .get_zooms ())
380
- vv = np .prod ([x / rescale for x in hdr .get_zooms ()])
381
- cortex_data = img .get_data ().ravel ()
382
- else :
383
- vv = 1 / rescale
384
- cortex_data = nb .load (cortex ).get_data ().ravel ()
375
+ maxdim = 514
376
+ img = nb .load (cortex )
377
+ dims = img .header .get_data_shape ()
378
+
379
+ if any ([x > maxdim for x in dims ]) and resize :
380
+ raise IOError ("Image dimensions greater than " + str (maxdim ) +
381
+ " voxels, which may be too large for thickinthehead "
382
+ "to resample." )
383
+
384
+ voxdims0 = img .header .get_zooms ()
385
+ voxdims = [x / rescale for x in voxdims0 ]
386
+ voxvol0 = np .prod (voxdims0 )
387
+ voxvol = np .prod (voxdims )
388
+ cortex_data = img .get_data ().ravel ()
385
389
386
390
# ------------------------------------------------------------------------
387
391
# Resample cortex and noncortex files from 1x1x1 to 0.5x0.5x0.5
388
392
# to better represent the contours of the boundaries of the cortex:
389
393
# ------------------------------------------------------------------------
390
394
if resize :
391
- dims = ' ' .join ([str (1 / rescale ), str (1 / rescale ), str (1 / rescale )])
392
- cmd = [ants_resample , '3' , cortex , cortex , dims , '0 0 1' ]
395
+ #voxdims_str = ' '.join([str(1/rescale), str(1/rescale), str(1/rescale)])
396
+ voxdims_str = ' ' .join ([str (x ) for x in voxdims ])
397
+ cmd = [ants_resample , '3' , cortex , cortex , voxdims_str , '0 0 1' ]
393
398
execute (cmd , 'os' )
394
- cmd = [ants_resample , '3' , noncortex , noncortex , dims , '0 0 1' ]
399
+ cmd = [ants_resample , '3' , noncortex , noncortex , voxdims_str , '0 0 1' ]
395
400
execute (cmd , 'os' )
396
401
397
402
# ------------------------------------------------------------------------
@@ -447,12 +452,13 @@ def thickinthehead(segmented_file, labeled_file, cortex_value=2,
447
452
# - Estimate the thickness of the labeled cortical region as the
448
453
# volume of the labeled region divided by the surface area.
449
454
# --------------------------------------------------------------------
450
- label_cortex_volume = vv_orig * len (np .where (cortex_data == label )[0 ])
451
- label_inner_edge_volume = vv * len (np .where (inner_edge_data == label )[0 ])
455
+ label_cortex_volume = voxvol0 * len (np .where (cortex_data == label )[0 ])
456
+ label_inner_edge_volume = voxvol * \
457
+ len (np .where (inner_edge_data == label )[0 ])
452
458
if label_inner_edge_volume :
453
459
if use_outer_edge :
454
460
label_outer_edge_volume = \
455
- vv * len (np .where (outer_edge_data == label )[0 ])
461
+ voxvol * len (np .where (outer_edge_data == label )[0 ])
456
462
label_area = (label_inner_edge_volume +
457
463
label_outer_edge_volume ) / 2.0
458
464
else :
0 commit comments