def main(): ## Initial print print('\n') print('############################################################') print('############# FORWARD HIERACHICAL PROJECTOR #############') print('############################################################') print('\n') ## Get the startimg time of the reconstruction time1 = time.time() ## Get input arguments args = getArgs() ## Get input directory pathin = args.pathin if pathin[len(pathin)-1] != '/': pathin += '/' if os.path.exists( pathin ) is False: sys.exit('\nERROR: input directory ', pathin,' does not exist!') print('\nInput directory:\n', pathin) ## Get input image and number of views imgfile = args.image image = io.readImage( pathin + imgfile ) npix = image.shape[0] print('\nSinogram to reconstruct:\n', imgfile) print('Number of pixels: ', npix) ## Display image if args.plot is True: dis.plot( image , 'Input image' ) ## Get projection angle range if args.geometry == '0' or args.geometry == '1': if args.angle_range.find( ':' ) == -1: angle_start = myfloat( args.angle_range ) angle_end = angle_start + 180.0 else: angle_aux = args.angle_range.find( ':' ) angle_start = myfloat( angle_aux[0] ) angle_end = myfloat( angle_aux[1] ) print( '\nSelected angle range: [ ', angle_start,' , ', angle_end,' ]' ) ## Get projection geometry print( 'args.geometry = ', args.geometry) if args.geometry == '0': nang = args.nang print('\nDealing with equiangular projections distributed between 0 and' +' 180 degrees ---> [0,180)') angles = create_equally_spaced_angles( nang , angle_start , angle_end ) elif args.geometry == '1': nang = args.nang angles = create_pseudo_polar_angles( nang ) * 180.0 / np.pi print('\nDealing with equally sloped projections in [0,180)') else: geometryfile = pathin + args.geometry print('\nReading list of projection angles: ', geometryfile) angles = np.fromfile( geometryfile , sep="\t" ) nang = len( angles ) print('Number of projection angles: ', nang) if args.plot is True: print('\nProjection angles:\n', angles) ## Pad image to reach number of required sinogram pixels if args.npix_s is not None: npix_s = args.npix_s else: npix_s = npix if args.base_size == 0: base_size = npix else: base_size = args.base_size if args.down_size == 0: down_size = npix else: down_size = args.down_size ## Set parameters print( '\nFHBP parameter setting:' ) print( 'Number sinogram pixels: ' , npix_s ) print( 'Base size: ' , base_size ) print( 'Downsampling size: ' , down_size ) print( 'Ratio sinogram / image sampling: ' , args.sampl_ratio ) param = np.array( [ npix_s , base_size , down_size , args.sampl_ratio ] ) ## Apply forward projection operator time_rec1 = time.time() sino = fhbp.forwproj( image.astype( myfloat ) , angles.astype( myfloat ) , param.astype( myfloat ) ) time_rec2 = time.time() ## Crop sinogram if args.crop is True and npix_s > npix: print( 'Sinogram cropping enabled') i1 = int( 0.5 * ( npix_s - npix ) ) i2 = i1 + npix sino = sino[::-1,i1:i2] ## Display sinogram if args.plot is True: dis.plot( sino , 'Sinogram' ) ## Save sinogram write_sinogram( sino , pathin , angles , args ) ## Time elapsed to run the code time2 = time.time() print('\nTime elapsed to run the forward gridrec: ', time_rec2-time_rec1) print('Total time elapsed for the run of the program: ', time2-time1) print('\n') print('#######################################') print('#### FORWARD PROJECTION DONE ! ####') print('#######################################') print('\n')