def process_frames(self, data): sino = data[0] cors, angles, vol_shape, init = self.get_frame_params() voxels = ccpi_alg.cgls(sino.astype(np.float32), angles.astype(np.float32), cors[0], self.res, self.n_iters, 1, self.parameters['log']) # need to get left and right shift and crop pad_start, pad_end = self.array_pad(cors[0], self.width) return np.transpose(voxels[pad_start:pad_end, pad_start:pad_end, :], (0, 2, 1))
import numpy as np import h5py from ccpi.reconstruction.parallelbeam import alg as ccpi_reconstruction angles = np.load('angles.npy') sino = np.load('sino.npy') sino = sino.astype(np.float32) angles = angles.astype(np.float32) voxels = ccpi_reconstruction.cgls(sino, angles, np.double(0.0), 1, 5, 1, False) #output = h5py.File('output.h5','w') #odata = output.create_dataset("default", data=voxels) #output.close() #output = h5py.File('input.h5','w') #odata = output.create_dataset("default", data=sino) #output.close()
## Data can now be passed to the reconstruction algorithms: ## CGLS, MLEM, SIRT, CGLS_CONV, CGLS_TIKHONOV, CGLS_TVregularization #center of rotation center_of_rotation = numpy.double(86.2) #resolution resolution = 1 # number of iterations niterations = 10 # number of threads threads = 4 #data are in log scale? isPixelDataInLogScale = False # CGLS img_cgls = alg.cgls(norm, angle_proj, center_of_rotation, resolution, niterations, threads, isPixelDataInLogScale) #img_cgls = numpy.transpose(img_cgls, axes=[0,2,1]) # check if padded shape = numpy.shape(img_cgls) img_cgls = img_cgls[:, :shape[1] - 1, :] #counter = shape[2] - 1 #while True: # if numpy.all(img_cgls[:,:,counter] == 0): # counter = counter -1 # else: # break # #if counter < shape[2] - 1: # img_cgls = img_cgls[:,:,:counter]
cor = 175.75 ############################################################ #recon.pars['algorithm'] = Reconstructor.Algorithm.CGLS_CONV #recon.pars['regularize'] = numpy.double(0.1) #img_cgls_conv = recon.reconstruct() niterations = 15 threads = 4 data = (norm.T).copy() del norm del reader norm = data print ("Launching CGLS") img_cgls = alg.cgls(norm, angle_proj, numpy.double(cor), 1 , niterations, threads, False) numpy.save("chadwick_chamber.npy", img_cgls) print ("CGLS finished") v = CILViewer2D() v.setInputAsNumpy(img_cgls) v.startRenderLoop() ##img_mlem = alg.mlem(norm, angle_proj, numpy.double(cor), 1 , niterations, threads, False) ##img_sirt = alg.sirt(norm, angle_proj, numpy.double(cor), 1 , niterations, threads, False) ## ##iteration_values = numpy.zeros((niterations,)) ##img_cgls_conv = alg.cgls_conv(norm, angle_proj, numpy.double(cor), 1 , niterations, threads, ## iteration_values, False) ##print ("iteration values %s" % str(iteration_values)) ## ##iteration_values = numpy.zeros((niterations,))
# CGLS niterations = 10 threads = 4 isPixelDataInLogScale = False m = stack.min() M = stack.max() scale = 1 / (M - m) shift = -m + 1e-2 norm = stack * scale + shift # absorption is from 0 to 1 where 0 is max density norm = 0.99 - norm norm = numpy.transpose(norm, axes=[0, 2, 1]).copy() img_cgls = alg.cgls(norm, angles, center_of_rotation , \ pixel_per_voxel , niterations, threads, isPixelDataInLogScale) cols = 4 rows = 1 current = 1 fig = plt.figure() a = fig.add_subplot(rows, cols, current) a.set_title('volume') imgplot = plt.imshow(phantom[64]) current = current + 1 a = fig.add_subplot(rows, cols, current) a.set_title('stack') imgplot = plt.imshow(stack[20]) current = current + 1