def select_volume(filename, which):
 from nibabel import load
 import numpy as np
 if (which.lower() == u'first'):
  idx = 0
 elif (which.lower() == u'middle'):
  idx = int(np.ceil((load(filename).shape[3] / 2)))
 else:
  raise Exception((u'unknown value for volume selection : %s' % which))
 return idx

def select_volume ( filename , which ) : from nibabel import load import numpy as np if ( which . lower ( ) == u'first' ) : idx = 0 elif ( which . lower ( ) == u'middle' ) : idx = int ( np . ceil ( ( load ( filename ) . shape [ 3 ] / 2 ) ) ) else : raise Exception ( ( u'unknown value for volume selection : %s' % which ) ) return idx
return the middle index of a file .