def test_simple(): """Simple test for backproject""" count = mp.Value("i") max_count = mp.Value("i") sino = np.random.random((10, 30)) radontea.backproject(sinogram=sino, angles=np.arange(len(sino)), count=count, max_count=max_count) assert count.value == 11 assert count.value == max_count.value
def test_2d_backproject(): sino, angles = create_test_sino(A=100, N=100) r = radontea.backproject(sino, angles, padding=True) # np.savetxt('outfile.txt', np.array(r).flatten().view(float), fmt="%.8f") reffile = pathlib.Path(__file__).parent / "data" / "2d_backproject.txt" ref = np.loadtxt(str(reffile)) assert np.allclose(np.array(r).flatten().view(float), ref)
def test_2d_backproject(): myname = sys._getframe().f_code.co_name print("running ", myname) sino, angles = create_test_sino(A=100, N=100) r = radontea.backproject(sino, angles, padding=True) r2 = radontea._Back.backproject(sino, angles, padding=True) # np.savetxt('outfile.txt', np.array(r).flatten().view(float), fmt="%.8f") assert np.allclose(r, r2) assert np.allclose(np.array(r).flatten().view(float), results[myname])
from matplotlib import pylab as plt import numpy as np import radontea from radontea.logo import get_original N = 55 # image size A = 13 # number of sinogram angles ITA = 10 # number of iterations a ITB = 100 # number of iterations b angles = np.linspace(0, np.pi, A) im = get_original(N) sino = radontea.radon_parallel(im, angles) fbp = radontea.backproject(sino, angles) fintp = radontea.fourier_map(sino, angles).real sarta = radontea.sart(sino, angles, iterations=ITA) sartb = radontea.sart(sino, angles, iterations=ITB) im2 = (im >= (im.max() / 5)) * 255 sino2 = radontea.radon_parallel(im2, angles) fbp2 = radontea.backproject(sino2, angles) fintp2 = radontea.fourier_map(sino2, angles).real sarta2 = radontea.sart(sino2, angles, iterations=ITA) sartb2 = radontea.sart(sino2, angles, iterations=ITB) plt.figure(figsize=(8, 22)) pltkw = {"vmin": -20, "vmax": 280}
from matplotlib import pylab as plt import numpy as np import radontea from radontea.logo import get_original N = 55 # image size A = 13 # number of sinogram angles ITA = 10 # number of iterations a ITB = 100 # number of iterations b angles = np.linspace(0, np.pi, A) im = get_original(N) sino = radontea.radon_parallel(im, angles) fbp = radontea.backproject(sino, angles) fintp = radontea.fourier_map(sino, angles).real sarta = radontea.sart(sino, angles, iterations=ITA) sartb = radontea.sart(sino, angles, iterations=ITB) im2 = (im >= (im.max() / 5)) * 255 sino2 = radontea.radon_parallel(im2, angles) fbp2 = radontea.backproject(sino2, angles) fintp2 = radontea.fourier_map(sino2, angles).real sarta2 = radontea.sart(sino2, angles, iterations=ITA) sartb2 = radontea.sart(sino2, angles, iterations=ITB) plt.figure(figsize=(8, 22)) pltkw = {"vmin": -20, "vmax": 280} plt.subplot(6, 2, 1, title="original image")
import jobmanager as jm jm.decorators.decorate_module_ProgressBar(rt, decorator=jm.decorators.ProgressBarOverrideCount, interval=.1) except: pass if __name__ == "__main__": A = 70 # number of angles N = 128 # detector size x M = 24 # detector size y (number of slices) # generate random data sino0 = np.random.random((A,N)) # for 2d example sino = np.random.random((A,M,N)) # for 3d example sino[:,0,:] = sino0 angles = np.linspace(0,np.pi,A) # for both a = time.time() data0 = rt.backproject(sino0, angles) print("time on 1 core: {} s".format((time.time() - a)*M)) a = time.time() data = rt._Back_3D.backproject(sino, angles) print("time on {} cores: {} s".format(cpu_count(), time.time() - a)) assert np.sum(data0==data[:,0,:]) == N**2, "2D and 3D results don't match"
t_ImageInterp[t_Sudut] = t_XValueInterp ## Interpolasi Sudut t_YIndex = np.arange(t_ImageInterp.shape[0]) t_YIndexInterp = np.linspace(0, t_ImagePartial.shape[0] - 1, A) for t_SensorPos in range(t_ImageInterp.shape[1]): t_YValueInterp = np.interp(t_YIndexInterp, t_YIndex, t_ImageInterp[:, t_SensorPos]) # print(t_YValueInterp, ' len=', len(t_YValueInterp)) t_ImageInterp[:, t_SensorPos] = t_YValueInterp print(t_ImagePartial.shape) t_SinoPartial = radontea.radon_parallel(t_ImagePartial, t_Angles) t_Sino = radontea.radon_parallel(t_ImageInterp, t_Angles) print('Sinogram shape = ', t_Sino.shape) t_FilterBackProjection = radontea.backproject(t_Sino, t_Angles) t_SART = radontea.sart(t_Sino, t_Angles, iterations=15) # t_Reconstruction = iradon(t_Sino, filter="ramp" ,interpolation="linear", circle=True)#, theta=t_Angles) # t_Reconstruction = iradon_sart(t_Sino, theta=t_Angles, relaxation=0.01) fig, axes = plt.subplots(2, 2) ax = axes.ravel() ax[0].set_title("Original") # ax[0].imshow(image, cmap=plt.cm.Greys_r) # ax[0].imshow(t_ImageNoised[::7], cmap="jet") ax[0].imshow(t_SinoPartial[::10], cmap="jet") ax[1].imshow(t_Sino, cmap="jet") ax[2].imshow(t_FilterBackProjection, cmap="jet") ax[3].imshow(t_SART, cmap="jet")
def backpropagate_sinogram( sinogram, angles, approx, res, nm, ld=0, ): """Backpropagate a 2D or 3D sinogram Parameters ---------- sinogram: complex ndarray The scattered field data angles: 1d ndarray The angles at which the sinogram data were recorded approx: str Approximation to use, one of ["radon", "born", "rytov"] res: float Size of vacuum wavelength in pixels nm: float Refractive index of surrounding medium ld: float Reconstruction distance. Values !=0 only make sense for the Born approximation (which itself is not very usable). See the ODTbrain documentation for more information. Returns ------- ri: ndarray The 2D or 3D reconstructed refractive index """ sshape = len(sinogram.shape) assert sshape in [2, 3], "sinogram must have dimension 2 or 3" uSin = sinogram assert approx in ["radon", "born", "rytov"] if approx == "rytov": uSin = odt.sinogram_as_rytov(uSin) elif approx == "radon": uSin = odt.sinogram_as_radon(uSin) if approx in ["born", "rytov"]: # Perform reconstruction with ODT if sshape == 2: f = odt.backpropagate_2d(uSin, angles=angles, res=res, nm=nm, lD=ld) else: f = odt.backpropagate_3d(uSin, angles=angles, res=res, nm=nm, lD=ld) ri = odt.odt_to_ri(f, res, nm) else: # Perform reconstruction with OPT # works in 2d and 3d f = rt.backproject(uSin, angles=angles) ri = odt.opt_to_ri(f, res, nm) return ri