<s> class param : <EOL> def __init__ ( self ) : <EOL> self . verbose = <NUM_LIT:1> <EOL> self . gapxy = <NUM_LIT> <EOL> self . cross = '<STR_LIT>' <EOL> import sys , commands <EOL> import getopt <EOL> status , path_sct = commands . getstatusoutput ( '<STR_LIT>' ) <EOL> sys . path . append ( path_sct + '<STR_LIT>' ) <EOL> import sct_utils as sct <EOL> import nibabel <EOL> import os <EOL> def main ( ) : <EOL> fname = '<STR_LIT>' <EOL> fname_template = '<STR_LIT>' <EOL> verbose = param . verbose <EOL> gapxy = param . gapxy <EOL> cross = param . cross <EOL> x = '<STR_LIT>' <EOL> y = '<STR_LIT>' <EOL> zmin = '<STR_LIT>' <EOL> zmax = '<STR_LIT>' <EOL> try : <EOL> opts , args = getopt . getopt ( sys . argv [ <NUM_LIT:1> : ] , '<STR_LIT>' ) <EOL> except getopt . GetoptError : <EOL> usage ( ) <EOL> for opt , arg in opts : <EOL> if opt == '<STR_LIT>' : <EOL> usage ( ) <EOL> elif opt in ( "<STR_LIT>" ) : <EOL> fname = arg <EOL> elif opt in ( '<STR_LIT>' ) : <EOL> x = int ( arg ) <EOL> elif opt in ( '<STR_LIT>' ) : <EOL> y = int ( arg ) <EOL> elif opt in ( '<STR_LIT>' ) : <EOL> zmin = int ( arg ) <EOL> elif opt in ( '<STR_LIT>' ) : <EOL> zmax = int ( arg ) <EOL> elif opt in ( '<STR_LIT:-c>' ) : <EOL> cross = arg <EOL> elif opt in ( "<STR_LIT>" ) : <EOL> fname_template = arg <EOL> elif opt in ( '<STR_LIT>' ) : <EOL> verbose = int ( arg ) <EOL> if fname == '<STR_LIT>' and fname_template == '<STR_LIT>' : <EOL> usage ( ) <EOL> print '<STR_LIT>' <EOL> if fname != '<STR_LIT>' : <EOL> sct . check_file_exist ( fname ) <EOL> if fname_template != '<STR_LIT>' : <EOL> sct . check_file_exist ( fname_template ) <EOL> if cross not in [ '<STR_LIT>' , '<STR_LIT>' ] : <EOL> usage ( ) <EOL> print '<STR_LIT>' <EOL> print '<STR_LIT>' + fname <EOL> print '<STR_LIT>' + fname_template <EOL> print '<STR_LIT>' + str ( verbose ) <EOL> if fname != '<STR_LIT>' : <EOL> print '<STR_LIT>' <EOL> from msct_image import Image <EOL> nx , ny , nz , nt , px , py , pz , pt = Image ( fname ) . dim <EOL> print '<STR_LIT>' + str ( nx ) + '<STR_LIT>' + str ( ny ) + '<STR_LIT>' + str ( nz ) <EOL> print '<STR_LIT>' + str ( px ) + '<STR_LIT>' + str ( py ) + '<STR_LIT>' + str ( pz ) + '<STR_LIT>' <EOL> file = nibabel . load ( fname ) <EOL> data = file . get_data ( ) <EOL> hdr = file . get_header ( ) <EOL> data = data * <NUM_LIT:0> <EOL> list_opts = [ ] <EOL> for i in range ( len ( opts ) ) : <EOL> list_opts . append ( opts [ i ] [ <NUM_LIT:0> ] ) <EOL> if cross == '<STR_LIT>' : <EOL> gapx = int ( round ( gapxy / px ) ) <EOL> gapy = int ( round ( gapxy / py ) ) <EOL> if ( "<STR_LIT>" ) in list_opts and ( "<STR_LIT>" ) in list_opts and zmax < nz : <EOL> data [ x , y , zmin ] = <NUM_LIT:1> <EOL> data [ x , y , zmax ] = <NUM_LIT:2> <EOL> data [ x + gapx , y , zmax ] = <NUM_LIT:3> <EOL> data [ x - gapx , y , zmax ] = <NUM_LIT:4> <EOL> data [ x , y + gapy , zmax ] = <NUM_LIT:5> <EOL> data [ x , y - gapy , zmax ] = <NUM_LIT:6> <EOL> else : <EOL> data [ x , y , <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> data [ x , y , nz - <NUM_LIT:1> ] = <NUM_LIT:2> <EOL> data [ x + gapx , y , nz - <NUM_LIT:1> ] = <NUM_LIT:3> <EOL> data [ x - gapx , y , nz - <NUM_LIT:1> ] = <NUM_LIT:4> <EOL> data [ x , y + gapy , nz - <NUM_LIT:1> ] = <NUM_LIT:5> <EOL> data [ x , y - gapy , nz - <NUM_LIT:1> ] = <NUM_LIT:6> <EOL> if cross == '<STR_LIT>' : <EOL> gapxy = int ( gapxy ) <EOL> if ( "<STR_LIT>" ) in list_opts and ( "<STR_LIT>" ) in list_opts and zmax < nz : <EOL> data [ x , y , zmin ] = <NUM_LIT:1> <EOL> data [ x , y , zmax ] = <NUM_LIT:2> <EOL> data [ x + gapx , y , zmax ] = <NUM_LIT:3> <EOL> data [ x - gapx , y , zmax ] = <NUM_LIT:4> <EOL> data [ x , y + gapy , zmax ] = <NUM_LIT:5> <EOL> data [ x , y - gapy , zmax ] = <NUM_LIT:6> <EOL> else : <EOL> data [ x , y , <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> data [ x , y , nz - <NUM_LIT:1> ] = <NUM_LIT:2> <EOL> data [ x + gapx , y , nz - <NUM_LIT:1> ] = <NUM_LIT:3> <EOL> data [ x - gapx , y , nz - <NUM_LIT:1> ] = <NUM_LIT:4> <EOL> data [ x , y + gapy , nz - <NUM_LIT:1> ] = <NUM_LIT:5> <EOL> data [ x , y - gapy , nz - <NUM_LIT:1> ] = <NUM_LIT:6> <EOL> print '<STR_LIT>' <EOL> hdr . set_data_dtype ( '<STR_LIT>' ) <EOL> img = nibabel . Nifti1Image ( data , None , hdr ) <EOL> file_name = '<STR_LIT>' <EOL> nibabel . save ( img , file_name ) <EOL> print '<STR_LIT>' + file_name <EOL> if fname_template != '<STR_LIT>' : <EOL> print '<STR_LIT>' <EOL> nx , ny , nz , nt , px , py , pz , pt = Image ( fname_template ) . dim <EOL> print '<STR_LIT>' + str ( nx ) + '<STR_LIT>' + str ( ny ) + '<STR_LIT>' + str ( nz ) <EOL> print '<STR_LIT>' + str ( px ) + '<STR_LIT>' + str ( py ) + '<STR_LIT>' + str ( pz ) + '<STR_LIT>' <EOL> file_t = nibabel . load ( fname_template ) <EOL> data_t = file_t . get_data ( ) <EOL> hdr_t = file_t . get_header ( ) <EOL> data_t = data_t * <NUM_LIT:0> <EOL> if cross == '<STR_LIT>' : <EOL> gapx = int ( round ( gapxy / px ) ) <EOL> gapy = int ( round ( gapxy / py ) ) <EOL> if ( "<STR_LIT>" ) in list_opts and ( "<STR_LIT>" ) in list_opts and zmax < nz : <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) , zmin ] = <NUM_LIT:1> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) , zmax ] = <NUM_LIT:2> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) + gapx , int ( round ( ny / <NUM_LIT> ) ) , zmax ] = <NUM_LIT:3> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) - gapx , int ( round ( ny / <NUM_LIT> ) ) , zmax ] = <NUM_LIT:4> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) + gapy , zmax ] = <NUM_LIT:5> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) - gapy , zmax ] = <NUM_LIT:6> <EOL> else : <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) , <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) , nz - <NUM_LIT:1> ] = <NUM_LIT:2> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) + gapx , int ( round ( ny / <NUM_LIT> ) ) , nz - <NUM_LIT:1> ] = <NUM_LIT:3> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) - gapx , int ( round ( ny / <NUM_LIT> ) ) , nz - <NUM_LIT:1> ] = <NUM_LIT:4> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) + gapy , nz - <NUM_LIT:1> ] = <NUM_LIT:5> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) - gapy , nz - <NUM_LIT:1> ] = <NUM_LIT:6> <EOL> if cross == '<STR_LIT>' : <EOL> gapxy = int ( gapxy ) <EOL> if ( "<STR_LIT>" ) in list_opts and ( "<STR_LIT>" ) in list_opts and zmax < nz : <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) , zmin ] = <NUM_LIT:1> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) , zmax ] = <NUM_LIT:2> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) + gapxy , int ( round ( ny / <NUM_LIT> ) ) , zmax ] = <NUM_LIT:3> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) - gapxy , int ( round ( ny / <NUM_LIT> ) ) , zmax ] = <NUM_LIT:4> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) + gapxy , zmax ] = <NUM_LIT:5> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) - gapxy , zmax ] = <NUM_LIT:6> <EOL> else : <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) , <NUM_LIT:0> ] = <NUM_LIT:1> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) , nz - <NUM_LIT:1> ] = <NUM_LIT:2> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) + gapxy , int ( round ( ny / <NUM_LIT> ) ) , nz - <NUM_LIT:1> ] = <NUM_LIT:3> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) - gapxy , int ( round ( ny / <NUM_LIT> ) ) , nz - <NUM_LIT:1> ] = <NUM_LIT:4> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) + gapxy , nz - <NUM_LIT:1> ] = <NUM_LIT:5> <EOL> data_t [ int ( round ( nx / <NUM_LIT> ) ) , int ( round ( ny / <NUM_LIT> ) ) - gapxy , nz - <NUM_LIT:1> ] = <NUM_LIT:6> <EOL> print '<STR_LIT>' <EOL> hdr_t . set_data_dtype ( '<STR_LIT>' ) <EOL> img_t = nibabel . Nifti1Image ( data_t , None , hdr_t ) <EOL> file_name_t = '<STR_LIT>' <EOL> nibabel . save ( img_t , file_name_t ) <EOL> print '<STR_LIT>' + file_name_t <EOL> def usage ( ) : <EOL> print """<STR_LIT:U+0020>""" + os . path . basename ( __file__ ) + """<STR_LIT>""" + os . path . basename ( __file__ ) + """<STR_LIT>""" + str ( param . verbose ) + """<STR_LIT>""" + param . cross + """<STR_LIT>""" + os . path . basename ( __file__ ) + """<STR_LIT>""" <EOL> sys . exit ( <NUM_LIT:2> ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> param = param ( ) <EOL> main ( ) </s>
