Ejemplo n.º 1
0
from sparse_ct.reconstructor_2d import (
                        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,
Ejemplo n.º 2
0
                                        SartBM3DReconstructor)

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,
Ejemplo n.º 3
0
                                                         noise_pow=33.0)

# for i in range(100):
# fname = random.choice(file_list_train)
# gt, sinogram, theta, FOCUS = image_to_sparse_sinogram(fname, channel=1,
#         n_proj=128, size=512, angle1=0.0, angle2=180.0, noise_pow=12.0 )

# plt.figure()
# plt.imshow(sinogram, cmap='gray')#, vmin=0.0, vmax=1.0)
# plt.figure()
# plt.imshow(gt, cmap='gray', vmin=0.0, vmax=1.0)
# plt.figure()
# plt.imshow(iradon(sinogram, theta=theta), cmap='gray')
# plt.show()

recon_fbp = IRadonReconstructor('FBP')
fbp_img = recon_fbp.calc(sinogram, theta)

imgs = [
    gt,
    fbp_img,
    gt,
    fbp_img,
    gt,
    fbp_img,
]

# plot_grid(
#         imgs, FOCUS=None, show=True, number_of_rows=3
# )
# plot_grid(
Ejemplo n.º 4
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')