@@ -401,10 +401,11 @@ def volume_per_label(labels, input_file):
401
401
402
402
return volumes .tolist (), labels
403
403
404
- def normalize_by_neighborhood (scalars , indices , neighbor_lists , nedges = 10 , p = 99 ):
404
+ def rescale_by_neighborhood (scalars , indices , neighbor_lists , nedges = 10 , p = 99 ,
405
+ set_max_to_1 = True ):
405
406
"""
406
- Normalize the scalar values of a VTK file by a percentile value in each
407
- vertex's surface mesh neighborhood.
407
+ Rescale the scalar values of a VTK file by a percentile value
408
+ in each vertex's surface mesh neighborhood.
408
409
409
410
Parameters
410
411
----------
@@ -418,18 +419,20 @@ def normalize_by_neighborhood(scalars, indices, neighbor_lists, nedges=10, p=99)
418
419
number or edges from vertex, defining the size of its neighborhood
419
420
p : float in range of [0,100]
420
421
percentile used to normalize each scalar
422
+ set_max_to_1 : Boolean
423
+ set all rescaled values greater than 1 to 1.0?
421
424
422
425
Returns
423
426
-------
424
- normalized_scalars : list of floats
425
- normalized scalar values
427
+ rescaled_scalars : list of floats
428
+ rescaled scalar values
426
429
427
430
Examples
428
431
--------
429
432
>>> import os
430
433
>>> from mindboggle.utils.io_vtk import read_scalars
431
434
>>> from mindboggle.utils.mesh import find_neighbors_from_file
432
- >>> from mindboggle.shapes.measure import normalize_by_neighborhood
435
+ >>> from mindboggle.shapes.measure import rescale_by_neighborhood
433
436
>>> path = os.environ['MINDBOGGLE_DATA']
434
437
>>> vtk_file = os.path.join(path, 'arno', 'measures', 'lh.pial.depth.vtk')
435
438
>>> scalars, name = read_scalars(vtk_file, return_first=True, return_array=True)
@@ -439,16 +442,17 @@ def normalize_by_neighborhood(scalars, indices, neighbor_lists, nedges=10, p=99)
439
442
>>> neighbor_lists = find_neighbors_from_file(vtk_file)
440
443
>>> nedges = 10
441
444
>>> p = 99
445
+ >>> set_max_to_1 = True
442
446
>>> #
443
- >>> normalized_scalars = normalize_by_neighborhood (scalars, indices,
447
+ >>> rescaled_scalars = rescale_by_neighborhood (scalars, indices,
444
448
>>> neighbor_lists, nedges, p)
445
449
>>> #
446
- >>> # View normalized scalar values on folds:
450
+ >>> # View rescaled scalar values on folds:
447
451
>>> from mindboggle.utils.io_vtk import rewrite_scalars
448
452
>>> from mindboggle.utils.mesh import plot_vtk
449
- >>> rewrite_scalars(vtk_file, 'test_normalize_by_neighborhood .vtk',
450
- >>> normalized_scalars , 'normalized_scalars ', subfolds)
451
- >>> plot_vtk('test_normalize_by_neighborhood .vtk')
453
+ >>> rewrite_scalars(vtk_file, 'test_rescale_by_neighborhood .vtk',
454
+ >>> rescaled_scalars , 'rescaled_scalars ', subfolds)
455
+ >>> plot_vtk('test_rescale_by_neighborhood .vtk')
452
456
453
457
"""
454
458
import numpy as np
@@ -459,7 +463,7 @@ def normalize_by_neighborhood(scalars, indices, neighbor_lists, nedges=10, p=99)
459
463
scalars = np .asarray (scalars )
460
464
461
465
# Loop through all vertices:
462
- normalized_scalars = - 1 * np .ones (len (scalars ))
466
+ rescaled_scalars = - 1 * np .ones (len (scalars ))
463
467
for index in indices :
464
468
print ('{0} of {1})' .format (index , len (indices )))
465
469
@@ -468,12 +472,13 @@ def normalize_by_neighborhood(scalars, indices, neighbor_lists, nedges=10, p=99)
468
472
469
473
# Compute a high neighborhood percentile to normalize the vertex's value:
470
474
normalization_factor = np .percentile (scalars [neighborhood ], p )
471
- normalized_scalar = scalars [index ] / normalization_factor
472
- normalized_scalars [index ] = normalized_scalar
475
+ rescaled_scalar = scalars [index ] / normalization_factor
476
+ rescaled_scalars [index ] = rescaled_scalar
473
477
474
- # Make any normalized value greater than 1 equal to 1:
475
- for index in indices :
476
- if normalized_scalars [index ] > 1 :
477
- normalized_scalars [index ] = 1.0
478
+ # Make any rescaled value greater than 1 equal to 1:
479
+ if set_max_to_1 :
480
+ for index in indices :
481
+ if rescaled_scalars [index ] > 1 :
482
+ rescaled_scalars [index ] = 1.0
478
483
479
- return normalized_scalars .tolist ()
484
+ return rescaled_scalars .tolist ()
0 commit comments