<s> import sys , commands <EOL> status , path_sct = commands . getstatusoutput ( '<STR_LIT>' ) <EOL> sys . path . append ( path_sct + '<STR_LIT>' ) <EOL> from sct_register_multimodal import Paramreg <EOL> def register_slicereg2d_pointwise ( fname_source , fname_dest , window_length = <NUM_LIT> , paramreg = Paramreg ( step = '<STR_LIT:0>' , type = '<STR_LIT>' , algo = '<STR_LIT>' , metric = '<STR_LIT>' , iter = '<STR_LIT>' , shrink = '<STR_LIT:1>' , smooth = '<STR_LIT:0>' , gradStep = '<STR_LIT>' ) , <EOL> warp_forward_out = '<STR_LIT>' , warp_inverse_out = '<STR_LIT>' , factor = <NUM_LIT:2> , verbose = <NUM_LIT:0> ) : <EOL> """<STR_LIT>""" <EOL> if paramreg . type != '<STR_LIT>' : <EOL> print '<STR_LIT>' <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> else : <EOL> from msct_register_regularized import register_seg , generate_warping_field <EOL> from numpy import asarray <EOL> from msct_smooth import smoothing_window , outliers_detection , outliers_completion <EOL> x_disp , y_disp = register_seg ( fname_source , fname_dest ) <EOL> x_disp_a = asarray ( x_disp ) <EOL> y_disp_a = asarray ( y_disp ) <EOL> mask_x_a = outliers_detection ( x_disp_a , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = verbose ) <EOL> mask_y_a = outliers_detection ( y_disp_a , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = verbose ) <EOL> x_disp_a_no_outliers = outliers_completion ( mask_x_a , verbose = <NUM_LIT:0> ) <EOL> y_disp_a_no_outliers = outliers_completion ( mask_y_a , verbose = <NUM_LIT:0> ) <EOL> x_disp_smooth = smoothing_window ( x_disp_a_no_outliers , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = verbose ) <EOL> y_disp_smooth = smoothing_window ( y_disp_a_no_outliers , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = verbose ) <EOL> generate_warping_field ( fname_dest , x_disp_smooth , y_disp_smooth , fname = warp_forward_out ) <EOL> generate_warping_field ( fname_source , - x_disp_smooth , - y_disp_smooth , fname = warp_inverse_out ) <EOL> def register_slicereg2d_translation ( fname_source , fname_dest , window_length = <NUM_LIT> , paramreg = Paramreg ( step = '<STR_LIT:0>' , type = '<STR_LIT>' , algo = '<STR_LIT>' , metric = '<STR_LIT>' , iter = '<STR_LIT>' , shrink = '<STR_LIT:1>' , smooth = '<STR_LIT:0>' , gradStep = '<STR_LIT>' ) , <EOL> fname_mask = '<STR_LIT>' , warp_forward_out = '<STR_LIT>' , warp_inverse_out = '<STR_LIT>' , factor = <NUM_LIT:2> , remove_temp_files = <NUM_LIT:1> , verbose = <NUM_LIT:0> , <EOL> ants_registration_params = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> """<STR_LIT>""" <EOL> from msct_register_regularized import register_images , generate_warping_field <EOL> from numpy import asarray <EOL> from msct_smooth import smoothing_window , outliers_detection , outliers_completion <EOL> x_disp , y_disp = register_images ( fname_source , fname_dest , mask = fname_mask , paramreg = paramreg , remove_tmp_folder = remove_temp_files , ants_registration_params = ants_registration_params ) <EOL> x_disp_a = asarray ( x_disp ) <EOL> y_disp_a = asarray ( y_disp ) <EOL> mask_x_a = outliers_detection ( x_disp_a , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = verbose ) <EOL> mask_y_a = outliers_detection ( y_disp_a , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = verbose ) <EOL> x_disp_a_no_outliers = outliers_completion ( mask_x_a , verbose = <NUM_LIT:0> ) <EOL> y_disp_a_no_outliers = outliers_completion ( mask_y_a , verbose = <NUM_LIT:0> ) <EOL> x_disp_smooth = smoothing_window ( x_disp_a_no_outliers , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = verbose ) <EOL> y_disp_smooth = smoothing_window ( y_disp_a_no_outliers , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = verbose ) <EOL> generate_warping_field ( fname_dest , x_disp_smooth , y_disp_smooth , fname = warp_forward_out ) <EOL> generate_warping_field ( fname_source , - x_disp_smooth , - y_disp_smooth , fname = warp_inverse_out ) <EOL> def register_slicereg2d_rigid ( fname_source , fname_dest , window_length = <NUM_LIT> , paramreg = Paramreg ( step = '<STR_LIT:0>' , type = '<STR_LIT>' , algo = '<STR_LIT>' , metric = '<STR_LIT>' , iter = '<STR_LIT>' , shrink = '<STR_LIT:1>' , smooth = '<STR_LIT:0>' , gradStep = '<STR_LIT>' ) , <EOL> fname_mask = '<STR_LIT>' , warp_forward_out = '<STR_LIT>' , warp_inverse_out = '<STR_LIT>' , factor = <NUM_LIT:2> , remove_temp_files = <NUM_LIT:1> , verbose = <NUM_LIT:0> , <EOL> ants_registration_params = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> """<STR_LIT>""" <EOL> from msct_register_regularized import register_images , generate_warping_field <EOL> from numpy import asarray <EOL> from msct_smooth import smoothing_window , outliers_detection , outliers_completion <EOL> x_disp , y_disp , theta_rot = register_images ( fname_source , fname_dest , mask = fname_mask , paramreg = paramreg , remove_tmp_folder = remove_temp_files , ants_registration_params = ants_registration_params ) <EOL> x_disp_a = asarray ( x_disp ) <EOL> y_disp_a = asarray ( y_disp ) <EOL> theta_rot_a = asarray ( theta_rot ) <EOL> mask_x_a = outliers_detection ( x_disp_a , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = verbose ) <EOL> mask_y_a = outliers_detection ( y_disp_a , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = verbose ) <EOL> mask_theta_a = outliers_detection ( theta_rot_a , type = '<STR_LIT>' , factor = <NUM_LIT:2> , return_filtered_signal = '<STR_LIT>' , verbose = verbose ) <EOL> x_disp_a_no_outliers = outliers_completion ( mask_x_a , verbose = <NUM_LIT:0> ) <EOL> y_disp_a_no_outliers = outliers_completion ( mask_y_a , verbose = <NUM_LIT:0> ) <EOL> theta_rot_a_no_outliers = outliers_completion ( mask_theta_a , verbose = <NUM_LIT:0> ) <EOL> x_disp_smooth = smoothing_window ( x_disp_a_no_outliers , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = verbose ) <EOL> y_disp_smooth = smoothing_window ( y_disp_a_no_outliers , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = verbose ) <EOL> theta_rot_smooth = smoothing_window ( theta_rot_a_no_outliers , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = verbose ) <EOL> generate_warping_field ( fname_dest , x_disp_smooth , y_disp_smooth , theta_rot_smooth , fname = warp_forward_out ) <EOL> generate_warping_field ( fname_source , - x_disp_smooth , - y_disp_smooth , - theta_rot_smooth , fname = warp_inverse_out ) <EOL> def register_slicereg2d_affine ( fname_source , fname_dest , window_length = <NUM_LIT> , paramreg = Paramreg ( step = '<STR_LIT:0>' , type = '<STR_LIT>' , algo = '<STR_LIT>' , metric = '<STR_LIT>' , iter = '<STR_LIT>' , shrink = '<STR_LIT:1>' , smooth = '<STR_LIT:0>' , gradStep = '<STR_LIT>' ) , <EOL> fname_mask = '<STR_LIT>' , warp_forward_out = '<STR_LIT>' , warp_inverse_out = '<STR_LIT>' , factor = <NUM_LIT:2> , remove_temp_files = <NUM_LIT:1> , verbose = <NUM_LIT:0> , <EOL> ants_registration_params = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> """<STR_LIT>""" <EOL> from nibabel import load , Nifti1Image , save <EOL> from msct_smooth import smoothing_window , outliers_detection , outliers_completion <EOL> from msct_register_regularized import register_images <EOL> from numpy import apply_along_axis , zeros <EOL> import sct_utils as sct <EOL> name_warp_syn = '<STR_LIT>' + str ( paramreg . step ) <EOL> register_images ( fname_source , fname_dest , mask = fname_mask , paramreg = paramreg , remove_tmp_folder = remove_temp_files , ants_registration_params = ants_registration_params ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> sct . run ( '<STR_LIT>' + name_warp_syn + '<STR_LIT>' + name_warp_syn + '<STR_LIT>' + name_warp_syn + '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + name_warp_syn + '<STR_LIT>' + name_warp_syn + '<STR_LIT>' + name_warp_syn + '<STR_LIT>' ) <EOL> data_warp_x = load ( name_warp_syn + '<STR_LIT>' ) . get_data ( ) <EOL> data_warp_y = load ( name_warp_syn + '<STR_LIT>' ) . get_data ( ) <EOL> hdr_warp = load ( name_warp_syn + '<STR_LIT>' ) . get_header ( ) <EOL> data_warp_x_inverse = load ( name_warp_syn + '<STR_LIT>' ) . get_data ( ) <EOL> data_warp_y_inverse = load ( name_warp_syn + '<STR_LIT>' ) . get_data ( ) <EOL> hdr_warp_inverse = load ( name_warp_syn + '<STR_LIT>' ) . get_header ( ) <EOL> print '<STR_LIT>' <EOL> mask_x_a = apply_along_axis ( lambda m : outliers_detection ( m , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_x ) <EOL> mask_y_a = apply_along_axis ( lambda m : outliers_detection ( m , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_y ) <EOL> mask_x_inverse_a = apply_along_axis ( lambda m : outliers_detection ( m , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_x_inverse ) <EOL> mask_y_inverse_a = apply_along_axis ( lambda m : outliers_detection ( m , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_y_inverse ) <EOL> data_warp_x_no_outliers = apply_along_axis ( lambda m : outliers_completion ( m , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = mask_x_a ) <EOL> data_warp_y_no_outliers = apply_along_axis ( lambda m : outliers_completion ( m , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = mask_y_a ) <EOL> data_warp_x_inverse_no_outliers = apply_along_axis ( lambda m : outliers_completion ( m , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = mask_x_inverse_a ) <EOL> data_warp_y_inverse_no_outliers = apply_along_axis ( lambda m : outliers_completion ( m , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = mask_y_inverse_a ) <EOL> print '<STR_LIT>' <EOL> data_warp_x_smooth = apply_along_axis ( lambda m : smoothing_window ( m , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_x_no_outliers ) <EOL> data_warp_x_smooth_inverse = apply_along_axis ( lambda m : smoothing_window ( m , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_x_inverse_no_outliers ) <EOL> data_warp_y_smooth = apply_along_axis ( lambda m : smoothing_window ( m , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_y_no_outliers ) <EOL> data_warp_y_smooth_inverse = apply_along_axis ( lambda m : smoothing_window ( m , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_y_inverse_no_outliers ) <EOL> print '<STR_LIT>' <EOL> '''<STR_LIT>''' <EOL> from msct_image import Image <EOL> nx , ny , nz , nt , px , py , pz , pt = Image ( fname_dest ) . dim <EOL> data_warp_smooth = zeros ( ( ( ( ( nx , ny , nz , <NUM_LIT:1> , <NUM_LIT:3> ) ) ) ) ) <EOL> data_warp_smooth [ : , : , : , <NUM_LIT:0> , <NUM_LIT:0> ] = data_warp_x_smooth <EOL> data_warp_smooth [ : , : , : , <NUM_LIT:0> , <NUM_LIT:1> ] = data_warp_y_smooth <EOL> data_warp_smooth_inverse = zeros ( ( ( ( ( nx , ny , nz , <NUM_LIT:1> , <NUM_LIT:3> ) ) ) ) ) <EOL> data_warp_smooth_inverse [ : , : , : , <NUM_LIT:0> , <NUM_LIT:0> ] = data_warp_x_smooth_inverse <EOL> data_warp_smooth_inverse [ : , : , : , <NUM_LIT:0> , <NUM_LIT:1> ] = data_warp_y_smooth_inverse <EOL> hdr_warp . set_intent ( '<STR_LIT>' , ( ) , '<STR_LIT>' ) <EOL> hdr_warp_inverse . set_intent ( '<STR_LIT>' , ( ) , '<STR_LIT>' ) <EOL> img = Nifti1Image ( data_warp_smooth , None , header = hdr_warp ) <EOL> img_inverse = Nifti1Image ( data_warp_smooth_inverse , None , header = hdr_warp_inverse ) <EOL> save ( img , filename = warp_forward_out ) <EOL> print '<STR_LIT>' + warp_forward_out + '<STR_LIT>' <EOL> save ( img_inverse , filename = warp_inverse_out ) <EOL> print '<STR_LIT>' + warp_inverse_out + '<STR_LIT>' <EOL> def register_slicereg2d_syn ( fname_source , fname_dest , window_length = <NUM_LIT> , paramreg = Paramreg ( step = '<STR_LIT:0>' , type = '<STR_LIT>' , algo = '<STR_LIT>' , metric = '<STR_LIT>' , iter = '<STR_LIT>' , shrink = '<STR_LIT:1>' , smooth = '<STR_LIT:0>' , gradStep = '<STR_LIT>' ) , <EOL> fname_mask = '<STR_LIT>' , warp_forward_out = '<STR_LIT>' , warp_inverse_out = '<STR_LIT>' , factor = <NUM_LIT:2> , remove_temp_files = <NUM_LIT:1> , verbose = <NUM_LIT:0> , <EOL> ants_registration_params = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> """<STR_LIT>""" <EOL> from nibabel import load , Nifti1Image , save <EOL> from msct_smooth import smoothing_window , outliers_detection , outliers_completion <EOL> from msct_register_regularized import register_images <EOL> from numpy import apply_along_axis , zeros <EOL> import sct_utils as sct <EOL> name_warp_syn = '<STR_LIT>' <EOL> register_images ( fname_source , fname_dest , mask = fname_mask , paramreg = paramreg , remove_tmp_folder = remove_temp_files , ants_registration_params = ants_registration_params ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> sct . run ( '<STR_LIT>' + name_warp_syn + '<STR_LIT>' + name_warp_syn + '<STR_LIT>' + name_warp_syn + '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + name_warp_syn + '<STR_LIT>' + name_warp_syn + '<STR_LIT>' + name_warp_syn + '<STR_LIT>' ) <EOL> im_warp_x = Image ( name_warp_syn + '<STR_LIT>' ) <EOL> data_warp_x = im_warp_x . data <EOL> im_warp_y = Image ( name_warp_syn + '<STR_LIT>' ) <EOL> data_warp_y = im_warp_y . data <EOL> hdr_warp = im_warp_x . hdr <EOL> im_warp_x_inverse = Image ( name_warp_syn + '<STR_LIT>' ) <EOL> data_warp_x_inverse = im_warp_x_inverse . data <EOL> im_warp_y_inverse = Image ( name_warp_syn + '<STR_LIT>' ) <EOL> data_warp_y_inverse = im_warp_y_inverse . data <EOL> hdr_warp_inverse = im_warp_x_inverse . hdr <EOL> print '<STR_LIT>' <EOL> mask_x_a = apply_along_axis ( lambda m : outliers_detection ( m , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_x ) <EOL> mask_y_a = apply_along_axis ( lambda m : outliers_detection ( m , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_y ) <EOL> mask_x_inverse_a = apply_along_axis ( lambda m : outliers_detection ( m , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_x_inverse ) <EOL> mask_y_inverse_a = apply_along_axis ( lambda m : outliers_detection ( m , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_y_inverse ) <EOL> data_warp_x_no_outliers = apply_along_axis ( lambda m : outliers_completion ( m , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = mask_x_a ) <EOL> data_warp_y_no_outliers = apply_along_axis ( lambda m : outliers_completion ( m , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = mask_y_a ) <EOL> data_warp_x_inverse_no_outliers = apply_along_axis ( lambda m : outliers_completion ( m , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = mask_x_inverse_a ) <EOL> data_warp_y_inverse_no_outliers = apply_along_axis ( lambda m : outliers_completion ( m , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = mask_y_inverse_a ) <EOL> print '<STR_LIT>' <EOL> data_warp_x_smooth = apply_along_axis ( lambda m : smoothing_window ( m , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_x_no_outliers ) <EOL> data_warp_x_smooth_inverse = apply_along_axis ( lambda m : smoothing_window ( m , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_x_inverse_no_outliers ) <EOL> data_warp_y_smooth = apply_along_axis ( lambda m : smoothing_window ( m , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_y_no_outliers ) <EOL> data_warp_y_smooth_inverse = apply_along_axis ( lambda m : smoothing_window ( m , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_y_inverse_no_outliers ) <EOL> print '<STR_LIT>' <EOL> from msct_image import Image <EOL> nx , ny , nz , nt , px , py , pz , pt = Image ( fname_dest ) . dim <EOL> data_warp_smooth = zeros ( ( ( ( ( nx , ny , nz , <NUM_LIT:1> , <NUM_LIT:3> ) ) ) ) ) <EOL> data_warp_smooth [ : , : , : , <NUM_LIT:0> , <NUM_LIT:0> ] = data_warp_x_smooth <EOL> data_warp_smooth [ : , : , : , <NUM_LIT:0> , <NUM_LIT:1> ] = data_warp_y_smooth <EOL> data_warp_smooth_inverse = zeros ( ( ( ( ( nx , ny , nz , <NUM_LIT:1> , <NUM_LIT:3> ) ) ) ) ) <EOL> data_warp_smooth_inverse [ : , : , : , <NUM_LIT:0> , <NUM_LIT:0> ] = data_warp_x_smooth_inverse <EOL> data_warp_smooth_inverse [ : , : , : , <NUM_LIT:0> , <NUM_LIT:1> ] = data_warp_y_smooth_inverse <EOL> hdr_warp . set_intent ( '<STR_LIT>' , ( ) , '<STR_LIT>' ) <EOL> hdr_warp_inverse . set_intent ( '<STR_LIT>' , ( ) , '<STR_LIT>' ) <EOL> img = Nifti1Image ( data_warp_smooth , None , header = hdr_warp ) <EOL> img_inverse = Nifti1Image ( data_warp_smooth_inverse , None , header = hdr_warp_inverse ) <EOL> save ( img , filename = warp_forward_out ) <EOL> print '<STR_LIT>' + warp_forward_out + '<STR_LIT>' <EOL> save ( img_inverse , filename = warp_inverse_out ) <EOL> print '<STR_LIT>' + warp_inverse_out + '<STR_LIT>' <EOL> def register_slicereg2d_bsplinesyn ( fname_source , fname_dest , window_length = <NUM_LIT> , paramreg = Paramreg ( step = '<STR_LIT:0>' , type = '<STR_LIT>' , algo = '<STR_LIT>' , metric = '<STR_LIT>' , iter = '<STR_LIT>' , shrink = '<STR_LIT:1>' , smooth = '<STR_LIT:0>' , gradStep = '<STR_LIT>' ) , <EOL> fname_mask = '<STR_LIT>' , warp_forward_out = '<STR_LIT>' , warp_inverse_out = '<STR_LIT>' , factor = <NUM_LIT:2> , remove_temp_files = <NUM_LIT:1> , verbose = <NUM_LIT:0> , <EOL> ants_registration_params = { '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' , '<STR_LIT>' : '<STR_LIT>' } ) : <EOL> """<STR_LIT>""" <EOL> from nibabel import load , Nifti1Image , save <EOL> from msct_smooth import smoothing_window , outliers_detection , outliers_completion <EOL> from msct_register_regularized import register_images <EOL> from numpy import apply_along_axis , zeros <EOL> import sct_utils as sct <EOL> from msct_image import Image <EOL> name_warp_syn = '<STR_LIT>' <EOL> register_images ( fname_source , fname_dest , mask = fname_mask , paramreg = paramreg , remove_tmp_folder = remove_temp_files , ants_registration_params = ants_registration_params ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' <EOL> sct . run ( '<STR_LIT>' + name_warp_syn + '<STR_LIT>' + name_warp_syn + '<STR_LIT>' + name_warp_syn + '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + name_warp_syn + '<STR_LIT>' + name_warp_syn + '<STR_LIT>' + name_warp_syn + '<STR_LIT>' ) <EOL> data_warp_x = load ( name_warp_syn + '<STR_LIT>' ) . get_data ( ) <EOL> data_warp_y = load ( name_warp_syn + '<STR_LIT>' ) . get_data ( ) <EOL> hdr_warp = load ( name_warp_syn + '<STR_LIT>' ) . get_header ( ) <EOL> data_warp_x_inverse = load ( name_warp_syn + '<STR_LIT>' ) . get_data ( ) <EOL> data_warp_y_inverse = load ( name_warp_syn + '<STR_LIT>' ) . get_data ( ) <EOL> hdr_warp_inverse = load ( name_warp_syn + '<STR_LIT>' ) . get_header ( ) <EOL> print '<STR_LIT>' <EOL> mask_x_a = apply_along_axis ( lambda m : outliers_detection ( m , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_x ) <EOL> mask_y_a = apply_along_axis ( lambda m : outliers_detection ( m , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_y ) <EOL> mask_x_inverse_a = apply_along_axis ( lambda m : outliers_detection ( m , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_x_inverse ) <EOL> mask_y_inverse_a = apply_along_axis ( lambda m : outliers_detection ( m , type = '<STR_LIT>' , factor = factor , return_filtered_signal = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_y_inverse ) <EOL> data_warp_x_no_outliers = apply_along_axis ( lambda m : outliers_completion ( m , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = mask_x_a ) <EOL> data_warp_y_no_outliers = apply_along_axis ( lambda m : outliers_completion ( m , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = mask_y_a ) <EOL> data_warp_x_inverse_no_outliers = apply_along_axis ( lambda m : outliers_completion ( m , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = mask_x_inverse_a ) <EOL> data_warp_y_inverse_no_outliers = apply_along_axis ( lambda m : outliers_completion ( m , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = mask_y_inverse_a ) <EOL> print '<STR_LIT>' <EOL> data_warp_x_smooth = apply_along_axis ( lambda m : smoothing_window ( m , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_x_no_outliers ) <EOL> data_warp_x_smooth_inverse = apply_along_axis ( lambda m : smoothing_window ( m , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_x_inverse_no_outliers ) <EOL> data_warp_y_smooth = apply_along_axis ( lambda m : smoothing_window ( m , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_y_no_outliers ) <EOL> data_warp_y_smooth_inverse = apply_along_axis ( lambda m : smoothing_window ( m , window_len = int ( window_length ) , window = '<STR_LIT>' , verbose = <NUM_LIT:0> ) , axis = - <NUM_LIT:1> , arr = data_warp_y_inverse_no_outliers ) <EOL> print '<STR_LIT>' <EOL> nx , ny , nz , nt , px , py , pz , pt = Image ( fname_dest ) . dim <EOL> data_warp_smooth = zeros ( ( ( ( ( nx , ny , nz , <NUM_LIT:1> , <NUM_LIT:3> ) ) ) ) ) <EOL> data_warp_smooth [ : , : , : , <NUM_LIT:0> , <NUM_LIT:0> ] = data_warp_x_smooth <EOL> data_warp_smooth [ : , : , : , <NUM_LIT:0> , <NUM_LIT:1> ] = data_warp_y_smooth <EOL> data_warp_smooth_inverse = zeros ( ( ( ( ( nx , ny , nz , <NUM_LIT:1> , <NUM_LIT:3> ) ) ) ) ) <EOL> data_warp_smooth_inverse [ : , : , : , <NUM_LIT:0> , <NUM_LIT:0> ] = data_warp_x_smooth_inverse <EOL> data_warp_smooth_inverse [ : , : , : , <NUM_LIT:0> , <NUM_LIT:1> ] = data_warp_y_smooth_inverse <EOL> hdr_warp . set_intent ( '<STR_LIT>' , ( ) , '<STR_LIT>' ) <EOL> hdr_warp_inverse . set_intent ( '<STR_LIT>' , ( ) , '<STR_LIT>' ) <EOL> img = Nifti1Image ( data_warp_smooth , None , header = hdr_warp ) <EOL> img_inverse = Nifti1Image ( data_warp_smooth_inverse , None , header = hdr_warp_inverse ) <EOL> save ( img , filename = warp_forward_out ) <EOL> print '<STR_LIT>' + warp_forward_out + '<STR_LIT>' <EOL> save ( img_inverse , filename = warp_inverse_out ) <EOL> print '<STR_LIT>' + warp_inverse_out + '<STR_LIT>' </s>
