Example #1
0
if __name__ == "__main__":
    # file is tested with 4 different noise levels
    # 25, 33, 40 db
    data_dir = "../../sparse_ct/data/"
    fname = data_dir + "benchmark_ellipses/6.png"

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

    recon_sart = SartReconstructor('SART',
                                   sart_n_iter=40,
                                   sart_relaxation=0.15)
    recon_dip = DgrReconstructor(
        'DGR',
        dip_n_iter=4001,
        net='skip',
        lr=0.01,
        reg_std=1. / 100,
        w_proj_loss=1.00,
        # w_perceptual_loss=0.01,
        w_tv_loss=0.00,
        w_ssim_loss=0.00)

    img_sart = recon_sart.calc(sinogram, theta)
    recon_dip.set_for_metric(gt, img_sart, FOCUS=FOCUS, log_dir='log/')
    img_dip = recon_dip.calc(sinogram, theta)
Example #2
0
                        IRadonReconstructor,
                        SartReconstructor,
                        SartTVReconstructor)



if __name__ == "__main__":

    fname = "../data/benchmark_human/20.png"


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

    n_iter = 40
    recon_fbp = IRadonReconstructor('FBP')
    recon_sart_95 = SartReconstructor('SART95', sart_n_iter=n_iter, sart_relaxation=0.95)
    recon_sart_90 = SartReconstructor('SART90', sart_n_iter=n_iter, sart_relaxation=0.90)
    recon_sart_80 = SartReconstructor('SART80', sart_n_iter=n_iter, sart_relaxation=0.80)
    recon_sart_50 = SartReconstructor('SART50', sart_n_iter=n_iter, sart_relaxation=0.50)
    recon_sart_30 = SartReconstructor('SART30', sart_n_iter=n_iter, sart_relaxation=0.30)
    recon_sart_15 = SartReconstructor('SART15', sart_n_iter=n_iter, sart_relaxation=0.15)
    recon_sart_07 = SartReconstructor('SART07', sart_n_iter=n_iter, sart_relaxation=0.07)
    recon_sart_05 = SartReconstructor('SART05', sart_n_iter=n_iter, sart_relaxation=0.05)
    recon_sart_03 = SartReconstructor('SART03', sart_n_iter=n_iter, sart_relaxation=0.03)
    recon_sart_02 = SartReconstructor('SART02', sart_n_iter=n_iter, sart_relaxation=0.02)

    recons = [
        recon_fbp,
        recon_sart_95,
        recon_sart_90,
        recon_sart_80,
Example #3
0
def benchmark(
        images_path,
        recon,
        theta,
        noise_pow
    ):

    images=get_images(images_path)

    log_filename = 'benchmark_{recon}'.format(
        recon=recon.name
    )
    
    logging.basicConfig(
        filename='{}.log'.format(log_filename), 
        filemode='a', 
        format='%(asctime)s - %(levelname)s - %(message)s',
        level=logging.INFO
    )

    logging.warning('Starting')
    logging.warning('images: %s', images_path)
    logging.warning('n_proj: %s', len(theta))
    logging.warning('noise_pow: %s', noise_pow)

    mse_list = []
    psnr_list = []
    ssim_list = []

    for fname in images:
        gt, sinogram, theta, FOCUS = image_to_sparse_sinogram(fname,
                        channel=1, n_proj=len(theta), size=512,
                        angle1=0.0, angle2=180.0, noise_pow=noise_pow)
        # set metrics
        if type(recon) == DgrReconstructor or type(recon) == N2SelfReconstructor:
            recon_bm3d = SartReconstructor('SART', 
                            sart_n_iter=40, sart_relaxation=0.15)
            img_sart_bm3d = recon_bm3d.calc(sinogram, theta)
            recon.set_for_metric(gt, img_sart_bm3d, FOCUS=FOCUS, log_dir='../log/dip')

        recon.calc(sinogram, theta)
        mse, psnr, ssim = recon.eval(gt)
        mse_list.append(mse)
        psnr_list.append(psnr)
        ssim_list.append(ssim)
        logstr = "{}: MSE:{:.5f} PSNR:{:.5f} SSIM:{:.5f}".format(
            fname, mse, psnr, ssim
        )
        logging.info(logstr)


    logging.info('Avg: MSE:{:.5f} PSNR:{:.5f} SSIM:{:.5f}'.format(
            np.mean(mse_list), 
            np.mean(psnr_list), 
            np.mean(ssim_list)
        ))
    logging.info('Std: MSE:{:.5f} PSNR:{:.5f} SSIM:{:.5f}'.format(
            np.std(mse_list), 
            np.std(psnr_list), 
            np.std(ssim_list)
        ))
    logging.warning('Done.')
if __name__ == "__main__":

    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),
Example #5
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')
Example #6
0
def benchmark_all(recon, data_list, theta_list):
    for data in data_list:
        for theta in theta_list:
            benchmark(
                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,