Skip to content

Reference for pyronn/ct_reconstruction/helpers/misc/general_utils.py


pyronn.ct_reconstruction.helpers.misc.general_utils.fibonacci_sphere

fibonacci_sphere(n)

Calculation of the fibonacci distribution on a unit sphere with n samples. :param n: Number of samples on the sphere :return: The entered coordinates seperated to x,y,z components

Source code in pyronn/ct_reconstruction/helpers/misc/general_utils.py
def fibonacci_sphere(n):
    # TODO: Document this function on your own. Could not be documented by the model.
    # TODO: Document this function on your own. Could not be documented by the model.
    '''
    Calculation of the fibonacci distribution on a unit sphere with n samples.
    :param n: Number of samples on the sphere
    :return: The entered coordinates seperated to x,y,z components
    '''
    goldenRatio = (1 + 5**0.5)/2
    i = np.arange(0, n)
    theta = (2 *np.pi * i / goldenRatio)  %(2*np.pi) # to radian  # in range [0°,360°]
    phi = np.arccos(1 - 2*(i+0.5)/n)  #/2  # in range [1°,179°]
    x,z, y = np.cos(theta) * np.sin(phi), np.sin(theta) * np.sin(phi), np.cos(phi)
    return np.vstack([x,y,z]).T





pyronn.ct_reconstruction.helpers.misc.general_utils.rotation_matrix_from_points

rotation_matrix_from_points(p1, p2)
Source code in pyronn/ct_reconstruction/helpers/misc/general_utils.py
def rotation_matrix_from_points(p1, p2):
    # TODO: Document this function on your own. Could not be documented by the model.
    # TODO: Document this function on your own. Could not be documented by the model.
    p1 = np.array(p1) / np.linalg.norm(p1)
    p2 = np.array(p2) / np.linalg.norm(p2)

    axis = np.cross(p1, p2)
    axis_length = np.linalg.norm(axis)
    if axis_length < 1e-5:
        if np.dot(p1, p2) > 0:
            return np.eye(3)
        else:
            axis = np.array([p1[1], -p1[0], 0])
            if np.linalg.norm(axis) == 0:
                axis = np.array([p1[2], 0, -p1[0]])
            axis = axis / np.linalg.norm(axis)
            theta = np.pi
    else:
        axis = axis / axis_length

    cos_theta = np.dot(p1, p2)
    sin_theta = np.sqrt(1 - cos_theta ** 2)

    K = np.array([[0, -axis[2], axis[1]],
                  [axis[2], 0, -axis[0]],
                  [-axis[1], axis[0], 0]])
    R = np.eye(3) + sin_theta * K + (1 - cos_theta) * np.dot(K, K)

    return R





pyronn.ct_reconstruction.helpers.misc.general_utils.fft_and_ifft

fft_and_ifft(sinogram, filter)
Source code in pyronn/ct_reconstruction/helpers/misc/general_utils.py
def fft_and_ifft(sinogram, filter):
    # TODO: Document this function on your own. Could not be documented by the model.
    # TODO: Document this function on your own. Could not be documented by the model.
    if pyronn.read_backend() == 'torch':
        import torch
        if not isinstance(sinogram, torch.Tensor):
            sinogram = torch.tensor(sinogram).cuda()
        if not isinstance(filter, torch.Tensor):
            filter = torch.tensor(filter).cuda()

        x = torch.fft.fft(sinogram, dim=-1, norm='ortho')
        x = torch.multiply(x, filter)
        x = torch.fft.ifft(x, dim=-1, norm='ortho').real
        return x
    elif pyronn.read_backend() == 'tensorflow':
        import tensorflow as tf
        sino_freq = tf.signal.fft(tf.cast(sinogram, dtype=tf.complex64))
        sino_filtered_freq = tf.multiply(sino_freq, tf.cast(filter, dtype=tf.complex64))
        sinogram_filtered = tf.math.real(tf.signal.ifft(sino_filtered_freq))
        return sinogram_filtered