<s> import nibabel as nib <EOL> import splines_approximation_v2 as splinapp <EOL> from scipy import ndimage <EOL> import sct_utils as sct <EOL> import matplotlib . pyplot as plt <EOL> import sys <EOL> import numpy as np <EOL> def main ( fname ) : <EOL> list_sigma = [ <NUM_LIT:0.5> , <NUM_LIT:5> , <NUM_LIT:10> , <NUM_LIT:15> , <NUM_LIT:20> ] <EOL> for sigma in list_sigma : <EOL> fname_smooth = smooth ( fname , sigma ) <EOL> file = nib . load ( fname_smooth ) <EOL> data = file . get_data ( ) <EOL> nx , ny , nz = splinapp . getDim ( fname_smooth ) <EOL> x = [ <NUM_LIT:0> for iz in range ( <NUM_LIT:0> , nz , <NUM_LIT:1> ) ] <EOL> y = [ <NUM_LIT:0> for iz in range ( <NUM_LIT:0> , nz , <NUM_LIT:1> ) ] <EOL> z = [ iz for iz in range ( <NUM_LIT:0> , nz , <NUM_LIT:1> ) ] <EOL> for iz in range ( <NUM_LIT:0> , nz , <NUM_LIT:1> ) : <EOL> x [ iz ] , y [ iz ] = ndimage . measurements . center_of_mass ( np . array ( data [ : , : , iz ] ) ) <EOL> ax = plt . subplot ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:1> ) <EOL> if sigma == <NUM_LIT:0.5> or sigma == <NUM_LIT:20> : <EOL> plt . plot ( x , z , '<STR_LIT>' , label = '<STR_LIT>' + str ( sigma ) ) <EOL> ax = plt . subplot ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> plt . plot ( y , z , '<STR_LIT>' , label = '<STR_LIT>' + str ( sigma ) ) <EOL> plt . xlabel ( '<STR_LIT:z>' ) <EOL> plt . ylabel ( '<STR_LIT:x>' ) <EOL> else : <EOL> plt . plot ( x , z , '<STR_LIT>' , label = '<STR_LIT>' + str ( sigma ) ) <EOL> ax = plt . subplot ( <NUM_LIT:1> , <NUM_LIT:2> , <NUM_LIT:2> ) <EOL> plt . plot ( y , z , '<STR_LIT>' , label = '<STR_LIT>' + str ( sigma ) ) <EOL> plt . xlabel ( '<STR_LIT:z>' ) <EOL> plt . ylabel ( '<STR_LIT:y>' ) <EOL> plt . show ( ) <EOL> def smooth ( fname , sigma ) : <EOL> path , fname , ext_fname = sct . extract_fname ( fname ) <EOL> print '<STR_LIT>' <EOL> fname_smooth = fname + '<STR_LIT>' <EOL> print '<STR_LIT>' , smooth <EOL> cmd = '<STR_LIT>' + fname + '<STR_LIT>' + str ( sigma ) + '<STR_LIT:U+0020>' + fname_smooth + ext_fname <EOL> sct . run ( cmd ) <EOL> return fname_smooth + ext_fname <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> file_name = sys . argv [ <NUM_LIT:1> ] <EOL> print file_name <EOL> main ( file_name ) </s>
