Esempio n. 1
0
def bench_fanbeam_backward(phantom, det_count, num_angles, source_dist,
                           det_dist, warmup, repeats):
    geometry = create_fanbeam_geometry(det_count, num_angles, source_dist,
                                       det_dist)

    sino = fan_projection2d(phantom, geometry)
    f = lambda x: fan_backprojection2d(x, geometry)

    return benchmark(f, sino, warmup, repeats)
Esempio n. 2
0
def example_fan_2d_shortscan():
    # Volume Parameters:
    volume_size = 256
    volume_shape = [volume_size, volume_size]
    volume_spacing = [1, 1]

    # Detector Parameters:
    detector_shape = 500
    detector_spacing = 1

    # Trajectory Parameters:
    number_of_projections = 250
    angular_range = None  # will get set to pi + 2 * fan_angle

    source_detector_distance = 1200
    source_isocenter_distance = 750

    # Create Geometry class
    geometry = GeometryFan2D(volume_shape, volume_spacing, detector_shape,
                             detector_spacing, number_of_projections,
                             angular_range, source_detector_distance,
                             source_isocenter_distance)

    geometry.angular_range = np.pi + 2 * geometry.fan_angle  # fan_angle gets defined by sdd and detector_shape
    geometry.set_trajectory(circular_trajectory_2d(geometry))

    # Create Phantom
    phantom = shepp_logan_enhanced(volume_shape)
    # Add required batch dimension
    phantom = np.expand_dims(phantom, axis=0)
    # Build up Reconstruction Pipeline

    # Create Sinogram of Phantom
    sinogram = fan_projection2d(phantom, geometry)

    # Redundancy Weighting: Create Weights Image and pointwise multiply
    redundancy_weights = weights.parker_weights_2d(geometry)
    sinogram_redun_weighted = sinogram * redundancy_weights

    # Filtering: Create 2D Filter and pointwise multiply
    reco_filter = filters.ram_lak_2D(geometry)
    sino_freq = tf.signal.fft(
        tf.cast(sinogram_redun_weighted, dtype=tf.complex64))
    sino_filtered_freq = tf.multiply(sino_freq,
                                     tf.cast(reco_filter, dtype=tf.complex64))
    sinogram_filtered = tf.math.real(tf.signal.ifft(sino_filtered_freq))
    # Final Backprojection
    reco = fan_backprojection2d(sinogram_filtered, geometry)

    plt.figure()
    plt.imshow(np.squeeze(reco), cmap=plt.get_cmap('gist_gray'))
    plt.axis('off')
    plt.savefig('2d_fan_short_scan_reco.png',
                dpi=150,
                transparent=False,
                bbox_inches='tight')
Esempio n. 3
0
def example_fan_2d_shortscan():
    # Volume Parameters:
    volume_size = 256
    volume_shape = [volume_size, volume_size]
    volume_spacing = [1,1]

    # Detector Parameters:
    detector_shape = 500
    detector_spacing = 1

    # Trajectory Parameters:
    number_of_projections = 250
    angular_range = None # will get set to pi + 2 * fan_angle

    source_detector_distance = 1200
    source_isocenter_distance = 750

    # Create Geometry class
    geometry = GeometryFan2D(volume_shape, volume_spacing, 
                             detector_shape, detector_spacing, 
                             number_of_projections, angular_range, 
                             source_detector_distance, source_isocenter_distance)
    
    geometry.angular_range =  np.pi + 2*geometry.fan_angle # fan_angle gets defined by sdd and detector_shape
    geometry.central_ray_vectors = circular_trajectory_2d(geometry)

    # Create Phantom
    phantom = shepp_logan_enhanced(volume_shape)
    phantom = np.expand_dims(phantom,axis=0)
    # Build up Reconstruction Pipeline
    with tf.Session() as sess:

        # Create Sinogram of Phantom
        result = fan_projection2d(phantom, geometry)
        sinogram = result.eval()

        # Redundancy Weighting: Create Weights Image and pointwise multiply
        redundancy_weights = weights.parker_weights_2d(geometry)
        sinogram_redun_weighted = sinogram * redundancy_weights

        # Filtering: Create 2D Filter and pointwise multiply
        the_filter = filters.ram_lak_2D(geometry)
        sino_fft = np.fft.fft(sinogram_redun_weighted, axis=-1)
        sino_filtered_fft = np.multiply(sino_fft, the_filter)
        sinogram_filtered = np.fft.ifft(sino_filtered_fft, axis=-1)

        # Final Backprojection
        result_back_proj = fan_backprojection2d(sinogram_filtered, geometry)
        reco = result_back_proj.eval()

        plt.figure()
        plt.imshow(np.squeeze(reco), cmap=plt.get_cmap('gist_gray'))
        plt.axis('off')
        plt.savefig('2d_fan_short_scan_reco.png', dpi=150, transparent=False, bbox_inches='tight')
Esempio n. 4
0
def example_fan_2d():
    # ------------------ Declare Parameters ------------------

    # Volume Parameters:
    volume_size = 256
    volume_shape = [volume_size, volume_size]
    volume_spacing = [1, 1]

    # Detector Parameters:
    detector_shape = 800
    detector_spacing = 1

    # Trajectory Parameters:
    number_of_projections = 360
    angular_range = 2 * np.pi

    source_detector_distance = 1200
    source_isocenter_distance = 750

    # create Geometry class
    geometry = GeometryFan2D(volume_shape, volume_spacing, detector_shape,
                             detector_spacing, number_of_projections,
                             angular_range, source_detector_distance,
                             source_isocenter_distance)
    geometry.set_central_ray_vectors(
        circular_trajectory.circular_trajectory_2d(geometry))

    # Get Phantom
    phantom = shepp_logan.shepp_logan_enhanced(volume_shape)
    phantom = np.expand_dims(phantom, axis=0)
    # ------------------ Call Layers ------------------
    with tf.Session() as sess:
        result = fan_projection2d(phantom, geometry)
        sinogram = result.eval()

        #TODO: Add Cosine weighting
        #TODO: Add redundancy weighting for 360 degree

        reco_filter = filters.ramp_2D(geometry)

        sino_freq = np.fft.fft(sinogram, axis=-1)
        sino_filtered_freq = np.multiply(sino_freq, reco_filter)
        sinogram_filtered = np.fft.ifft(sino_filtered_freq, axis=-1)

        result_back_proj = fan_backprojection2d(sinogram_filtered, geometry)
        reco = result_back_proj.eval()
        plt.figure()
        plt.imshow(np.squeeze(reco), cmap=plt.get_cmap('gist_gray'))
        plt.axis('off')
        plt.savefig('2d_fan_reco.png',
                    dpi=150,
                    transparent=False,
                    bbox_inches='tight')
Esempio n. 5
0
def example_fan_2d():
    # ------------------ Declare Parameters ------------------

    # Volume Parameters:
    volume_size = 256
    volume_shape = [volume_size, volume_size]
    volume_spacing = [1,1]

    # Detector Parameters:
    detector_shape = 800
    detector_spacing = 1

    # Trajectory Parameters:
    number_of_projections = 360
    angular_range = 2*np.pi

    source_detector_distance = 1200
    source_isocenter_distance = 750

    # create Geometry class
    geometry = GeometryFan2D(volume_shape, volume_spacing, detector_shape, detector_spacing, number_of_projections, angular_range, source_detector_distance, source_isocenter_distance)
    geometry.set_trajectory(circular_trajectory.circular_trajectory_2d(geometry))

    # Get Phantom
    phantom = shepp_logan.shepp_logan_enhanced(volume_shape)
    # Add required batch dimension
    phantom = np.expand_dims(phantom,axis=0)
    # ------------------ Call Layers ------------------

    sinogram = fan_projection2d(phantom, geometry)

    #TODO: Add Cosine weighting
    #TODO: Add redundancy weighting for 360 degree

    reco_filter = filters.ramp_2D(geometry)
    sino_freq = tf.signal.fft(tf.cast(sinogram,dtype=tf.complex64))
    sino_filtered_freq = tf.multiply(sino_freq,tf.cast(reco_filter,dtype=tf.complex64))
    sinogram_filtered = tf.math.real(tf.signal.ifft(sino_filtered_freq))

    reco = fan_backprojection2d(sinogram_filtered, geometry)

    plt.figure()
    plt.imshow(np.squeeze(reco), cmap=plt.get_cmap('gist_gray'))
    plt.axis('off')
    plt.savefig('2d_fan_reco.png', dpi=150, transparent=False, bbox_inches='tight')
Esempio n. 6
0
 def test_func_reco(x):
     return fan_backprojection2d(x,geometry)
 def f(x):
     return fan_backprojection2d(x, geometry)