def main(): ## Initial print print("\n") print("##########################################################") print("############# HIERARCHICAL BACKPROJECTION #############") 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 sinogram sinofile = pathin + args.sino sino = io.readImage(sinofile) nang, npix = sino.shape print("\nSinogram to reconstruct:\n", sinofile) print("Number of projection angles: ", nang) print("Number of pixels: ", npix) ## Display sinogram if args.plot is True: dis.plot(sino, "Input sinogram") ## Getting projection geometry if args.geometry == "0": print("\nDealing with equiangular projections distributed between 0 and" + " 180 degrees ---> [0,180)") angles = np.arange(nang).astype(myfloat) angles[:] = (angles * 180.0) / myfloat(nang) else: geometryfile = pathin + args.geometry print("\nReading list of projection angles: ", geometryfile) angles = np.fromfile(geometryfile, sep="\t") if args.plot is True: print("\nProjection angles:\n", angles) ## Enable edge padding if args.edge_pad is True: sino = proc.edgePadding(sino, 0.5) i1 = int((sino.shape[1] - npix) * 0.5) i2 = i1 + npix npix = sino.shape[1] if args.plot is True: dis.plot(sino, "Edge padded sinogram") ## Set center of rotation axis if args.ctr == -1: ctr = proc.searchCtrRot(sino, None, "a") elif args.ctr == 0: ctr = 0.5 * npix else: ctr = args.ctr sino[:, :] = proc.sinoRotAxisCorrect(sino, ctr) print("Center of rotation axis placed at pixel: ", ctr) print("Center of rotation correction done! ") if args.edge_pad is True and ctr != 0.0: ctr += i1 ## External sinogram filtering filt = args.filt if filt not in filt_list: print( "\nERROR: filter named: ', filt,' does not exist!\n \ Use one of the following available filters:\n \ 'none' , 'ramp' , 'shlo' , 'hann' , 'hamm' , \n \ 'parz' , 'lancz' " ) print("\nSelected filter: ", filt) if filt == "none": filter_name = "none" elif filt == "ramp": filter_name = "ramp" elif filt == "hann": filter_name = "hanning" elif filt == "hamm": filter_name = "hamming" sino = fil.filter_fft(sino, filter_name, 0) sino *= 4.0 / myfloat(npix) if args.plot is True: dis.plot(sino, "Filtered sinogram") ## Set number of pixels of the reconstructed image if args.npix_im is None: npix_im = npix else: npix_im = args.npix_im 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 image pixels: ", npix_im) print("Base size: ", base_size) print("Downsampling size: ", down_size) print("Ratio sinogram / image sampling: ", args.sampl_ratio) param = np.array([npix_im, base_size, down_size, args.sampl_ratio]) ## Reconstruction with regridding method time_rec1 = time.time() reco = fhbp.backproj(sino.astype(myfloat), angles.astype(myfloat), param.astype(myfloat)) time_rec2 = time.time() ## Crop reconstruction if args.edge_pad: reco = reco[i1:i2, i1:i2] ## Rotate and flip reconstruction reco[:, :] = reco[:, ::-1] ## Display reconstruction if args.plot is True: dis.plot(reco, "Reconstruction") ## Save reconstruction write_reconstruction(reco, pathin, args) ## Time elapsed and memory usage for the reconstruction time2 = time.time() print("\nTime elapsed for the back-projection: ", time_rec2 - time_rec1, " s") print("Total time elapsed: ", time2 - time1, " s") print("\n") print("########################################") print("#### FHBP BACKPROJECTION DONE ! ####") print("########################################") print("\n")