Beispiel #1
0
    #fname = "../../sparse_ct/data/benchmark_ellipses/6.png"
    fname = args.fname # "../../sparse_ct/data/shepp_logan.jpg"
    res_name = fname.split('/')[-1]


    gt, sinogram, theta, FOCUS = image_to_sparse_sinogram(fname, channel=1,
            n_proj=64, size=512, angle1=0.0, angle2=180.0, noise_pow=39.0 )

    dgr_iter = 4001
    sart_iter = 40

    recon_fbp = IRadonReconstructor('FBP')
    recon_sart = SartReconstructor('SART', sart_n_iter=sart_iter, sart_relaxation=0.15)
    recon_sart_tv = SartTVReconstructor('SART+TV', 
                                sart_n_iter=sart_iter, sart_relaxation=0.15,
                                tv_weight=0.8, tv_n_iter=100)

    recon_dip1 = DgrReconstructor('DGR1',
                                dip_n_iter=dgr_iter, 
                                net='skip',
                                lr=0.01,
                                reg_std=1./100,
                                w_proj_loss=1.00,
                                # w_perceptual_loss=0.01,
                                w_tv_loss=0.0,
                                w_ssim_loss=0.00
                            )
    recon_dip2 = DgrReconstructor('DGR2',
                                dip_n_iter=dgr_iter, 
                                net='skip',
Beispiel #2
0
def test(fname, label, n_proj=32, noise_pow=25.0):

    
    dgr_iter = 4000
    lr = 0.01
    net = 'skip'
    noise_std = 1./100

    gt, sinogram, theta, FOCUS = image_to_sparse_sinogram(fname,
                                    channel=1, n_proj=n_proj, size=512,
                                    angle1=0.0, angle2=180.0, noise_pow=noise_pow)

    logging.warning('Starting')
    logging.warning('fname: %s %s',label, fname)
    logging.warning('n_proj: %s', n_proj)
    logging.warning('noise_pow: %s', noise_pow)
    logging.warning('dgr_n_iter: %s', dgr_iter)
    logging.warning('dgr_lr: %s', lr)
    logging.warning('dgr_net: %s', net)
    logging.warning('dgr_noise_std: %s', noise_std)

    recons = [
        IRadonReconstructor('FBP'),
        SartReconstructor('SART', sart_n_iter=40, sart_relaxation=0.15),
        SartTVReconstructor('SART+TV', 
                                    sart_n_iter=40, sart_relaxation=0.15,
                                    tv_weight=0.5, tv_n_iter=100),
        SartBM3DReconstructor('SART+BM3D', 
                                    sart_n_iter=40, sart_relaxation=0.15,
                                    bm3d_sigma=0.5),    
        DgrReconstructor('DIP_1.00_0.00_0.00_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=1.0,
                         w_perceptual_loss=0.0,
                         w_tv_loss=0.0
                         ),
        DgrReconstructor('DIP_0.99_0.01_0.00_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.99,
                         w_perceptual_loss=0.01,
                         w_tv_loss=0.0
                         ),
        DgrReconstructor('DIP_0.90_0.10_0.00_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.90,
                         w_perceptual_loss=0.10,
                         w_tv_loss=0.0
                         ),
        DgrReconstructor('DIP_0.50_0.50_0.00_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.5,
                         w_perceptual_loss=0.5,
                         w_tv_loss=0.0
                         ),
        DgrReconstructor('DIP_0.10_0.90_0.00_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.10,
                         w_perceptual_loss=0.90,
                         w_tv_loss=0.0
                         ),
        DgrReconstructor('DIP_0.01_0.99_0.00_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.01,
                         w_perceptual_loss=0.99,
                         w_tv_loss=0.0
                         ),
        DgrReconstructor('DIP_0.00_1.00_0.00_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.0,
                         w_perceptual_loss=1.0,
                         w_tv_loss=0.0
                         ),
        DgrReconstructor('DIP_0.99_0.00_0.01_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.99,
                         w_perceptual_loss=0.0,
                         w_tv_loss=0.01
                         ),
        DgrReconstructor('DIP_0.90_0.00_0.10_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.9,
                         w_perceptual_loss=0.0,
                         w_tv_loss=0.1
                         ),
        DgrReconstructor('DIP_0.50_0.00_0.50_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.5,
                         w_perceptual_loss=0.0,
                         w_tv_loss=0.5
                         ),
        DgrReconstructor('DIP_0.10_0.00_0.90_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.1,
                         w_perceptual_loss=0.0,
                         w_tv_loss=0.9
                         ),
        DgrReconstructor('DIP_0.01_0.00_0.99_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.01,
                         w_perceptual_loss=0.0,
                         w_tv_loss=0.99
                         ),
        DgrReconstructor('DIP_0.00_0.00_1.0_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.00,
                         w_perceptual_loss=0.0,
                         w_tv_loss=1.0
                         ),



        DgrReconstructor('DIP_0.33_0.33_0.33_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.33,
                         w_perceptual_loss=0.33,
                         w_tv_loss=0.33
                         ),
        DgrReconstructor('DIP_0.8_0.10_0.10_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.8,
                         w_perceptual_loss=0.1,
                         w_tv_loss=0.1
                         ),
        DgrReconstructor('DIP_0.98_0.01_0.01_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.98,
                         w_perceptual_loss=0.01,
                         w_tv_loss=0.01
                         ),

        DgrReconstructor('DIP_0.10_0.80_0.10_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.10,
                         w_perceptual_loss=0.80,
                         w_tv_loss=0.10
                         ),
        DgrReconstructor('DIP_0.01_0.98_0.01_0.00',
                         dip_n_iter=dgr_iter,
                         net=net,
                         lr=lr,
                         reg_std=noise_std,
                         w_proj_loss=0.01,
                         w_perceptual_loss=0.98,
                         w_tv_loss=0.01
                         ),

    ]

    img_sart_bm3d = recons[3].calc(sinogram, theta)

    imgs = []
    for recon in recons:
        if type(recon) == DgrReconstructor:
            recon.set_for_metric(gt, img_sart_bm3d, FOCUS=FOCUS, log_dir='../log/dip')
        imgs.append(recon.calc(sinogram))
        mse, psnr, ssim = recon.eval(gt)
        recon.save_result()
        logstr = "{}: MSE:{:.5f} PSNR:{:.5f} SSIM:{:.5f}".format(
            recon.name, mse, psnr, ssim
        )
        logging.info(logstr)

    plot_grid([gt] + imgs,
              FOCUS=FOCUS, save_name=label+'.png', dpi=500)

    logging.warning('Done. Results saved as %s', label+'.png')
    fname = "../data/ct1.jpg"

    gt, sinogram, FOCUS = image_to_sparse_sinogram(fname,
                                                   channel=1,
                                                   n_proj=32,
                                                   size=512,
                                                   noise_pow=25.0)

    n_iter = 40

    recons = [
        IRadonReconstructor('FBP'),
        SartReconstructor('SART', sart_n_iter=n_iter, sart_relaxation=0.15),
        SartTVReconstructor('SART+TVw0.2',
                            sart_n_iter=n_iter,
                            sart_relaxation=0.15,
                            tv_weight=0.2,
                            tv_n_iter=100),
        SartTVReconstructor('SART+TVw0.5',
                            sart_n_iter=n_iter,
                            sart_relaxation=0.15,
                            tv_weight=0.5,
                            tv_n_iter=100),
        SartTVReconstructor('SART+TVw0.8',
                            sart_n_iter=n_iter,
                            sart_relaxation=0.15,
                            tv_weight=0.8,
                            tv_n_iter=100),
        SartTVReconstructor('SART+TVw0.95',
                            sart_n_iter=n_iter,
                            sart_relaxation=0.15,
Beispiel #4
0
                data,
                recon,
                theta,
                40.0
            )



recon_fbp = IRadonReconstructor('FBP')

recon_sart = SartReconstructor('SART', 
                        sart_n_iter=40, 
                        sart_relaxation=0.15)

recon_sart_tv = SartTVReconstructor('SART+TVw0.9',
                        sart_n_iter=40, sart_relaxation=0.15,
                        tv_weight=0.9, tv_n_iter=100)
recon_sart_bm3d = SartBM3DReconstructor('SART+BM3Ds0.35', 
                        sart_n_iter=40, sart_relaxation=0.15,
                        bm3d_sigma=0.35)

recon_dgr = DgrReconstructor('DGR_0.80_0.00_0.10_0.10', 
                        dip_n_iter=4001, 
                        net='skip',
                        lr=0.01,
                        reg_std=1./100,
                        w_proj_loss=0.80,
                        w_perceptual_loss=0.00,
                        w_tv_loss=0.10,
                        w_ssim_loss=0.10)
recon_rdgr = DgrReconstructor('RDGR_1.00_0.00_0.00',