예제 #1
0
def _main():

    # Create phantom
    l = load_lena()
    ph = portal.utils.misc.phantom_mask(l)

    # Create Projector and Backprojector
    npx = l.shape[0]
    nangles = 80
    AST = portal.operators.tomography.AstraToolbox(npx, nangles)

    # Configure the TV regularization
    Lambda = 5.0

    # Configure the optimization algorithm (Chambolle-Pock for TV min)
    K = lambda x : AST.proj(x)
    Kadj = lambda x : AST.backproj(x, filt=True)
    n_it = 101

    # Run the algorithm to reconstruct the sinogram
    sino = K(ph)
    en, res = portal.algorithms.chambollepock.chambolle_pock_tv(sino, K, Kadj, Lambda, L=22.5, n_it=301, return_all=True)

    # Display the result, compare to FBP
    res_fbp = Kadj(sino)
    portal.utils.misc.my_imshow((res_fbp, res), (1,2), cmap="gray", nocbar=True)
    scipy.misc.imsave("lena_tomo_fbp.png", res_fbp)
    scipy.misc.imsave("lena_tomo_tv.png", res)
예제 #2
0
def _main(CASE, DO_RETURN_ALL):

    l = load_lena()
    SAVE = False


    if CASE == 1: # Denoising (Gaussian noise)

        pc = 0.3
        lb = l + np.random.rand(l.shape[0], l.shape[1])*l.max() * pc
        Lambda = 17.

        # With custom C-P
        #~ res = chambolle_pock(lb, Lambda, 101)
        Id = lambda x : x
        K = Id
        Kadj = Id
        res  = portal.algorithms.chambollepock.chambolle_pock_tv(lb, K, Kadj, Lambda, L= 3.5, n_it=151, return_all=DO_RETURN_ALL)
        if DO_RETURN_ALL: res = res[1]
        portal.utils.misc.my_imshow([lb, res], shape=(1,2), cmap="gray")
        if SAVE:
            scipy.misc.imsave("lena_gaussian_noise.png", lb)
            scipy.misc.imsave("lena_gaussian_noise_cp.png", res)

    if CASE == 2: # deblurring (Gaussian blur)

        sigma = 2.6
        # Define the operator A and its adjoint
        gaussian_kernel = portal.utils.misc.gaussian1D(sigma)
        Blur = portal.operators.convolution.ConvolutionOperator(gaussian_kernel)
        A = lambda x : Blur*x
        Aadj = lambda x : Blur.adjoint() * x

        # Create the blurred image
        lb = A(l)

        Lambda = 0.03
        res  = portal.algorithms.chambollepock.chambolle_pock_tv(lb, A, Aadj, Lambda, n_it=801, return_all=DO_RETURN_ALL)
        if DO_RETURN_ALL: res = res[1]
        portal.utils.misc.my_imshow([lb, res], shape=(1,2), cmap="gray")
        if SAVE:
            scipy.misc.imsave("lena_gaussian_blur.png", lb)
            scipy.misc.imsave("lena_gaussian_blur_cp.png", res)


    if CASE == 3: # denoising (salt & pepper noise)

        lb = sp_noise(l, 0.1, 0.1)
        Lambda = 0.7
        Id = lambda x : x
        A = Id
        Aadj = Id

        res  = portal.algorithms.chambollepock.chambolle_pock_l1_tv(lb, A, Aadj, Lambda, n_it=1001, return_all=DO_RETURN_ALL)
        if DO_RETURN_ALL: res = res[1]
        portal.utils.misc.my_imshow([lb, res], shape=(1,2), cmap="gray")
        if SAVE:
            scipy.misc.imsave("lena_sp_noise.png", lb)
            scipy.misc.imsave("lena_sp_noise_cp.png", res)
        # Here many iterations are required.
        # Warning : isotropic TV is zero at the beginning ; this is an entirely non-smooth problem !

    if CASE == 4: # tomographic reconstruction with TV-L1
        n_proj = 80
        tomo = portal.operators.tomography.AstraToolbox(l.shape[0], n_proj)
        A = lambda x : tomo.proj(x)
        Aadj = lambda x : tomo.backproj(x, filt=True)
        portal.operators.tomography.clipCircle(l)
        sino = A(l) * 1.5708/n_proj

        Lambda = 0.1
        res  = portal.algorithms.chambollepock.chambolle_pock_tv(sino, A, Aadj, Lambda, L=2.5e1, n_it=301, return_all=DO_RETURN_ALL)
        if DO_RETURN_ALL: res = res[1]
        fbp = Aadj(sino)
        #
        portal.operators.tomography.clipCircle(fbp)
        portal.operators.tomography.clipCircle(res)
        #
        portal.utils.misc.my_imshow([fbp, res], shape=(1,2), cmap="gray")
예제 #3
0
파일: zoom.py 프로젝트: pierrepaleo/portal
def bin2(im):
    return (im[::2, ::2] + im[1::2, ::2] + im[::2, 1::2] + im[1::2, 1::2])/2.

def antibin2(im):
    res = np.zeros((2*im.shape[0], 2*im.shape[1]))
    res[::2, ::2] = im
    res[::2, 1::2] = im
    res[1::2, ::2] = im
    res[1::2, 1::2] = im
    return res/2.


if __name__ == '__main__':

    l = load_lena()

    # 2-zoom
    #~ K = bin2
    #~ Kadj = antibin2

    # 4-zoom
    K = lambda x : bin2(bin2(x))
    Kadj = lambda x : antibin2(antibin2(x))

    lb = K(l) # Use lb = l  instead of lb = K(l)  for "true" digital zooming of lena (slower !)

    '''
    # TV-zooming
    #------------
    Lambda = 0.5