Example #1
0
    def test_dimension(self):
        image_dim = (50, 50, 3)
        image_3d = np.random.default_rng().random(image_dim)
        image_2d = np.copy(image_3d[..., 0])

        spline_3d = spl.radon(image_3d)
        spline_2d = spl.radon(image_2d)

        np.testing.assert_allclose(
            spline_2d, spline_3d[..., 0], rtol=1e-12, atol=1e-12)

        out_3d = spl.iradon(image_3d)
        out_2d = spl.iradon(image_2d)

        np.testing.assert_allclose(
            out_2d, out_3d[..., 0], rtol=1e-12, atol=1e-12)
Example #2
0
    def test_contiguous(self):
        image_dim = (50, 50, 3)
        image_3d = np.random.default_rng().random(image_dim)

        image_3d = np.transpose(image_3d, (1, 0, 2))
        image_2d = np.copy(image_3d[..., 0])

        spline_3d = spl.radon(image_3d)
        spline_2d = spl.radon(image_2d)

        np.testing.assert_allclose(
            spline_2d, spline_3d[..., 0], rtol=1e-9, atol=1e-12)

        out_3d = spl.iradon(spline_3d)
        out_2d = spl.iradon(spline_2d)

        np.testing.assert_allclose(
            out_2d, out_3d[..., 0], rtol=1e-9, atol=1e-12)
Example #3
0
    def test_padding(self):
        theta = np.arange(10)
        for size in range(5, 25):
            shape = (size, size)
            image = np.random.default_rng().random(shape)

            for circle in (True, False):
                rd = spl.radon(image, theta, circle=circle,
                               b_spline_deg=(0, 0))
                ird = spl.iradon(rd, theta, circle=circle, b_spline_deg=(0, 0))

                np.testing.assert_array_equal(shape, ird.shape)
Example #4
0
# SPDX-License-Identifier: BSD-3-Clause

import os
import numpy as np

import cbi_toolbox.splineradon as spl

path = os.environ['OVC_PATH']

ipath = os.path.join(path, 'imaging')
rpath = os.path.join(path, 'reconstruct')

theta = np.linspace(0, 180, 360, endpoint=False)

radon = np.load(os.path.join(ipath, 'radon.npy'))
iradon = spl.iradon(radon, theta=theta, circle=True)
np.save(os.path.join(rpath, 'iradon.npy'), iradon)
print('iradon saved')
del iradon, radon

for na in (30, 50, 80):
    fps_opt = np.load(os.path.join(ipath, 'fpsopt_{:03d}.npy'.format(na)))
    iradon = spl.iradon(fps_opt, theta=theta, circle=True)
    np.save(os.path.join(rpath, 'fpsopt_{:03d}.npy'.format(na)), iradon)
    print('fpsopt saved')
    del iradon, fps_opt

    fss_opt = np.load(os.path.join(ipath, 'fssopt_{:03d}.npy'.format(na)))
    iradon = spl.iradon(fss_opt, theta=theta, circle=True)
    np.save(os.path.join(rpath, 'fssopt_{:03d}.npy'.format(na)), iradon)
    print('fssopt saved')
Example #5
0
image[50, 50, 0] = 1
image[10, 50, 1] = 1
image[60, 20, 1] = 1
image[30, 60, 2] = 1
image[30, 20, 2] = 1
image[35, 35, :] = 1

use_cuda = spl.is_cuda_available()
if use_cuda:
    print('Running with GPU acceleration')
else:
    print('Running on CPU')

sinogram = spl.radon(image, use_cuda=use_cuda)

reconstruct = spl.iradon(sinogram, use_cuda=use_cuda)

reconstruct -= reconstruct.min()
reconstruct /= reconstruct.max()

sinogram[sinogram < 0] = 0
sinogram /= sinogram.max()

plt.figure()
plt.subplot(131)
plt.imshow(image)
plt.subplot(132)
plt.imshow(sinogram)
plt.subplot(133)
plt.imshow(reconstruct)
Example #6
0
na = id // 19
dna = id % 19

l = (1e4, 1e3, 1e2)[na]
na = (30, 50, 80)[na]
dna = 10 + 5 * dna

theta = np.linspace(0, 180, 360, endpoint=False)

fps_opt = np.load(os.path.join(ipath, 'fpsopt_{:03d}.npy'.format(na)))
fps_opt = imaging.noise(fps_opt, in_place=True, seed=0, photons=photons)

psf, _ = utils.load_ome_tiff(os.path.join(
    path, 'psf', 'BW_{:03d}.tif'.format(dna)))
fpsf = optics.gaussian_psf(
    psf.shape[1], psf.shape[0], numerical_aperture=dna/100)


deco = deconv.deconvolve_sinogram(fps_opt, psf, l=l)
np.save(os.path.join(npath, '{:03d}_{:03d}d.npy'.format(na, dna)), deco)
deco = spl.iradon(deco, theta=theta, circle=True)
np.save(os.path.join(npath, '{:03d}_{:03d}.npy'.format(na, dna)), deco)
print('saved {:03d}_{:03d}.npy'.format(na, dna))

deco = deconv.deconvolve_sinogram(fps_opt, fpsf, l=l)
np.save(os.path.join(npath, '{:03d}_{:03d}fd.npy'.format(na, dna)), deco)
deco = spl.iradon(deco, theta=theta, circle=True)
np.save(os.path.join(npath, '{:03d}_{:03d}f.npy'.format(na, dna)), deco)
print('saved {:03d}_{:03d}f.npy'.format(na, dna))
Example #7
0
print('Time for FPS-OPT: \t{}s'.format(time.time() - start))

start = time.time()
s_fssopt = imaging.fss_opt(sample, s_psf, spim_illu, theta=s_theta)
print('Time for FSS-OPT: \t{}s'.format(time.time() - start))

start = time.time()
s_radon = spl.radon(sample, theta=s_theta, circle=True)
print('Time for radon: \t{}s'.format(time.time() - start))

start = time.time()
s_deconv = fpsopt.deconvolve_sinogram(s_fpsopt, s_psf)
print('Time for deconv: \t{}s'.format(time.time() - start))

start = time.time()
r_radon = spl.iradon(s_radon, s_theta, circle=True)
print('Time for reconstruct radon: \t{}s'.format(time.time() - start))

start = time.time()
r_opt = spl.iradon(s_opt, s_theta, circle=True)
print('Time for reconstruct OPT: \t{}s'.format(time.time() - start))

start = time.time()
r_fpsopt = spl.iradon(s_fpsopt, s_theta, circle=True)
print('Time for reconstruct FPS-OPT: \t{}s'.format(time.time() - start))

start = time.time()
r_deconv = spl.iradon(s_deconv, s_theta, circle=True)
print('Time for reconstruct FPS-OPT deconv: \t{}s'.format(time.time() - start))

start = time.time()
Example #8
0
import cbi_toolbox.splineradon as spl

parser = argparse.ArgumentParser()
parser.add_argument('id', type=int)

args = parser.parse_args()
id = args.id - 1

na = id // 19
dna = id % 19

na = (30, 50, 80)[na]
dna = 10 + 5 * dna

theta = np.linspace(0, 180, 360, endpoint=False)

path = os.environ['OVC_PATH']

dpath = os.path.join(path, 'deconv')
rpath = os.path.join(path, 'reconstruct')

for suffix in ('', 'f'):
    file = '{:03d}_{:03d}{}.npy'.format(na, dna, suffix)

    deconv = np.load(os.path.join(dpath, file))

    iradon = spl.iradon(deconv, theta=theta, circle=True)

    np.save(os.path.join(rpath, file), iradon)
    print('{} saved'.format(file))
Example #9
0
# 3-Clause BSD License for more details.
#
# You should have received a copy of the 3-Clause BSD License along
# with CBI Toolbox. If not, see https://opensource.org/licenses/BSD-3-Clause.
#
# SPDX-License-Identifier: BSD-3-Clause

import os
import numpy as np

import cbi_toolbox.splineradon as spl
from cbi_toolbox.simu import imaging

photons = 1e4

path = os.environ['OVC_PATH']

ipath = os.path.join(path, 'imaging')
npath = os.path.join(path, 'noise')

theta = np.linspace(0, 180, 360, endpoint=False)

radon = np.load(os.path.join(ipath, 'radon.npy'))
radon[radon < 0] = 0

radon = imaging.noise(radon, seed=0, in_place=True, photons=photons)

iradon = spl.iradon(radon, theta=theta, circle=True)
np.save(os.path.join(npath, 'iradon.npy'), iradon)
print('iradon saved')