def test_project():
    N=100
    x=modified_shepp_logan((N,N,3))[:,:,1]
    x=numpy.array(x)
    rp=ref.project(x)
    ip=opencl.project(x)
    assert is_equal(rp,ip)
Esempio n. 2
0
def generate_phantom_sinogram(size, nang):
    dir_name = get_strorage_directory(size, nang)
    phantom_image = os.path.join(dir_name, 'phantom.png')
    sinogramm_image = os.path.join(dir_name, 'sinogramm.png')
    phantom_file = os.path.join(dir_name, 'phantom.txt')
    sinogramm_file = os.path.join(dir_name, 'sinogramm.txt')

    if not os.path.isdir(dir_name):
        ph = phantom.modified_shepp_logan(shape=(size, size, 3))[:, :, 1]
        ph = np.array(ph, dtype='float32')
        angles = np.arange(0, 180, 180.0 / nang).astype('float32')
        s, a = genrate_sinogam(ph, angles)

        try:
            os.mkdir(dir_name)
        except OSError:
            pass

        imsave(phantom_image, ph, cmap=plt.cm.Greys_r)
        imsave(sinogramm_image, s, cmap=plt.cm.Greys_r)

        np.savetxt(phantom_file, ph)
        np.savetxt(os.path.join(dir_name, 'ang.txt'), a)
        np.savetxt(sinogramm_file, s)

    return {'phantom': phantom_file, 'sinogramm': sinogramm_file,
            'sinogramm_image': sinogramm_image, 'phantom_image': phantom_image}
def test_backproject():
    N=50
    x=modified_shepp_logan((N,N,3))[:,int(N/2),1]
    x=numpy.array(x)
    rbp=ref.back_project(x)
    obp=ocv.back_project(x)
    assert is_equal(rbp,obp)
def test_project():
    N=50
    x=modified_shepp_logan((N,N,3))[:,:,1]
    x=numpy.array(x)
    rp=ref.project(x)
    op=ocv.project(x)
    assert is_equal(rp,op)
def test_project():
    N=50
    x=modified_shepp_logan((N,N,3))[:,:,1]
    x=numpy.array(x)
    rp=ref.project(x)
    ip=ispmd.project(x)
#    import pylab
#    pylab.figure()
#    pylab.subplot(211)
#    pylab.plot(rp)
#    pylab.subplot(212)
#    pylab.plot(ip)
#    pylab.show()
    assert is_equal(rp,ip)
def test_backproject():
    N=50
    x=modified_shepp_logan((N,N,3))[:,int(N/2),1]
    x=numpy.array(x)
    rbp=ref.back_project(x)
    ibp=ispmd.back_project(x)
#    pylab.figure()
#    pylab.subplot(121)
#    pylab.imshow(ibp)
#    pylab.colorbar()
#    pylab.subplot(122)
#    pylab.imshow(rbp)
#    pylab.colorbar()
#    pylab.show()
    assert is_equal(rbp,ibp)
Esempio n. 7
0
def bencmark_backprojection(sizes):
    bencmark_res={}
    counts=10
    functions={'ocv.back_project':ocv.back_project,
               'ispmd.back_project':ispmd.back_project,
               'ref.back_project':ref.back_project}
    for size in sizes:
        x=phantom.modified_shepp_logan((size,size,3))[:,:,1]
        x=ref.project(x)
        for func_name in functions:
            func=functions[func_name]
            t=time.time()
            for c in range(counts):
                y=func(x)
            btime=(time.time()-t)/counts
            if not func_name in bencmark_res:
                bencmark_res[func_name]=[]
            bencmark_res[func_name].append({'size':size,'time':btime})
    return bencmark_res
def test_rotate_square():
    N=501
    x=modified_shepp_logan((N,N,3))[:,:,1]
    x=numpy.array(x)
    for angle in [0.0, 10.0,45.0,90.0,150.0,180.0,210.0]:
        r_rot=ref.rotate_square(x,angle)
        o_rot=ocv.rotate_square(x,angle)
        mssim=MSSIM(r_rot,o_rot,16)
        print angle,mssim.min()
        if not (numpy.min(mssim)>0.90).all():
            pylab.figure()
            pylab.subplot(121)
            pylab.imshow(mssim)
            pylab.colorbar()
            pylab.subplot(122)
            pylab.imshow(r_rot-o_rot)
            pylab.colorbar()
            pylab.show()
            assert False
def test_rotate_square():
    N=501
    x=modified_shepp_logan((N,N,3))[:,:,1]
    x=numpy.array(x)
    for angle in [0.0, 10.0,45.0,90.0,150.0,180.0,210.0]:
        r_rot=ref.rotate_square(x,angle)
        i_rot=ispmd.rotate_square(x,angle)
        mssim=MSSIM(r_rot,i_rot,16)
        mssim=scipy.ndimage.median_filter(mssim,3)
        print angle,mssim.min()
        if not (numpy.min(mssim)>0.9).all():
            pylab.figure()
            pylab.subplot(121)
            pylab.imshow(mssim)
            pylab.colorbar()
            pylab.subplot(122)
            pylab.imshow(r_rot-i_rot)
            pylab.colorbar()
            pylab.show()
            assert False
Esempio n. 10
0
def test_sart():
    size = 1024
    angles = numpy.arange(0, 180, 1.0, dtype="float32")
    x = modified_shepp_logan((size, size, 3))[:, :, 1]
    x = numpy.array(x)
    sinogram, angles = genrate_sinogam_ref(x, angles)
    t = time.time()
    for i in range(32):
        res = sart(sinogram, angles)
    print "Tomographic reconstruction: " + str(time.time() - t)

    import pylab

    pylab.subplot(121)
    pylab.imshow(x)
    pylab.colorbar()
    pylab.subplot(122)
    pylab.imshow(res, vmin=0, vmax=1)
    pylab.colorbar()
    pylab.show()
Esempio n. 11
0
def bencmark_rotation(sizes,angles):
    bencmark_res={}
    counts=10
    functions={'ocv.rotate_square':ocv.rotate_square,
               'ispmd.rotate_square':ispmd.rotate_square,
#               'ref.rotate_square':ref.rotate_square
            }
    for size in sizes:
        x=phantom.modified_shepp_logan((size,size,3))[:,:,1]
        x=numpy.array(x)
        for func_name in functions:
            func=functions[func_name]
            for angle in angles:
                t=time.time()
                for c in range(counts):
                    y=func(x,angle)
                btime=(time.time()-t)/counts
                if not func_name in bencmark_res:
                    bencmark_res[func_name]=[]
                bencmark_res[func_name].append({'size':size,'time':btime,'angle':angle})
    return bencmark_res