def choix_fichier(self): # L'utilisateur choisi le dossier dans lequel se trouve les fichiers path = QtWidgets.QFileDialog.getExistingDirectory( self, "Open a folder", os.sep.join( (os.path.expanduser('~'), 'Desktop' )), #Permet d'afficher le bureau à l'ouverture de la fenêtre options=QtWidgets.QFileDialog.ShowDirsOnly) #Gestion de l'exception dans le cas où l'utilisateur choisit un mauvais dossier #Si aucun dossier n'est sélectionné path = 0 et il ne se passe rien if path: try: MatrixGeneration(path + '/*.tif') except IndexError: return tomopy.project(tomopy.shepp3d(), tomopy.angles(180))
def choix_fichier(self): factor = float(str(self.selectFactor.currentText())) # L'utilisateur choisi le dossier dans lequel se trouve les fichiers path = QtWidgets.QFileDialog.getExistingDirectory( self, "Open a folder", os.sep.join((os.path.expanduser('~'), 'Desktop')), #Permet d'afficher le bureau à l'ouverture de la fenêtre options = QtWidgets.QFileDialog.ShowDirsOnly ) #Gestion de l'exception dans le cas où l'utilisateur choisit un mauvais dossier #Dans ce cas on envoie des projections générées virtuellement par tomopy #Si aucun dossier n'est sélectionné path = 0 et il ne se passe rien if path: try: MatrixGeneration(self, path, factor) except IndexError: return tomopy.project(tomopy.shepp3d(), tomopy.angles(180))
# preform the adjoint warp x = adjoint_backward_warp_3D(x_warped, self.u, self.v, self.w, degree=self.degree) # return as flattened array return x.ravel() # we start by preforming the same warp as in e04_3D_warping.py import tomopy im_size = 512 print("generating 3D images and DVFs") shepp = tomopy.shepp3d(im_size).astype(np.float32) u = 10 * np.repeat( np.sin(np.linspace(0, 4 * np.pi, im_size, dtype=np.float32)), im_size** 2).reshape((im_size, ) * 3) v = 8 * np.repeat(np.cos(np.linspace(0, 4 * np.pi, im_size, dtype=np.float32)), im_size**2).reshape((im_size, ) * 3) w = 2 * np.repeat(np.cos(np.linspace(0, 4 * np.pi, im_size, dtype=np.float32)), im_size**2).reshape((im_size, ) * 3) # this time, we can preform the warp with more high level syntax, # as if warping is a matrix vector multiplication (which it is). A = WarpingOperator(u, v, w) b = A @ shepp.ravel() # @ is matrix mult warped_shepp = b.reshape(shepp.shape) # we will now try to reconstruct shepp form the warped version "warped_shepp"
comm = MPI.COMM_WORLD print("Hello! I'm rank %d from %d running in total..." % (comm.rank, comm.size)) comm.Barrier() # wait for everybody to synchronize _here_ num_slice = 512 num_col = 2560 num_angles = 1024 blk_size = np.int(num_slice / comm.size) ang = tomopy.angles(num_angles) # Generate uniformly spaced tilt angles. obj_recv = np.zeros(blk_size * num_col * num_col, dtype=np.float32) if (comm.rank == 0): # obj = np.random.rand(num_slice,num_col,num_col).astype(np.float32) obj = np.float32(tomopy.shepp3d( (num_slice, num_col, num_col))) # Generate an object. vol = np.zeros((num_slice, num_col, num_col), dtype=np.float32) else: obj = None chunks = None vol = np.empty(num_slice * num_col * num_col) comm.Scatter(obj, obj_recv, root=0) #proj_data = np.random.rand(ang.size,num_slice,num_col) # Calculate projections for the relevant chunk proj_data = tomopy.project(obj_recv.reshape(blk_size, num_col, num_col), ang) # Calculate projections for the relevant chunk theta, rows, cols = proj_data.shape proj_data = proj_data[:, :, cols / 2 - num_col / 2:cols / 2 + num_col / 2] t_start = MPI.Wtime() rec = np.float32(reconMBIR_tomocam(proj_data, ang, comm.rank))
import tomopy import pylab obj = tomopy.shepp3d() # Generate an object. ang = tomopy.angles(180) # Generate uniformly spaced tilt angles. sim = tomopy.project(obj, ang) # Calculate projections. # rec = tomopy.recon_accelerated(sim, ang, algorithm='ospml_quad', hardware='Xeon_Phi', implementation='tomoperi') # Reconstruct object. rec = tomopy.recon_accelerated(sim, ang, algorithm="ospml_hybrid") # Show 64th slice of the reconstructed object. pylab.imshow(rec[64], cmap="gray") pylab.show()
import tomopy import pylab obj = tomopy.shepp3d() # Generate an object. ang = tomopy.angles(180) # Generate uniformly spaced tilt angles. sim = tomopy.project(obj, ang) # Calculate projections. #rec = tomopy.recon_accelerated(sim, ang, algorithm='ospml_quad', hardware='Xeon_Phi', implementation='tomoperi') # Reconstruct object. rec = tomopy.recon_accelerated(sim, ang, algorithm='ospml_hybrid') # Show 64th slice of the reconstructed object. pylab.imshow(rec[64], cmap='gray') pylab.show()
#import pyqtgraph as pg import afnumpy as afnp import math from XT_argsParser import bl832inputs_parser from XT_ForwardModel import forward_project, init_nufft_params, back_project from XT_Common import padmat from normalize import normalize_bo num_slice = 50 im_size = 512 #A n X n X n volume sino_center = im_size / 2 num_angles = 256 slice_idx = num_slice / 2 obj = tomopy.shepp3d((num_slice, im_size, im_size)) # Generate an object. #obj = tomopy.shepp3d(im_size) # Generate an object. ang = tomopy.angles(num_angles) # Generate uniformly spaced tilt angles. ### Comparing to tomopy sim = tomopy.project(obj, ang) sino = {} geom = {} sino['Ns'] = 768 #3624#im_size*2 #Sinogram size after padding sino['Ns_orig'] = im_size #size of original sinogram sino['center'] = sino_center + (sino['Ns'] / 2 - sino['Ns_orig'] / 2 ) #for padded sinogram sino['angles'] = ang params = init_nufft_params(sino, geom)
import numpy as np import cupy as cp from cupy_optomo import OpTomo import tomopy import astra from time import time im_size = 256 x = cp.asarray(tomopy.shepp3d(im_size), dtype=np.float32) vol_geom = astra.create_vol_geom(x.shape[1], x.shape[2], x.shape[0]) proj_geom = astra.create_proj_geom('parallel3d', 1, 1, x.shape[1], x.shape[2], np.linspace(0, np.pi, 200)) proj_id = astra.create_projector('cuda3d', proj_geom, vol_geom) # the astra version of OpTomo only accepts numpy arrays (CPU) # so we have to copy x to CPU before we can pass it to W1. W1 = astra.OpTomo(proj_id) # This would crash: # p1 = W1 @ x.ravel() # so we do this instead t0 = time() p1 = W1 @ (x.ravel().get()) print("Projected with ASTRA OpTomo in", time() - t0, "seconds") # with the cupy friendly OpTomo we can work on cupy arrays (GPU) # directly (and it still works on numpy arrays) W = OpTomo(proj_id)