<s> import sys <EOL> import os <EOL> import commands <EOL> import time <EOL> from glob import glob <EOL> import sct_utils as sct <EOL> from sct_utils import add_suffix <EOL> from sct_image import set_orientation <EOL> from sct_register_multimodal import Paramreg , ParamregMultiStep , register <EOL> from msct_parser import Parser <EOL> from msct_image import Image , find_zmin_zmax <EOL> from shutil import move <EOL> from sct_label_utils import ProcessLabels <EOL> status , path_sct = commands . getstatusoutput ( '<STR_LIT>' ) <EOL> class Param : <EOL> def __init__ ( self ) : <EOL> self . debug = <NUM_LIT:0> <EOL> self . remove_temp_files = <NUM_LIT:1> <EOL> self . output_type = <NUM_LIT:1> <EOL> self . fname_mask = '<STR_LIT>' <EOL> self . padding = <NUM_LIT:10> <EOL> self . verbose = <NUM_LIT:1> <EOL> self . folder_template = '<STR_LIT>' <EOL> self . path_template = path_sct + '<STR_LIT>' <EOL> self . file_template_label = '<STR_LIT>' <EOL> self . zsubsample = '<STR_LIT>' <EOL> self . param_straighten = '<STR_LIT>' <EOL> step1 = Paramreg ( step = '<STR_LIT:1>' , type = '<STR_LIT>' , algo = '<STR_LIT>' , metric = '<STR_LIT>' , slicewise = '<STR_LIT:1>' , smooth = '<STR_LIT:5>' ) <EOL> step2 = Paramreg ( step = '<STR_LIT:2>' , type = '<STR_LIT>' , algo = '<STR_LIT>' , metric = '<STR_LIT>' , iter = '<STR_LIT:5>' , smooth = '<STR_LIT:1>' ) <EOL> step3 = Paramreg ( step = '<STR_LIT:3>' , type = '<STR_LIT>' , algo = '<STR_LIT>' , metric = '<STR_LIT>' , iter = '<STR_LIT:3>' ) <EOL> paramreg = ParamregMultiStep ( [ step1 , step2 , step3 ] ) <EOL> def get_parser ( ) : <EOL> param = Param ( ) <EOL> parser = Parser ( __file__ ) <EOL> parser . usage . set_description ( '<STR_LIT>' ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT:file>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = True , <EOL> example = "<STR_LIT>" ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT:file>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = True , <EOL> example = "<STR_LIT>" ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT:file>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = True , <EOL> default_value = '<STR_LIT>' , <EOL> example = "<STR_LIT>" ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = False , <EOL> default_value = '<STR_LIT>' ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT>" , <EOL> description = "<STR_LIT>" , <EOL> mandatory = False , <EOL> default_value = param . path_template ) <EOL> parser . add_option ( name = '<STR_LIT:-c>' , <EOL> type_value = '<STR_LIT>' , <EOL> description = '<STR_LIT>' , <EOL> mandatory = False , <EOL> default_value = '<STR_LIT>' , <EOL> example = [ '<STR_LIT>' , '<STR_LIT>' ] ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = [ [ '<STR_LIT::>' ] , '<STR_LIT:str>' ] , <EOL> description = '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . type + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . algo + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . metric + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . iter + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . smooth + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . gradStep + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . slicewise + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:2>' ] . type + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:2>' ] . algo + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:2>' ] . metric + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:2>' ] . iter + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:2>' ] . smooth + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:2>' ] . gradStep + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:3>' ] . type + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:3>' ] . algo + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:3>' ] . metric + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:3>' ] . iter + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:3>' ] . smooth + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:3>' ] . gradStep + '<STR_LIT:\n>' , <EOL> mandatory = False , <EOL> example = "<STR_LIT>" ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = None , <EOL> description = '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . type + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . algo + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . metric + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . iter + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . smooth + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . gradStep + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:1>' ] . slicewise + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:2>' ] . type + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:2>' ] . algo + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:2>' ] . metric + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:2>' ] . iter + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:2>' ] . smooth + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:2>' ] . gradStep + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:2>' ] . slicewise + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:3>' ] . type + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:3>' ] . algo + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:3>' ] . metric + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:3>' ] . iter + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:3>' ] . smooth + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:3>' ] . gradStep + '<STR_LIT>' + paramreg . steps [ '<STR_LIT:3>' ] . slicewise + '<STR_LIT:\n>' , <EOL> mandatory = False , <EOL> deprecated_by = '<STR_LIT>' ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = '<STR_LIT:str>' , <EOL> description = """<STR_LIT>""" , <EOL> mandatory = False , <EOL> default_value = '<STR_LIT>' , <EOL> example = "<STR_LIT>" ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT>" , <EOL> description = """<STR_LIT>""" , <EOL> mandatory = False , <EOL> default_value = '<STR_LIT:1>' , <EOL> example = [ '<STR_LIT:0>' , '<STR_LIT:1>' ] ) <EOL> parser . add_option ( name = "<STR_LIT>" , <EOL> type_value = "<STR_LIT>" , <EOL> description = """<STR_LIT>""" , <EOL> mandatory = False , <EOL> default_value = param . verbose , <EOL> example = [ '<STR_LIT:0>' , '<STR_LIT:1>' , '<STR_LIT:2>' ] ) <EOL> return parser <EOL> def main ( ) : <EOL> parser = get_parser ( ) <EOL> param = Param ( ) <EOL> arguments = parser . parse ( sys . argv [ <NUM_LIT:1> : ] ) <EOL> fname_data = arguments [ '<STR_LIT>' ] <EOL> fname_seg = arguments [ '<STR_LIT>' ] <EOL> fname_landmarks = arguments [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in arguments : <EOL> path_output = arguments [ '<STR_LIT>' ] <EOL> else : <EOL> path_output = '<STR_LIT>' <EOL> path_template = sct . slash_at_the_end ( arguments [ '<STR_LIT>' ] , <NUM_LIT:1> ) <EOL> contrast_template = arguments [ '<STR_LIT:-c>' ] <EOL> remove_temp_files = int ( arguments [ '<STR_LIT>' ] ) <EOL> verbose = int ( arguments [ '<STR_LIT>' ] ) <EOL> if '<STR_LIT>' in arguments : <EOL> param . param_straighten = arguments [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' in arguments : <EOL> paramreg_user = arguments [ '<STR_LIT>' ] <EOL> for paramStep in paramreg_user : <EOL> paramreg . addStep ( paramStep ) <EOL> file_template_label = param . file_template_label <EOL> output_type = param . output_type <EOL> zsubsample = param . zsubsample <EOL> if contrast_template == '<STR_LIT>' : <EOL> contrast_template = '<STR_LIT>' <EOL> elif contrast_template == '<STR_LIT>' : <EOL> contrast_template = '<STR_LIT>' <EOL> fname_template_list = glob ( path_template + param . folder_template + '<STR_LIT:*>' + contrast_template + '<STR_LIT>' ) <EOL> fname_template = fname_template_list [ <NUM_LIT:0> ] <EOL> fname_template_seg_list = glob ( path_template + param . folder_template + '<STR_LIT>' ) <EOL> fname_template_seg = fname_template_seg_list [ <NUM_LIT:0> ] <EOL> start_time = time . time ( ) <EOL> path_template = os . path . abspath ( path_template + param . folder_template ) <EOL> fname_template_label = sct . slash_at_the_end ( path_template , <NUM_LIT:1> ) + file_template_label <EOL> sct . printv ( '<STR_LIT>' ) <EOL> sct . check_file_exist ( fname_template , verbose ) <EOL> sct . check_file_exist ( fname_template_label , verbose ) <EOL> sct . check_file_exist ( fname_template_seg , verbose ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . printv ( '<STR_LIT>' + fname_data , verbose ) <EOL> sct . printv ( '<STR_LIT>' + fname_landmarks , verbose ) <EOL> sct . printv ( '<STR_LIT>' + fname_seg , verbose ) <EOL> sct . printv ( '<STR_LIT>' + path_template , verbose ) <EOL> sct . printv ( '<STR_LIT>' + path_output , verbose ) <EOL> sct . printv ( '<STR_LIT>' + str ( output_type ) , verbose ) <EOL> sct . printv ( '<STR_LIT>' + str ( remove_temp_files ) , verbose ) <EOL> sct . printv ( '<STR_LIT>' ) <EOL> for pStep in range ( <NUM_LIT:1> , len ( paramreg . steps ) + <NUM_LIT:1> ) : <EOL> sct . printv ( '<STR_LIT>' + paramreg . steps [ str ( pStep ) ] . step , verbose ) <EOL> sct . printv ( '<STR_LIT>' + paramreg . steps [ str ( pStep ) ] . type , verbose ) <EOL> sct . printv ( '<STR_LIT>' + paramreg . steps [ str ( pStep ) ] . algo , verbose ) <EOL> sct . printv ( '<STR_LIT>' + paramreg . steps [ str ( pStep ) ] . metric , verbose ) <EOL> sct . printv ( '<STR_LIT>' + paramreg . steps [ str ( pStep ) ] . iter , verbose ) <EOL> sct . printv ( '<STR_LIT>' + paramreg . steps [ str ( pStep ) ] . shrink , verbose ) <EOL> sct . printv ( '<STR_LIT>' + paramreg . steps [ str ( pStep ) ] . smooth , verbose ) <EOL> sct . printv ( '<STR_LIT>' + paramreg . steps [ str ( pStep ) ] . gradStep , verbose ) <EOL> sct . printv ( '<STR_LIT>' + paramreg . steps [ str ( pStep ) ] . poly , verbose ) <EOL> path_data , file_data , ext_data = sct . extract_fname ( fname_data ) <EOL> sct . printv ( '<STR_LIT>' ) <EOL> if not sct . check_if_same_space ( fname_data , fname_seg ) : <EOL> sct . printv ( '<STR_LIT>' , verbose , '<STR_LIT:error>' ) <EOL> if not sct . check_if_same_space ( fname_data , fname_landmarks ) : <EOL> sct . printv ( '<STR_LIT>' , verbose , '<STR_LIT:error>' ) <EOL> sct . printv ( '<STR_LIT>' ) <EOL> image_label = Image ( fname_landmarks ) <EOL> labels = image_label . getNonZeroCoordinates ( sorting = '<STR_LIT:value>' ) <EOL> hasDifferentLabels = True <EOL> for lab in labels : <EOL> for otherlabel in labels : <EOL> if lab != otherlabel and lab . hasEqualValue ( otherlabel ) : <EOL> hasDifferentLabels = False <EOL> break <EOL> if not hasDifferentLabels : <EOL> sct . printv ( '<STR_LIT>' , verbose , '<STR_LIT:error>' ) <EOL> image_label_template = Image ( fname_template_label ) <EOL> labels_template = image_label_template . getNonZeroCoordinates ( sorting = '<STR_LIT:value>' ) <EOL> if labels [ - <NUM_LIT:1> ] . value > labels_template [ - <NUM_LIT:1> ] . value : <EOL> sct . printv ( '<STR_LIT>' <EOL> '<STR_LIT>' + str ( labels [ - <NUM_LIT:1> ] . value ) + '<STR_LIT>' + <EOL> str ( labels_template [ - <NUM_LIT:1> ] . value ) , verbose , '<STR_LIT:error>' ) <EOL> path_tmp = sct . tmp_create ( verbose = verbose ) <EOL> ftmp_data = '<STR_LIT>' <EOL> ftmp_seg = '<STR_LIT>' <EOL> ftmp_label = '<STR_LIT>' <EOL> ftmp_template = '<STR_LIT>' <EOL> ftmp_template_seg = '<STR_LIT>' <EOL> ftmp_template_label = '<STR_LIT>' <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + fname_data + '<STR_LIT>' + path_tmp + ftmp_data ) <EOL> sct . run ( '<STR_LIT>' + fname_seg + '<STR_LIT>' + path_tmp + ftmp_seg ) <EOL> sct . run ( '<STR_LIT>' + fname_landmarks + '<STR_LIT>' + path_tmp + ftmp_label ) <EOL> sct . run ( '<STR_LIT>' + fname_template + '<STR_LIT>' + path_tmp + ftmp_template ) <EOL> sct . run ( '<STR_LIT>' + fname_template_seg + '<STR_LIT>' + path_tmp + ftmp_template_seg ) <EOL> sct . run ( '<STR_LIT>' + fname_template_label + '<STR_LIT>' + path_tmp + ftmp_template_label ) <EOL> os . chdir ( path_tmp ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + ftmp_seg + '<STR_LIT>' + add_suffix ( ftmp_seg , '<STR_LIT>' ) ) <EOL> ftmp_seg = add_suffix ( ftmp_seg , '<STR_LIT>' ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + ftmp_data + '<STR_LIT>' + add_suffix ( ftmp_data , '<STR_LIT>' ) ) <EOL> ftmp_data = add_suffix ( ftmp_data , '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + ftmp_seg + '<STR_LIT>' + add_suffix ( ftmp_seg , '<STR_LIT>' ) ) <EOL> ftmp_seg = add_suffix ( ftmp_seg , '<STR_LIT>' ) <EOL> resample_labels ( ftmp_label , ftmp_data , add_suffix ( ftmp_label , '<STR_LIT>' ) ) <EOL> ftmp_label = add_suffix ( ftmp_label , '<STR_LIT>' ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + ftmp_data + '<STR_LIT>' + add_suffix ( ftmp_data , '<STR_LIT>' ) ) <EOL> ftmp_data = add_suffix ( ftmp_data , '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + ftmp_seg + '<STR_LIT>' + add_suffix ( ftmp_seg , '<STR_LIT>' ) ) <EOL> ftmp_seg = add_suffix ( ftmp_seg , '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + ftmp_label + '<STR_LIT>' + add_suffix ( ftmp_label , '<STR_LIT>' ) ) <EOL> ftmp_label = add_suffix ( ftmp_label , '<STR_LIT>' ) <EOL> status_crop , output_crop = sct . run ( '<STR_LIT>' + ftmp_seg + '<STR_LIT>' + add_suffix ( ftmp_seg , '<STR_LIT>' ) + '<STR_LIT>' , verbose ) <EOL> ftmp_seg = add_suffix ( ftmp_seg , '<STR_LIT>' ) <EOL> cropping_slices = output_crop . split ( '<STR_LIT>' ) [ <NUM_LIT:1> ] . split ( '<STR_LIT:\n>' ) [ <NUM_LIT:0> ] . split ( '<STR_LIT:U+0020>' ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + ftmp_seg + '<STR_LIT>' + ftmp_seg + '<STR_LIT>' + add_suffix ( ftmp_seg , '<STR_LIT>' ) + '<STR_LIT>' + str ( verbose ) , verbose ) <EOL> sct . run ( '<STR_LIT>' + ftmp_data + '<STR_LIT>' ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + ftmp_template_label + '<STR_LIT>' + ftmp_template_label + '<STR_LIT>' + ftmp_label ) <EOL> sct . printv ( '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + ftmp_label + '<STR_LIT>' + add_suffix ( ftmp_label , '<STR_LIT>' ) + '<STR_LIT>' ) <EOL> ftmp_label = add_suffix ( ftmp_label , '<STR_LIT>' ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + ftmp_label + '<STR_LIT>' + add_suffix ( ftmp_label , '<STR_LIT>' ) + '<STR_LIT>' + add_suffix ( ftmp_seg , '<STR_LIT>' ) + '<STR_LIT>' ) <EOL> ftmp_label = add_suffix ( ftmp_label , '<STR_LIT>' ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> template_image = Image ( ftmp_template_label ) <EOL> coordinates_input = template_image . getNonZeroCoordinates ( sorting = '<STR_LIT:value>' ) <EOL> landmark_template = coordinates_input <EOL> if verbose == <NUM_LIT:2> : <EOL> template_image . setFileName ( add_suffix ( ftmp_template_label , '<STR_LIT>' ) ) <EOL> template_image . save ( type = '<STR_LIT>' ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> label_straight_image = Image ( ftmp_label ) <EOL> coordinates_input = label_straight_image . getCoordinatesAveragedByValue ( ) <EOL> landmark_straight = coordinates_input <EOL> if verbose == <NUM_LIT:2> : <EOL> label_straight_image . setFileName ( add_suffix ( ftmp_label , '<STR_LIT>' ) ) <EOL> label_straight_image . save ( type = '<STR_LIT>' ) <EOL> points_fixed , points_moving = [ ] , [ ] <EOL> for coord in landmark_straight : <EOL> point_straight = label_straight_image . transfo_pix2phys ( [ [ coord . x , coord . y , coord . z ] ] ) <EOL> points_moving . append ( [ point_straight [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , point_straight [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , point_straight [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] ] ) <EOL> for coord in landmark_template : <EOL> point_template = template_image . transfo_pix2phys ( [ [ coord . x , coord . y , coord . z ] ] ) <EOL> points_fixed . append ( [ point_template [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] , point_template [ <NUM_LIT:0> ] [ <NUM_LIT:1> ] , point_template [ <NUM_LIT:0> ] [ <NUM_LIT:2> ] ] ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> import msct_register_landmarks <EOL> if verbose == <NUM_LIT:2> : <EOL> show_transfo = True <EOL> else : <EOL> show_transfo = False <EOL> ( rotation_matrix , translation_array , points_moving_reg , points_moving_barycenter ) = msct_register_landmarks . getRigidTransformFromLandmarks ( points_moving , points_fixed , constraints = '<STR_LIT>' , show = show_transfo ) <EOL> text_file = open ( "<STR_LIT>" , "<STR_LIT:w>" ) <EOL> text_file . write ( "<STR_LIT>" ) <EOL> text_file . write ( "<STR_LIT>" ) <EOL> text_file . write ( "<STR_LIT>" ) <EOL> text_file . write ( "<STR_LIT>" % ( <EOL> rotation_matrix [ <NUM_LIT:0> , <NUM_LIT:0> ] , rotation_matrix [ <NUM_LIT:0> , <NUM_LIT:1> ] , rotation_matrix [ <NUM_LIT:0> , <NUM_LIT:2> ] , <EOL> rotation_matrix [ <NUM_LIT:1> , <NUM_LIT:0> ] , rotation_matrix [ <NUM_LIT:1> , <NUM_LIT:1> ] , rotation_matrix [ <NUM_LIT:1> , <NUM_LIT:2> ] , <EOL> rotation_matrix [ <NUM_LIT:2> , <NUM_LIT:0> ] , rotation_matrix [ <NUM_LIT:2> , <NUM_LIT:1> ] , rotation_matrix [ <NUM_LIT:2> , <NUM_LIT:2> ] , <EOL> - translation_array [ <NUM_LIT:0> , <NUM_LIT:0> ] , - translation_array [ <NUM_LIT:0> , <NUM_LIT:1> ] , translation_array [ <NUM_LIT:0> , <NUM_LIT:2> ] ) ) <EOL> text_file . write ( "<STR_LIT>" % ( - points_moving_barycenter [ <NUM_LIT:0> ] , <EOL> - points_moving_barycenter [ <NUM_LIT:1> ] , <EOL> points_moving_barycenter [ <NUM_LIT:2> ] ) ) <EOL> text_file . close ( ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + ftmp_data + '<STR_LIT>' + add_suffix ( ftmp_data , '<STR_LIT>' ) + '<STR_LIT>' + ftmp_template + '<STR_LIT>' ) <EOL> ftmp_data = add_suffix ( ftmp_data , '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + ftmp_seg + '<STR_LIT>' + add_suffix ( ftmp_seg , '<STR_LIT>' ) + '<STR_LIT>' + ftmp_template + '<STR_LIT>' ) <EOL> ftmp_seg = add_suffix ( ftmp_seg , '<STR_LIT>' ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + ftmp_seg + '<STR_LIT>' + add_suffix ( ftmp_seg , '<STR_LIT>' ) ) <EOL> sct . run ( '<STR_LIT>' + add_suffix ( ftmp_seg , '<STR_LIT>' ) + '<STR_LIT>' + add_suffix ( ftmp_seg , '<STR_LIT>' ) ) <EOL> ftmp_seg = add_suffix ( ftmp_seg , '<STR_LIT>' ) <EOL> zmin_template , zmax_template = find_zmin_zmax ( ftmp_seg ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + ftmp_template + '<STR_LIT>' + add_suffix ( ftmp_template , '<STR_LIT>' ) + '<STR_LIT>' + str ( zmin_template ) + '<STR_LIT>' + str ( zmax_template ) ) <EOL> ftmp_template = add_suffix ( ftmp_template , '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + ftmp_template_seg + '<STR_LIT>' + add_suffix ( ftmp_template_seg , '<STR_LIT>' ) + '<STR_LIT>' + str ( zmin_template ) + '<STR_LIT>' + str ( zmax_template ) ) <EOL> ftmp_template_seg = add_suffix ( ftmp_template_seg , '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + ftmp_data + '<STR_LIT>' + add_suffix ( ftmp_data , '<STR_LIT>' ) + '<STR_LIT>' + str ( zmin_template ) + '<STR_LIT>' + str ( zmax_template ) ) <EOL> ftmp_data = add_suffix ( ftmp_data , '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + ftmp_seg + '<STR_LIT>' + add_suffix ( ftmp_seg , '<STR_LIT>' ) + '<STR_LIT>' + str ( zmin_template ) + '<STR_LIT>' + str ( zmax_template ) ) <EOL> ftmp_seg = add_suffix ( ftmp_seg , '<STR_LIT>' ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + ftmp_template + '<STR_LIT>' + add_suffix ( ftmp_template , '<STR_LIT>' ) + '<STR_LIT>' + zsubsample , verbose ) <EOL> ftmp_template = add_suffix ( ftmp_template , '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + ftmp_template_seg + '<STR_LIT>' + add_suffix ( ftmp_template_seg , '<STR_LIT>' ) + '<STR_LIT>' + zsubsample , verbose ) <EOL> ftmp_template_seg = add_suffix ( ftmp_template_seg , '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + ftmp_data + '<STR_LIT>' + add_suffix ( ftmp_data , '<STR_LIT>' ) + '<STR_LIT>' + zsubsample , verbose ) <EOL> ftmp_data = add_suffix ( ftmp_data , '<STR_LIT>' ) <EOL> sct . run ( '<STR_LIT>' + ftmp_seg + '<STR_LIT>' + add_suffix ( ftmp_seg , '<STR_LIT>' ) + '<STR_LIT>' + zsubsample , verbose ) <EOL> ftmp_seg = add_suffix ( ftmp_seg , '<STR_LIT>' ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> warp_forward = [ ] <EOL> warp_inverse = [ ] <EOL> for i_step in range ( <NUM_LIT:1> , len ( paramreg . steps ) + <NUM_LIT:1> ) : <EOL> sct . printv ( '<STR_LIT>' + str ( i_step ) + '<STR_LIT>' , verbose ) <EOL> if paramreg . steps [ str ( i_step ) ] . type == '<STR_LIT>' : <EOL> src = ftmp_data <EOL> dest = ftmp_template <EOL> interp_step = '<STR_LIT>' <EOL> elif paramreg . steps [ str ( i_step ) ] . type == '<STR_LIT>' : <EOL> src = ftmp_seg <EOL> dest = ftmp_template_seg <EOL> interp_step = '<STR_LIT>' <EOL> else : <EOL> sct . printv ( '<STR_LIT>' , <NUM_LIT:1> , '<STR_LIT:error>' ) <EOL> if i_step > <NUM_LIT:1> : <EOL> sct . run ( '<STR_LIT>' + src + '<STR_LIT>' + dest + '<STR_LIT>' + '<STR_LIT:U+002C>' . join ( warp_forward ) + '<STR_LIT>' + add_suffix ( src , '<STR_LIT>' ) + '<STR_LIT>' + interp_step , verbose ) <EOL> src = add_suffix ( src , '<STR_LIT>' ) <EOL> warp_forward_out , warp_inverse_out = register ( src , dest , paramreg , param , str ( i_step ) ) <EOL> warp_forward . append ( warp_forward_out ) <EOL> warp_inverse . append ( warp_inverse_out ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + '<STR_LIT:U+002C>' . join ( warp_forward ) + '<STR_LIT>' , verbose ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> warp_inverse . reverse ( ) <EOL> sct . run ( '<STR_LIT>' + '<STR_LIT:U+002C>' . join ( warp_inverse ) + '<STR_LIT>' , verbose ) <EOL> if output_type == <NUM_LIT:1> : <EOL> sct . run ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' , verbose ) <EOL> os . chdir ( '<STR_LIT:..>' ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . generate_output_file ( path_tmp + '<STR_LIT>' , path_output + '<STR_LIT>' , verbose ) <EOL> sct . generate_output_file ( path_tmp + '<STR_LIT>' , path_output + '<STR_LIT>' , verbose ) <EOL> if output_type == <NUM_LIT:1> : <EOL> sct . generate_output_file ( path_tmp + '<STR_LIT>' , path_output + '<STR_LIT>' + ext_data , verbose ) <EOL> sct . generate_output_file ( path_tmp + '<STR_LIT>' , path_output + '<STR_LIT>' + ext_data , verbose ) <EOL> if remove_temp_files : <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . run ( '<STR_LIT>' + path_tmp ) <EOL> elapsed_time = time . time ( ) - start_time <EOL> sct . printv ( '<STR_LIT>' + str ( int ( round ( elapsed_time ) ) ) + '<STR_LIT:s>' , verbose ) <EOL> sct . printv ( '<STR_LIT>' , verbose ) <EOL> sct . printv ( '<STR_LIT>' + fname_data + '<STR_LIT:U+0020>' + path_output + '<STR_LIT>' , verbose , '<STR_LIT:info>' ) <EOL> sct . printv ( '<STR_LIT>' + fname_template + '<STR_LIT>' + path_output + '<STR_LIT>' , verbose , '<STR_LIT:info>' ) <EOL> def resample_labels ( fname_labels , fname_dest , fname_output ) : <EOL> """<STR_LIT>""" <EOL> nx , ny , nz , nt , px , py , pz , pt = Image ( fname_labels ) . dim <EOL> nxd , nyd , nzd , ntd , pxd , pyd , pzd , ptd = Image ( fname_dest ) . dim <EOL> sampling_factor = [ float ( nx ) / nxd , float ( ny ) / nyd , float ( nz ) / nzd ] <EOL> from sct_label_utils import ProcessLabels <EOL> processor = ProcessLabels ( fname_labels ) <EOL> label_list = processor . display_voxel ( ) <EOL> label_new_list = [ ] <EOL> for label in label_list : <EOL> label_sub_new = [ str ( int ( round ( int ( label . x ) / sampling_factor [ <NUM_LIT:0> ] ) ) ) , <EOL> str ( int ( round ( int ( label . y ) / sampling_factor [ <NUM_LIT:1> ] ) ) ) , <EOL> str ( int ( round ( int ( label . z ) / sampling_factor [ <NUM_LIT:2> ] ) ) ) , <EOL> str ( int ( float ( label . value ) ) ) ] <EOL> label_new_list . append ( '<STR_LIT:U+002C>' . join ( label_sub_new ) ) <EOL> label_new_list = '<STR_LIT::>' . join ( label_new_list ) <EOL> sct . run ( '<STR_LIT>' + fname_dest + '<STR_LIT>' + label_new_list + '<STR_LIT>' + fname_output ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> main ( ) </s>
