How to use pyconrad - 10 common examples

To help you get started, we’ve selected a few pyconrad examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github csyben / PYRO-NN / examples / ct_reconstruction / exampe_learning_simple.py View on Github external
# Trajectory Parameters:
    number_of_projections = 100
    angular_range = np.pi

    # create Geometry class
    geometry = GeometryParallel2D(volume_shape, volume_spacing, detector_shape, detector_spacing, number_of_projections, angular_range)
    geometry.set_ray_vectors(circular_trajectory.circular_trajectory_2d(geometry))

    # Get Phantom
    phantom = shepp_logan.shepp_logan(volume_shape)
    pyc.imshow(phantom, 'phantom')

    # Training Data
    sinogram = generate_sinogram.generate_sinogram(phantom, parallel_projection2d, geometry)
    pyc.imshow(sinogram, 'sinogram')


    # ------------------ Build Network ------------------

    # Define input sinogram
    input_sinogram_tf = tf.placeholder(tf.float32, shape=geometry.sinogram_shape, name="input_sinogram")

    # FFT layer
    fft_layer = tf.cast(tf.spectral.fft(tf.cast(input_sinogram_tf, dtype=tf.complex64)), tf.complex64)

    # Filtering as multiplication layer
    filter_weights = tf.Variable(tf.convert_to_tensor(filters.ramp(int(geometry.detector_shape[0])))) # init as ramp filter
    #filter_weights = tf.Variable(tf.convert_to_tensor(np.random.uniform(size=int(geometry.detector_shape[0])))) # init as random to see something
    filter_layer = tf.multiply(fft_layer, tf.cast(filter_weights, dtype=tf.complex64))

    # IFFT layer
github csyben / PYRO-NN / deep_ct_reconstruction / ct_reconstruction / helpers / phantoms / circle.py View on Github external
# params
    size_x = 200
    size_y = 300

    # circle
    cricle_phantom = circle([size_y, size_x], [50, 50], 30, 1)
    pyc.imshow(cricle_phantom, 'phantom1')

    # ellipse
    ellipse_phantom = ellipse([200, 200], [50, 50], [11, 31], 1, np.radians(18.0))
    pyc.imshow(ellipse_phantom, 'phantom2')

    # my_shepp_logan
    my_shepp_logan = shepp_logan_numpy([size_y, size_x])
    pyc.imshow(my_shepp_logan, 'my_shepp_logan')

    # pyconrad shepp logan
    _ = pyc.ClassGetter('edu.stanford.rsl.tutorial.phantoms')
    shepp_conrad = _.SheppLogan(size_x, True).as_numpy()
    pyc.imshow(shepp_conrad, 'shepp_conrad')

    # difference
    abs_diff = np.abs(my_shepp_logan - shepp_conrad)
    pyc.imshow(abs_diff, 'diff')
    print('difference: ', np.sum(abs_diff))
github csyben / PYRO-NN / examples / ct_reconstruction / exampe_learning_simple.py View on Github external
# ------------------ Training ------------------
    with tf.Session() as sess:
        sess.run(tf.global_variables_initializer())
        sess.run(tf.local_variables_initializer())

        for i in range(iterations):
            # run tf session
            training = sess.run(training_operator, feed_dict={input_sinogram_tf: sinogram, ground_truth_tf: phantom})
            loss_value = sess.run(loss_function,   feed_dict={input_sinogram_tf: sinogram, ground_truth_tf: phantom})

            # show some outputs
            if i%1 is 0:
                # show the current reco
                reco = sess.run(backprojection_layer, feed_dict={input_sinogram_tf: sinogram})
                pyc.imshow(reco, 'reco')

                # show the current filter
                current_filter = filter_weights.eval()
                plt.plot(current_filter)
                plt.ylabel('current_filter')
                plt.pause(0.05)

                # status
                print( "iteration: ", i)
                print( "loss: ", loss_value)
github csyben / PYRO-NN / deep_ct_reconstruction / ct_reconstruction / helpers / phantoms / circle.py View on Github external
# circle
    cricle_phantom = circle([size_y, size_x], [50, 50], 30, 1)
    pyc.imshow(cricle_phantom, 'phantom1')

    # ellipse
    ellipse_phantom = ellipse([200, 200], [50, 50], [11, 31], 1, np.radians(18.0))
    pyc.imshow(ellipse_phantom, 'phantom2')

    # my_shepp_logan
    my_shepp_logan = shepp_logan_numpy([size_y, size_x])
    pyc.imshow(my_shepp_logan, 'my_shepp_logan')

    # pyconrad shepp logan
    _ = pyc.ClassGetter('edu.stanford.rsl.tutorial.phantoms')
    shepp_conrad = _.SheppLogan(size_x, True).as_numpy()
    pyc.imshow(shepp_conrad, 'shepp_conrad')

    # difference
    abs_diff = np.abs(my_shepp_logan - shepp_conrad)
    pyc.imshow(abs_diff, 'diff')
    print('difference: ', np.sum(abs_diff))
github csyben / PYRO-NN / examples / ct_reconstruction / example_parallel_3d.py View on Github external
sinogram = sinogram + np.random.normal(
           loc=np.mean(np.abs(sinogram)), scale=np.std(sinogram), size=sinogram.shape) * 0.02

        reco_filter = filters.ram_lak_3D(geometry)

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

        result_back_proj = par_backprojection3d(sinogram_filtered,geometry)
        reco = result_back_proj.eval()
        import pyconrad as pyc
        pyc.setup_pyconrad()
        pyc.imshow(phantom)
        pyc.imshow(sinogram)
        pyc.imshow(reco)
        a = 5
        #plt.figure()
github csyben / PYRO-NN / deep_ct_reconstruction / ct_reconstruction / helpers / phantoms / circle.py View on Github external
# ellipse
    ellipse_phantom = ellipse([200, 200], [50, 50], [11, 31], 1, np.radians(18.0))
    pyc.imshow(ellipse_phantom, 'phantom2')

    # my_shepp_logan
    my_shepp_logan = shepp_logan_numpy([size_y, size_x])
    pyc.imshow(my_shepp_logan, 'my_shepp_logan')

    # pyconrad shepp logan
    _ = pyc.ClassGetter('edu.stanford.rsl.tutorial.phantoms')
    shepp_conrad = _.SheppLogan(size_x, True).as_numpy()
    pyc.imshow(shepp_conrad, 'shepp_conrad')

    # difference
    abs_diff = np.abs(my_shepp_logan - shepp_conrad)
    pyc.imshow(abs_diff, 'diff')
    print('difference: ', np.sum(abs_diff))
github csyben / PYRO-NN / examples / ct_reconstruction / exampe_learning_simple.py View on Github external
# Detector Parameters:
    detector_shape = 2*volume_size
    detector_spacing = 0.5

    # Trajectory Parameters:
    number_of_projections = 100
    angular_range = np.pi

    # create Geometry class
    geometry = GeometryParallel2D(volume_shape, volume_spacing, detector_shape, detector_spacing, number_of_projections, angular_range)
    geometry.set_ray_vectors(circular_trajectory.circular_trajectory_2d(geometry))

    # Get Phantom
    phantom = shepp_logan.shepp_logan(volume_shape)
    pyc.imshow(phantom, 'phantom')

    # Training Data
    sinogram = generate_sinogram.generate_sinogram(phantom, parallel_projection2d, geometry)
    pyc.imshow(sinogram, 'sinogram')


    # ------------------ Build Network ------------------

    # Define input sinogram
    input_sinogram_tf = tf.placeholder(tf.float32, shape=geometry.sinogram_shape, name="input_sinogram")

    # FFT layer
    fft_layer = tf.cast(tf.spectral.fft(tf.cast(input_sinogram_tf, dtype=tf.complex64)), tf.complex64)

    # Filtering as multiplication layer
    filter_weights = tf.Variable(tf.convert_to_tensor(filters.ramp(int(geometry.detector_shape[0])))) # init as ramp filter
github csyben / PYRO-NN / examples / ct_reconstruction / exampe_learning_simple.py View on Github external
import numpy as np
import tensorflow as tf
import lme_custom_ops
import pyconrad as pyc
import matplotlib.pyplot as plt
pyc.setup_pyconrad()


from pyronn.ct_reconstruction.layers.projection_2d import parallel_projection2d
from pyronn.ct_reconstruction.layers.backprojection_2d import parallel_backprojection2d
from pyronn.ct_reconstruction.geometry.geometry_parallel_2d import GeometryParallel2D
from pyronn.ct_reconstruction.helpers.phantoms import shepp_logan
from pyronn.ct_reconstruction.helpers.trajectories import circular_trajectory
from pyronn.ct_reconstruction.helpers.filters import filters
import pyronn.ct_reconstruction.helpers.misc.generate_sinogram as generate_sinogram


def example_learning_simple():
    # ------------------ Declare Parameters ------------------

    # Volume Parameters:
    volume_size = 200
github csyben / PYRO-NN / deep_ct_reconstruction / ct_reconstruction / helpers / phantoms / circle.py View on Github external
import numpy as np

import pyconrad as pyc # TODO: get independent of pyconrad
pyc.setup_pyconrad()

def circle(shape, pos, radius, value):

    # create meshgrid of coords
    xx, yy = np.mgrid[:shape[1], :shape[0]]

    # calc squared distance to pos
    circle = (xx - pos[1]) ** 2 + (yy - pos[0]) ** 2

    return (circle <= radius**2) * value

def ellipse(shape, pos, half_axes, value, theta=0):

    # create meshgrid of coords
    xx, yy = np.mgrid[:shape[0], :shape[1]]
github csyben / PYRO-NN / examples / ct_reconstruction / example_parallel_3d.py View on Github external
sinogram = sinogram + np.random.normal(
           loc=np.mean(np.abs(sinogram)), scale=np.std(sinogram), size=sinogram.shape) * 0.02

        reco_filter = filters.ram_lak_3D(geometry)

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

        result_back_proj = par_backprojection3d(sinogram_filtered,geometry)
        reco = result_back_proj.eval()
        import pyconrad as pyc
        pyc.setup_pyconrad()
        pyc.imshow(phantom)
        pyc.imshow(sinogram)
        pyc.imshow(reco)
        a = 5
        #plt.figure()

pyconrad

Python wrapper for CONRAD (https://www5.cs.fau.de/conrad/), a framework for cone beam radiography

GPL-3.0
Latest version published 4 years ago

Package Health Score

39 / 100
Full package analysis