Exemple #1
0
def generate_bead_test_volume(name: str,
                              size: Tuple[int, int, int] = (32, 32, 32),
                              num_beads: int = 32,
                              sigmas: Tuple[float, float, float] = (0, 0, 2)):
    data = np.zeros(size)
    mask = np.array([True] * num_beads + [False] *
                    (np.prod(data.size) - num_beads))
    np.random.shuffle(mask)
    mask = mask.reshape(data.shape)
    data[mask] = 1

    blurred = gaussian_filter(data, sigmas, mode='constant')
    blurred_vol = Volume(blurred, (1, 1, 1))
    blurred_vol.save_tiff('test_' + name)
    blurred_vol.save_tiff_single('test_single_' + name)
Exemple #2
0
def generate_spheres_test_volume(name: str,
                                 size: int = 32,
                                 num_beads: int = 32,
                                 sigmas: Tuple[float, float,
                                               float] = (0, 0, 2)):
    data = np.zeros((size, size, size))
    for i in range(num_beads):
        p = np.random.randint(8, size - 8, 3)
        data[p[0] - 8:p[0] + 8, p[1] - 8:p[1] + 8,
             p[1] - 8:p[1] + 8] = pymrt.geometry.sphere(16, 0.5, 8)

    vol = Volume(data, (1, 1, 1))
    vol.save_tiff('test_' + name)
    vol.save_tiff_single('test_single_' + name)

    blurred = gaussian_filter(data, sigmas, mode='constant')
    blurred_vol = Volume(blurred, (1, 1, 1))
    blurred_vol.save_tiff('btest_' + name)
    blurred_vol.save_tiff_single('btest_single_' + name)
    return data
Exemple #3
0
    psf = np.zeros((9, 9, 9))
    for x in range(9):
        for y in range(9):
            for z in range(9):
                psf[x, y, z] = multivariate_normal.pdf((x, y, z),
                                                       mean=(4, 4, 4),
                                                       cov=np.array([[4, 0, 0],
                                                                     [0, 4, 0],
                                                                     [0, 0,
                                                                      4]]))

    blurred = convolve(vol, psf)
    blurred += (np.random.poisson(lam=25, size=blurred.shape) - 10) / 250.

    blurred_vol = Volume(blurred, (1, 1, 1))
    blurred_vol.save_tiff('blurred_thing')

    # estimate = data
    # for i in range(200):
    #     estimate = estimate * blur(data/(blur(estimate)+1e-6))

    # estimate = restoration.richardson_lucy(blurred, psf, iterations=120)
    #
    # estimate_vol = Volume(estimate, (1, 1, 1))
    # estimate_vol.save_tiff('estimate')

    # import numpy as np
    # import matplotlib.pyplot as plt
    #
    # from scipy.signal import convolve2d as conv2
    #