Beispiel #1
0
image.fill(image_array)
mu_map = pet.ImageData('attenuation.hv')
mu_map_array = mu_map.as_array()
#%% bitmap display of images
slice_num = image_array.shape[0] // 2
plt.figure()
#plt.subplot(1,2,1);
imshow(image_array[slice_num, :, :, ], [], 'emission image')
#plt.subplot(1,2,2);
#imshow(mu_map_array[slice,:,:,], [], 'attenuation image');

#%% save max for future displays
cmax = image_array.max() * .6

#%% create acquisition model
am = pet.AcquisitionModelUsingRayTracingMatrix()
am.set_num_tangential_LORs(5)
templ = pet.AcquisitionData('template_sinogram.hs')
am.set_up(templ, image)
#%% simulate some data using forward projection
acquired_data = am.forward(image)
acquisition_array = acquired_data.as_array()

#%% Display bitmaps of a middle sinogram
plt.figure()
imshow(acquisition_array[0, 0, :, :, ], [], 'Forward projection')

#%% close all plots
plt.close('all')

#%% create objective function
Beispiel #2
0
def main():

    # output goes to files
    msg_red = pet.MessageRedirector('info.txt', 'warn.txt', 'errr.txt')

    # create acquisition model
    acq_model = pet.AcquisitionModelUsingRayTracingMatrix()

    # PET acquisition data to be read from the file specified by --file option
    print('raw data: %s' % raw_data_file)
    acq_data = pet.AcquisitionData(raw_data_file)

    # Noisy data for testing
    noisy_data = acq_data.clone()
    noisy_data_array = np.random.poisson(acq_data.as_array() / 10)
    noisy_data.fill(noisy_data_array)

    # create filter that zeroes the image outside a cylinder of the same
    # diameter as the image xy-section size
    filter = pet.TruncateToCylinderProcessor()

    # create initial image estimate
    image_size = (111, 111, 31)
    voxel_size = (3, 3, 3.375)  # voxel sizes are in mm
    image = pet.ImageData()
    image.initialise(image_size, voxel_size)
    image.fill(1.0)
    filter.apply(image)

    # create objective function
    obj_fun = pet.make_Poisson_loglikelihood(noisy_data)
    obj_fun.set_acquisition_model(acq_model)
    obj_fun.set_num_subsets(num_subsets)
    obj_fun.set_up(image)

    # create new obj_fun to get sensitivity image for one subset for dePierro MAPEM
    obj_fun2 = pet.make_Poisson_loglikelihood(noisy_data)
    obj_fun2.set_acquisition_model(acq_model)
    obj_fun2.set_num_subsets(1)
    obj_fun2.set_up(image)
    sensitivity_image = obj_fun2.get_subset_sensitivity(0)

    # create new noise-free obj_fun to use for guidance in dePierro MAPEM
    obj_fun3 = pet.make_Poisson_loglikelihood(acq_data)
    obj_fun3.set_acquisition_model(acq_model)
    obj_fun3.set_num_subsets(num_subsets)
    obj_fun3.set_up(image)

    # uniform weights
    weightsUniform = np.ones([sensitivity_image.as_array().size, 27],
                             dtype='float')
    weightsUniform = weightsUniform / 27.0

    # noise free recon with beta = 0 for guidance
    image_noiseFree = my_dePierroMap \
        (image, obj_fun3, 0, filter, num_subsets, num_subiterations, weightsUniform, sensitivity_image)

    # create a Prior for computing Bowsher weights
    myPrior = pr.Prior(sensitivity_image.as_array().shape)
    weightsBowsher = myPrior.BowshserWeights(image_noiseFree.as_array(), 10)
    weightsBowsher = np.float64(weightsBowsher / 10.0)

    # dePierro MAPEM with uniform and Bowsher weights
    beta = 5000.0
    image_dp_b = my_dePierroMap \
        (image, obj_fun, beta, filter, num_subsets, num_subiterations, weightsBowsher, sensitivity_image)

    image_dp_u = my_dePierroMap \
        (image, obj_fun, beta, filter, num_subsets, num_subiterations, weightsUniform, sensitivity_image)

    # show reconstructed images at z = 20
    image_dp_b_array = image_dp_b.as_array()
    image_dp_u_array = image_dp_u.as_array()
    show_2D_array('Noise free image', image_noiseFree.as_array()[20, :, :])
    show_2D_array('DP Bowsher', image_dp_b_array[20, :, :])
    show_2D_array('DP Uniform', image_dp_u_array[20, :, :])
    show_2D_array('Difference DP',
                  image_dp_b_array[20, :, :] - image_dp_u_array[20, :, :])