def cyto_downsample():
    """"""

    f_ident = 'cyto_sim_{:0>3}.tif'
    in_main_path = util.ptjoin(util.SIM_DATA, 'cyto_sim_full')

    res_path_add = 'res_[{0[0]:.1f},{0[1]:.1f},{0[2]:.1f}]'

    out_path_add = 'downsample_{}'

    path_in = util.ptjoin(util.SIM_DATA, 'cyto_sim_full',
                          res_path_add.format([0.1, 0.1, 0.1]))
    path_out = util.ptjoin(
        util.SIM_DATA, 'cyto_sim_full',
        out_path_add.format(res_path_add.format([0.2, 0.2, 0.2])))

    in_stack = util.stack_loader.read_image_stack(path_in, f_ident, meta=False)
    in_meta = util.stack_loader.read_meta_data_only(path_in, f_ident)

    cur_shape = in_stack.shape
    new_shape = [1 + (csh - 1) / 2 for csh in cur_shape]
    arr_hyb = in_stack.copy()
    for dim in range(3):
        slic_ind1 = [
            slice(0, -1, 2) if sl_ind == dim else slice(None, None, 1)
            for sl_ind in range(3)
        ]
        slic_ind2 = [
            slice(1, None, 2) if sl_ind == dim else slice(None, None, 1)
            for sl_ind in range(3)
        ]
        slic_ind3 = [
            slice(2, None, 2) if sl_ind == dim else slice(None, None, 1)
            for sl_ind in range(3)
        ]
        arr_hyb = 0.25 * arr_hyb[slic_ind1] + 0.5 * arr_hyb[
            slic_ind2] + 0.25 * arr_hyb[slic_ind3]

    in_meta.max_v = arr_hyb.max()
    out_stack = (255. * arr_hyb / arr_hyb.max()).astype('uint8')

    in_meta.size = new_shape
    in_meta.path = path_out
    in_meta.resolution = [0.2, 0.2, 0.2]
    in_meta.comment = in_meta.comment + '; Downsampled'

    util.stack_loader.write_image_stack(out_stack,
                                        path_out,
                                        f_ident,
                                        0,
                                        meta_data=in_meta.toList())
Exemple #2
0
def _readMeta(path, f_ident):
    """"""

    f_name = util.removeFileEnding(f_ident.format('META')) +'.txt'

    if os.path.isfile(util.ptjoin(path, f_name)):
        meta = []
        with open(util.ptjoin(path, f_name)) as handler:
            for lin in handler:
                meta.append(lin)

        return meta
    else:
        return None
Exemple #3
0
def main():

    test_path = util.ptjoin(util.MICRO_DATA, 'test_crops_17.08.2017')
    f_ident = 'B21_3525_test_psf_mode_LE01_R01_Slice{:0>2}_00_30_crop.tif'

    reg = im_reg.Linear_Registrator(test_path,
                                    f_ident,
                                    n_min=1,
                                    max_translation=[44, 44],
                                    output_shape=[256, 256])
    reg.calcTranslation()
    reg.translate()

    reg.writeImageStack(util.ptjoin(test_path, 'aligned'), f_ident)
Exemple #4
0
def read_meta_data_only(path, f_ident = None):
    """"""

    if f_ident is None:
        dir_content = os.listdir(path)
        dir_content = [f for f in dir_content if os.path.isfile(util.ptjoin(path, f)) and util.has_file_ending(f, 'txt')]
        f_name = dir_content[0]
    else:
        f_name = util.removeFileEnding(f_ident.format('META')) + '.txt'

    meta = MetaData()
    meta.loadFromFile(util.ptjoin(path, f_name))
    
    return meta
Exemple #5
0
def analyze_recon():
    
    recon_path = util.MICRO_RECON
    
    sub_paths = ['4082', '4083', '4084', '4085']
    
    f_ident = 'Richardson-Lucy_{:0>4}_{:0>3}.tif'
    
    
    #recon_array = np.array((1350, 1600, 120))
    
    recon_raw = []
    
    for sub in sub_paths:
        
        cur_path = util.ptjoin(recon_path, sub)
        tmp_stack = sl.read_image_stack(cur_path, f_ident.format(sub, '{:0>3}'), 0, 30)
        print(tmp_stack.shape)
        recon_raw.append(tmp_stack)
        
    recon_array = np.zeros((recon_raw[0].shape[0], recon_raw[0].shape[1], 120))
    
    recon_array[:,:,0:30] = recon_raw[0][:,:,:]
    recon_array[:,:,30:60] = recon_raw[1][:,:,:]
    recon_array[:,:,60:90] = recon_raw[2][:,:,:]
    recon_array[:,:,90:120] = recon_raw[3][:,:,:]
    
    util.imshow3D_slice(recon_array[256:512,256:512,:], center_coord=[90,90,80], show_slice_lines=True, cmap='gray')
Exemple #6
0
def createGaussSimpleBatch():
    """"""
    size = [1.6, 1.6, 1.6]
    #resolution = [[0.1, 0.1, 0.1],[0.2,0.2,0.2]]
    resolution = [[0.4, 0.4, 0.4], [0.8, 0.8, 0.8]]
    sig_list = [0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5]
    f_ident = 'psf_gauss_simple_{:0>3}.tif'

    for res in resolution:
        for sig in sig_list:
            path = util.ptjoin(
                util.SIM_PSF, 'odd', 'gauss_simple_sig-{:.2f}'.format(sig),
                'res_[{0[0]:.1f},{0[1]:.1f},{0[2]:.1f}]'.format(res))
            psf_gauss_simple = {'sigma': sig}

            psf_simu = pg.PSF_Generator(size,
                                        res,
                                        psf_type='positive',
                                        psf_model='gaussian_simple',
                                        psf_oddity='odd',
                                        name='GaussianPSF',
                                        comment='FifthIteration',
                                        psf_params=psf_gauss_simple)
            psf_simu.createPSF(oversampling=5)
            psf_simu.initSaveParameters(path, f_ident, overwrite=True)
            psf_simu.saveSolution()
Exemple #7
0
def createGaussSimple():
    """"""

    size = [1.6, 1.6, 1.6]
    resolution = [0.1, 0.1, 0.1]

    sig = 0.3

    psf_gauss_simple = {'sigma': sig}

    f_ident = 'psf_gauss_simple_{:0>3}.tif'
    path = util.ptjoin(
        util.SIM_PSF, 'gauss_simple_sig-{:.2f}'.format(sig),
        'res_[{0[0]:.1f},{0[1]:.1f},{0[2]:.1f}]'.format(resolution))

    psf_simu = pg.PSF_Generator(size,
                                resolution,
                                psf_type='positive',
                                psf_model='gaussian_simple',
                                psf_oddity='even',
                                name='GaussianPSF',
                                comment='SecondIteration',
                                psf_params=psf_gauss_simple)
    psf_simu.createPSF()
    psf_simu.initSaveParameters(path, f_ident, overwrite=True)
    psf_simu.saveSolution()

    [fig, ani] = v_util.imshow3D_ani(psf_simu.out, scale_log=True)
    plt.show()
Exemple #8
0
def createDefocusPSF():
    """"""

    #size = [6.2, 6.2, 6.4]
    size = [1.6, 1.6, 6.4]
    resolution = [0.1, 0.1, 0.1]

    sig = .05
    zi = 2000.
    K = 400.
    psf_defocus_params = {'sigma': sig, 'zi': zi, 'K': K}

    f_ident = 'psf_defocus_{:0>3}.tif'
    path = util.ptjoin(
        util.SIM_PSF,
        'defocussing_sig-{:.2f}_zi-{:.0f}_K-{:.0f}'.format(sig, zi, K),
        'res_[{0[0]:.1f},{0[1]:.1f},{0[2]:.1f}]'.format(resolution))

    psf_simu = pg.PSF_Generator(size,
                                resolution,
                                psf_type='positive',
                                psf_model='defocus',
                                psf_oddity='odd',
                                name='DefocusPSF',
                                comment='ThirdIteration',
                                psf_params=psf_defocus_params)
    psf_simu.createPSF(oversampling=5)

    psf_simu.initSaveParameters(path, f_ident, overwrite=True)
    psf_simu.saveSolution()
Exemple #9
0
def createGaussPSF():
    """"""
    size = [3.2, 3.2, 3.2]
    resolution = [0.1, 0.1, 0.1]

    sig0 = 0.15
    sig1 = 0.
    sig2 = 0.22

    psf_gauss_params = {'sigma_0': sig0, 'sigma_1': sig1, 'sigma_2': sig2}

    f_ident = 'psf_gauss_{:0>3}.tif'
    path = util.ptjoin(
        util.SIM_PSF,
        'gauss_sig0-{:.2f}_sig1-{:.2f}_sig2-{:.2f}'.format(sig0, sig1, sig2),
        'res_[{0[0]:.1f},{0[1]:.1f},{0[2]:.1f}]'.format(resolution))

    psf_simu = pg.PSF_Generator(size,
                                resolution,
                                psf_type='positive',
                                psf_model='gaussian',
                                psf_oddity='odd',
                                name='GaussianPSF',
                                comment='SecondIteration',
                                psf_params=psf_gauss_params)
    psf_simu.createPSF()
    psf_simu.initSaveParameters(path, f_ident, overwrite=True)
    psf_simu.saveSolution()

    [fig, ani] = v_util.imshow3D_ani(psf_simu.out, scale_log=True)
    plt.show()
Exemple #10
0
def _det_nmin_img_count(path, f_ident):
    """"""
    f_ident = util.removeFileEnding(f_ident)
    f_ident_beg, f_ident_end = f_ident.split('{')
    f_ident_end = f_ident_end.split('}')[1][::-1]
    
    file_listings = [fil for fil in os.listdir(path) if os.path.isfile(util.ptjoin(path, fil))]
    
    len_beg = len(f_ident_beg)
    len_end = len(f_ident_end)
    
    nums = []
    
    for fil in file_listings:
        fil = util.removeFileEnding(fil)
        
        if fil[:len_beg] == f_ident_beg and fil[-1:-1-len_end:-1] == f_ident_end:
            if len_end == 0:
                index = slice(len_beg, None, None)
            else:
                index = slice(len_beg,-len_end, None)
            t_str = fil[index]
            if t_str == 'META':
                continue
            else:
                nums.append(int(t_str))
    
    nums.sort()
    
    
    return [nums[0], len(nums)]
Exemple #11
0
def _writeMeta(meta, path, f_ident):
    """"""
    f_name = f_ident.format('META')

    f_name = util.removeFileEnding(f_name) + '.txt'

    with open(util.ptjoin(path, f_name), 'w') as handler:
        for lin in meta:
            handler.write(lin+'\n')
def main():
    """"""
    test_gr_truth_path = util.ptjoin(util.SIM_DATA, 'cyto_sim_full',
                                     'full_crop_0_0_res_[0.2,0.2,0.2]')
    test_gr_truth_fident = 'cyto_sim_{:0>3}.tif'
    test_conv_path = util.ptjoin(util.SIM_CONVOLUTED,
                                 'cyto_gauss_simple_sig-0.50',
                                 'full_crop_0_0_res_[0.2,0.2,0.2]')
    test_conv_fident = 'cyto_conv_gauss_simple_{:0>3}.tif'
    #test_psf_path = util.ptjoin(util.SIM_PSF, 'odd', 'gauss_simple_sig-0.50', 'res_[0.2,0.2,0.2]')
    test_psf_path = util.ptjoin(util.SIM_PSF, 'even', 'gauss_simple_sig-0.50',
                                'res_[0.2,0.2,0.2]')
    test_psf_fident = 'psf_gauss_simple_{:0>3}.tif'

    #test_abstract_decon(test_conv_path, test_conv_fident, test_psf_path, test_psf_fident)
    #test_single_step(test_gr_truth_path, test_gr_truth_fident, test_conv_path, test_conv_fident, test_psf_path, test_psf_fident)
    test_iterative(test_gr_truth_path, test_gr_truth_fident, test_conv_path,
                   test_conv_fident, test_psf_path, test_psf_fident)
def aligned_crops_to_256x256():
    path_psf_data_input = util.ptjoin(util.PSF_DATA_CROP,
                                      'LE01_Sample_4_100nm')

    sub_path_in = 'crop_{0}_600x600_{1:0>2}'  # 0: 1000, 1600,... , 1: 01, 02, 03, ...
    add_path = 'aligned'

    f_ident_in = 'PSF_LE01_crop_600x600_{:0>2}_Slice{:0>3}.tif'

    out_path_root = util.ptjoin(util.PSF_DATA_CROP,
                                'LE01_Sample_4_100nm_aligned_256')
    sub_path_out = 'crop_256x256_{0:0>2}_{1}'  #0: 01, 02, 03, 1: TR, TL, DR, DL

    crop_indexes = list(range(8))
    areas_slices = {
        'TR': [slice(0, 256, 1), slice(256, 512, 1)],
        'TL': [slice(0, 256, 1), slice(0, 256, 1)],
        'DR': [slice(256, 512, 1), slice(256, 512, 1)],
        'DL': [slice(256, 512, 1), slice(0, 256, 1)]
    }

    f_ident_out = 'PSF_LE01_crop_256x256_{:0>2}_Slice{:0>3}.tif'

    for cr_ind in crop_indexes:

        cur_in_path = util.ptjoin(
            path_psf_data_input,
            sub_path_in.format(1000 + cr_ind * 600, cr_ind + 1), add_path)
        cur_f_ident_in = f_ident_in.format(cr_ind + 1, '{:0>3}')
        cur_f_ident_out = f_ident_out.format(cr_ind + 1, '{2:0>3}')

        for area in areas_slices.keys():
            cur_out_path = util.ptjoin(out_path_root,
                                       sub_path_out.format(cr_ind + 1, area))

            t_crop = psf_crop.PSF_cropper(cur_in_path,
                                          cur_f_ident_in,
                                          cur_out_path,
                                          cur_f_ident_out,
                                          x_slice=areas_slices[area][0],
                                          y_slice=areas_slices[area][1])

            t_crop.crop()
Exemple #14
0
def createDefocusPSFOversampTest():
    """"""

    #size = [6.2, 6.2, 6.4]
    size = [1.6, 1.6, 3.2]
    resolution = [0.1, 0.1, 0.1]

    sig = .05
    zi = 800.
    K = 100.
    psf_defocus_params = {'sigma': sig, 'zi': zi, 'K': K}

    f_ident = 'psf_defocus_{:0>3}.tif'
    path = util.ptjoin(
        util.SIM_PSF,
        'defocussing_sig-{:.2f}_zi-{:.0f}_K-{:.0f}'.format(sig, zi, K),
        'res_[{0[0]:.1f},{0[1]:.1f},{0[2]:.1f}]'.format(resolution))

    psf_simu = pg.PSF_Generator(size,
                                resolution,
                                psf_type='positive',
                                psf_model='defocus',
                                psf_oddity='odd',
                                name='DefocusPSF',
                                comment='SecondIteration',
                                psf_params=psf_defocus_params)
    psf_simu.createPSF(oversampling=3)

    psf_simu2 = pg.PSF_Generator(size,
                                 resolution,
                                 psf_type='positive',
                                 psf_model='defocus',
                                 psf_oddity='odd',
                                 name='DefocusPSF',
                                 comment='SecondIteration',
                                 psf_params=psf_defocus_params)
    psf_simu2.createPSF(oversampling=5)

    psf_diff = psf_simu2.out - psf_simu.out

    print(psf_simu.out.shape)
    print(psf_simu2.out.shape)
    #psf_simu.initSaveParameters(path, f_ident, overwrite=True)
    #psf_simu.saveSolution()
    #[fig, ani] = v_util.imshow3D_ani(psf_simu2.out, scale_log=False)
    #[fig, ani] = v_util.imshow3D_ani(psf_simu.out, scale_log=False)
    [fig, ani] = v_util.imshow3D_ani(psf_diff, scale_log=False)

    #plt.figure()
    #plt.subplot(1,2,1)
    #plt.plot(psf_simu.out[:,32,128])
    #plt.plot(psf_simu2.out[:,32,128])
    #plt.plot(psf_diff[:,32,128])

    plt.show()
Exemple #15
0
def statistic_psf_recon():
    psf_in_path = util.ptjoin(util.PSF_RECON,
                              'LE01_Sample_4_100nm_aligned_256')

    psf_out_path = util.ptjoin(util.PSF_RECON,
                               'LE01_Sample_4_100nm_aligned_256')

    sub_in_path = 'crop_256x256_{0:0>2}_{1}'  # 0: 01,02,   1: DL DR TL TR
    sub_out_path = 'crop_256x256_stat'

    crop_indexes = range(1, 8)
    area_indexes = ['DL', 'DR', 'TL', 'TR']

    f_ident = 'PSF_LE01_crop_256x256_{:0>2}_Slice{:0>3}.tif'

    n_stack = 0
    psf_stack = np.zeros((256, 256, 160), dtype='float')

    for cr_ind in crop_indexes:

        cur_fident = f_ident.format(cr_ind, '{:0>3}')

        for area in area_indexes:

            cur_path = util.ptjoin(psf_in_path,
                                   sub_in_path.format(cr_ind, area))

            tmp_stack = sl.read_image_stack(cur_path, cur_fident, 0, 160)

            if tmp_stack.shape == (256, 256, 160):
                print('Adding to psf_stack. {} {}'.format(cr_ind, area))
                psf_stack += tmp_stack
                n_stack += 1

    print('Using {} stacks for statistics...'.format(n_stack))
    psf_stack = psf_stack / n_stack
    psf_stack = psf_stack / psf_stack.sum()

    sl.write_image_stack(psf_stack, util.ptjoin(psf_out_path, sub_out_path),
                         f_ident.format('STAT', '{:0>3}'), 0)
def create_psf_recon_sample():
    """"""

    resolution = [0.4, 0.4, 0.4]
    f_ident = 'psf_recon_{:0>3}.tif'

    save_path = util.ptjoin(
        util.SIM_DATA, 'psf_recon_full',
        'full_res_[{0[0]:.1f},{0[1]:.1f},{0[2]:.1f}]'.format(resolution))

    seed = 12345

    sim_sample = psf_recon_sample(resolution, seed)
    sim_sample.initSaveParameters(save_path, f_ident, overwrite=True)
    sim_sample.saveSolution()
def create_cyto():
    """"""
    f_ident = 'cyto_sim_{:0>3}.tif'
    save_path = util.ptjoin(util.SIM_DATA, 'data',
                            'cyto_sim_resol-[0.2,0.2,0.2]')

    resolution = [0.2, 0.2, 0.2]
    seed = 12345

    sim_sample = cyto_sim_with_inm(resolution, seed)

    sim_sample.initSaveParameters(save_path, f_ident, overwrite=True)

    #[fig,ani] = util.visu_util.imshow3D_ani(sim_sample.out)

    #util.utilities.imshow3D_slice(sim_sample.out)
    #plt.show()

    print(sim_sample.out.shape)
    #sim_sample.out = sim_sample.out[0:512,0:512,0:128]
    sim_sample.saveSolution()
Exemple #18
0
def createGaussBatch():
    """"""
    size = [3.2, 3.2, 3.2]
    #resolution = [[0.1, 0.1, 0.1],[0.2,0.2,0.2]]
    resolution = [[0.4, 0.4, 0.4], [0.8, 0.8, 0.8]]

    sig0_list = [0.05, 0.10, 0.15, 0.2, 0.3, 0.4]
    sig1_list = [0]
    sig2_list = [0.15, 0.2, 0.25, 0.3, 0.4]

    f_ident = 'psf_gauss_{:0>3}.tif'

    for res in resolution:
        for sig0 in sig0_list:
            for sig1 in sig1_list:
                for sig2 in sig2_list:
                    psf_gauss_params = {
                        'sigma_0': sig0,
                        'sigma_1': sig1,
                        'sigma_2': sig2
                    }
                    path = util.ptjoin(
                        util.SIM_PSF, 'odd',
                        'gauss_sig0-{:.2f}_sig1-{:.2f}_sig2-{:.2f}'.format(
                            sig0, sig1, sig2),
                        'res_[{0[0]:.1f},{0[1]:.1f},{0[2]:.1f}]'.format(res))

                    psf_simu = pg.PSF_Generator(size,
                                                res,
                                                psf_type='positive',
                                                psf_model='gaussian',
                                                psf_oddity='odd',
                                                name='GaussianPSF',
                                                comment='FifthIteration',
                                                psf_params=psf_gauss_params)
                    psf_simu.createPSF(oversampling=5)
                    psf_simu.initSaveParameters(path, f_ident, overwrite=True)
                    psf_simu.saveSolution()
Exemple #19
0
def createDefocusBatch():
    """"""

    size = [3.2, 3.2, 6.4]
    #resolution = [[0.1,0.1,0.1],[0.2,0.2,0.2]]
    resolution = [[0.4, 0.4, 0.4], [0.8, 0.8, 0.8]]

    sig_list = [.05, 0.1, 0.2, 0.3]
    zi_list = [800, 1000, 2000]
    K_list = [100, 200, 300, 400]

    f_ident = 'psf_defocus_{:0>3}.tif'

    for res in resolution:
        for sig in sig_list:
            for zi in zi_list:
                for K in K_list:

                    psf_defocus_params = {'sigma': sig, 'zi': zi, 'K': K}
                    path = util.ptjoin(
                        util.SIM_PSF, 'odd',
                        'defocussing_sig-{:.2f}_zi-{:.0f}_K-{:.0f}'.format(
                            sig, zi, K),
                        'res_[{0[0]:.1f},{0[1]:.1f},{0[2]:.1f}]'.format(res))

                    psf_simu = pg.PSF_Generator(size,
                                                res,
                                                psf_type='positive',
                                                psf_model='defocus',
                                                psf_oddity='odd',
                                                name='DefocusPSF',
                                                comment='FifthIteration',
                                                psf_params=psf_defocus_params)
                    psf_simu.createPSF(oversampling=5)

                    psf_simu.initSaveParameters(path, f_ident, overwrite=True)
                    psf_simu.saveSolution()
Exemple #20
0
def read_image_stack(path, f_ident, n_min = -1, img_count = -1, meta=False):
    """"""

    if n_min == -1 or img_count == -1:
        t_min, t_count = _det_nmin_img_count(path, f_ident)
        if n_min == -1:
            n_min = t_min
        if img_count == -1:
            img_count = t_count
    
    temp_img = _readImage(path, f_ident, n_min)

    ret_array = np.zeros((temp_img.shape[0], temp_img.shape[1], img_count), dtype = temp_img.dtype)
    ret_array[:,:,0] = temp_img[:,:]

    print('Reading Image Stack: n_min={}, img_count={}'.format(n_min, img_count))
    print('File Identifier: {}, Stack Path: {}'.format(f_ident, path))

    for ind in range(1, img_count):

        temp_img = _readImage(path, f_ident, ind + n_min)

        ret_array[:,:,ind] = temp_img[:,:]

    if meta:
        f_name = util.removeFileEnding(f_ident.format('META')) +'.txt'
        meta_data = MetaData()
        meta_data.loadFromFile(util.ptjoin(path, f_name))
        
        if meta_data.max_v:
            ret_array = ((meta_data.max_v/ret_array.max()) * ret_array).astype(meta_data.d_type)
        
        return [ret_array, meta_data]
    else:
        return ret_array
    
    print('Done')
def PSF_noise_additions_batch():
    """"""

    main_path = util.SIM_PSF

    #path_adds = ['odd', 'even']
    path_adds = ['odd']

    #res_list = [[0.1,0.1,0.1], [0.2,0.2,0.2]]
    #res_list = [[0.4,0.4,0.4]]
    res_list = [[0.8, 0.8, 0.8]]
    res_path_def = 'res_[{0[0]:.1f},{0[1]:.1f},{0[2]:.1f}]'

    #Defocus parameter lists

    sig_defocus_list = [.05, 0.1, 0.2, 0.3]
    zi_list = [800, 1000, 2000]
    K_list = [100, 200, 300, 400]

    defocus_noise_list = [['snr', 60.], ['snr', 30.], ['snr', 15.],
                          ['snr', 10.], ['snr', 5.], ['snr', 2.]]

    f_ident_defocus = 'psf_defocus_{:0>3}.tif'
    path_def_defocus = 'defocussing_sig-{:.2f}_zi-{:.0f}_K-{:.0f}'

    for oddity in path_adds:
        for res in res_list:
            for sig in sig_defocus_list:
                for zi in zi_list:
                    for K in K_list:
                        for noise_par in defocus_noise_list:
                            t_noise_free_path = util.ptjoin(
                                main_path, oddity,
                                path_def_defocus.format(sig, zi, K),
                                res_path_def.format(res))
                            t_new_path = util.ptjoin(
                                main_path, oddity,
                                path_def_defocus.format(sig, zi, K),
                                'res_[{0[0]:.1f},{0[1]:.1f},{0[2]:.1f}]_{1}-{2}'
                                .format(res, noise_par[0], noise_par[1]))

                            util.createAllPaths(t_new_path)

                            temp_stack = util.stack_loader.read_image_stack(
                                t_noise_free_path, f_ident_defocus, meta=True)

                            t_noise_dict = {
                                'noise_def':
                                convoluter.Noise_Adder.NOISE_DEF[noise_par[0]],
                                noise_par[0]:
                                noise_par[1]
                            }

                            temp_noise = convoluter.Noise_Adder(
                                temp_stack[0],
                                old_meta=temp_stack[1],
                                img_type='psf',
                                noise_type='gaussian',
                                noise_params=t_noise_dict,
                                debug_int=3)
                            temp_noise.addNoise()

                            temp_noise.initSaveParameters(
                                t_new_path,
                                f_ident_defocus,
                                orig_img_path=[
                                    t_noise_free_path, f_ident_defocus
                                ],
                                overwrite=True)
                            temp_noise.saveSolution()

    #Gaussian parameter lists

    sig0_list = [0.05, 0.10, 0.15, 0.2, 0.3, 0.4]
    sig1_list = [0]
    sig2_list = [0.15, 0.2, 0.25, 0.3, 0.4]

    gauss_noise_list = [['snr', 60.], ['snr', 30.], ['snr', 15.], ['snr', 10.],
                        ['snr', 5.], ['snr', 2.]]

    f_ident_gauss = 'psf_gauss_{:0>3}.tif'
    path_def_gauss = 'gauss_sig0-{:.2f}_sig1-{:.2f}_sig2-{:.2f}'

    for oddity in path_adds:
        for res in res_list:
            for sig0 in sig0_list:
                for sig1 in sig1_list:
                    for sig2 in sig2_list:
                        for noise_par in gauss_noise_list:

                            t_noise_free_path = util.ptjoin(
                                main_path, oddity,
                                path_def_gauss.format(sig0, sig1, sig2),
                                res_path_def.format(res))
                            t_new_path = util.ptjoin(
                                main_path, oddity,
                                path_def_gauss.format(sig0, sig1, sig2),
                                'res_[{0[0]:.1f},{0[1]:.1f},{0[2]:.1f}]_{1}-{2}'
                                .format(res, noise_par[0], noise_par[1]))

                            util.createAllPaths(t_new_path)

                            temp_stack = util.stack_loader.read_image_stack(
                                t_noise_free_path, f_ident_gauss, meta=True)

                            t_noise_dict = {
                                'noise_def':
                                convoluter.Noise_Adder.NOISE_DEF[noise_par[0]],
                                noise_par[0]:
                                noise_par[1]
                            }

                            temp_noise = convoluter.Noise_Adder(
                                temp_stack[0],
                                old_meta=temp_stack[1],
                                img_type='psf',
                                noise_type='gaussian',
                                noise_params=t_noise_dict,
                                debug_int=3)
                            temp_noise.addNoise()

                            temp_noise.initSaveParameters(
                                t_new_path,
                                f_ident_gauss,
                                orig_img_path=[
                                    t_noise_free_path, f_ident_gauss
                                ],
                                overwrite=True)
                            temp_noise.saveSolution()

    #Gaussian simple lists

    sig_gauss_simple_list = [0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.4, 0.5]

    gauss_simple_noise_list = [['snr', 60.], ['snr', 30.], ['snr', 15.],
                               ['snr', 10.], ['snr', 5.], ['snr', 2.]]

    f_ident_gauss_simple = 'psf_gauss_simple_{:0>3}.tif'
    path_def_gauss_simple = 'gauss_simple_sig-{:.2f}'

    for oddity in path_adds:
        for res in res_list:
            for sig in sig_gauss_simple_list:
                for noise_par in gauss_simple_noise_list:

                    t_noise_free_path = util.ptjoin(
                        main_path, oddity, path_def_gauss_simple.format(sig),
                        res_path_def.format(res))
                    t_new_path = util.ptjoin(
                        main_path, oddity, path_def_gauss_simple.format(sig),
                        'res_[{0[0]:.1f},{0[1]:.1f},{0[2]:.1f}]_{1}-{2}'.
                        format(res, noise_par[0], noise_par[1]))

                    util.createAllPaths(t_new_path)

                    temp_stack = util.stack_loader.read_image_stack(
                        t_noise_free_path, f_ident_gauss_simple, meta=True)

                    t_noise_dict = {
                        'noise_def':
                        convoluter.Noise_Adder.NOISE_DEF[noise_par[0]],
                        noise_par[0]: noise_par[1]
                    }

                    temp_noise = convoluter.Noise_Adder(
                        temp_stack[0],
                        old_meta=temp_stack[1],
                        img_type='psf',
                        noise_type='gaussian',
                        noise_params=t_noise_dict,
                        debug_int=3)
                    temp_noise.addNoise()

                    temp_noise.initSaveParameters(t_new_path,
                                                  f_ident_gauss_simple,
                                                  orig_img_path=[
                                                      t_noise_free_path,
                                                      f_ident_gauss_simple
                                                  ],
                                                  overwrite=True)
                    temp_noise.saveSolution()
def create_sub_crops_overlap():
    """"""

    f_ident = 'cyto_sim_{:0>3}.tif'
    in_main_path = util.ptjoin(util.SIM_DATA, 'cyto_sim_full')

    path_full = util.ptjoin(in_main_path, 'full_res_[0.2,0.2,0.2]')
    path_down = util.ptjoin(in_main_path, 'downsample_res_[0.2,0.2,0.2]')

    crop_diviser = 3

    crop_paths_full = [
        'full_overlap_crop_{}_{}_res_[0.2,0.2,0.2]'.format(
            i / crop_diviser, i % crop_diviser) for i in range(crop_diviser**2)
    ]
    crop_paths_down = [
        'downsampled_overlap_crop_{}_{}_res_[0.2,0.2,0.2]'.format(
            i / crop_diviser, i % crop_diviser) for i in range(crop_diviser**2)
    ]

    crop_paths_full = [util.ptjoin(in_main_path, pt) for pt in crop_paths_full]
    crop_paths_down = [util.ptjoin(in_main_path, pt) for pt in crop_paths_down]

    util.createAllPaths(crop_paths_full)
    util.createAllPaths(crop_paths_down)

    full_stack = util.stack_loader.read_image_stack(path_full,
                                                    f_ident,
                                                    meta=False)
    full_meta = util.stack_loader.read_meta_data_only(path_full, f_ident)

    t_reduced_shape = [
        sh / crop_diviser if sh % 2 == 0 else 1 + sh / crop_diviser
        for sh in full_stack.shape
    ]
    meta_comment = full_meta.comment

    for i, crop_path in enumerate(crop_paths_full):
        x_ind = i / crop_diviser
        y_ind = i % crop_diviser

        sh_bool2 = [sh % 2 == 0 for sh in t_reduced_shape]
        ind_slice = [
            slice(
                x_ind * (t_reduced_shape[0] / 2) if sh_bool2[0] else x_ind *
                ((t_reduced_shape[0] - 1) / 2),
                (x_ind + 2) * (t_reduced_shape[0] / 2) if sh_bool2[0] else 1 +
                (x_ind + 2) * (t_reduced_shape[0] - 1) / 2, 1),
            slice(
                y_ind * (t_reduced_shape[1] / 2) if sh_bool2[1] else y_ind *
                ((t_reduced_shape[1] - 1) / 2),
                (y_ind + 2) * (t_reduced_shape[1] / 2) if sh_bool2[1] else 1 +
                (y_ind + 2) * (t_reduced_shape[1] - 1) / 2, 1),
            slice(None, None, 1)
        ]

        cropped_stack = full_stack[ind_slice].copy()
        full_meta.comment = meta_comment + '; Cropped; Crop_index=[{},{}]'.format(
            x_ind, y_ind)
        util.stack_loader.write_image_stack(cropped_stack,
                                            crop_path,
                                            f_ident,
                                            0,
                                            meta_data=full_meta.toList())

    down_stack = util.stack_loader.read_image_stack(path_down,
                                                    f_ident,
                                                    meta=False)
    down_meta = util.stack_loader.read_meta_data_only(path_down, f_ident)

    t_reduced_shape = [
        sh / crop_diviser if sh % 2 == 0 else 1 + sh / crop_diviser
        for sh in down_stack.shape
    ]
    meta_comment = down_meta.comment

    for i, crop_path in enumerate(crop_paths_down):
        x_ind = i / crop_diviser
        y_ind = i % crop_diviser

        sh_bool2 = [sh % 2 == 0 for sh in t_reduced_shape]
        ind_slice = [
            slice(
                x_ind * (t_reduced_shape[0] / 2) if sh_bool2[0] else x_ind *
                ((t_reduced_shape[0] - 1) / 2),
                (x_ind + 2) * (t_reduced_shape[0] / 2) if sh_bool2[0] else 1 +
                (x_ind + 2) * (t_reduced_shape[0] - 1) / 2, 1),
            slice(
                y_ind * (t_reduced_shape[1] / 2) if sh_bool2[1] else y_ind *
                ((t_reduced_shape[1] - 1) / 2),
                (y_ind + 2) * (t_reduced_shape[1] / 2) if sh_bool2[1] else 1 +
                (y_ind + 2) * (t_reduced_shape[1] - 1) / 2, 1),
            slice(None, None, 1)
        ]

        cropped_stack = down_stack[ind_slice].copy()
        down_meta.comment = meta_comment + '; Cropped; Crop_index=[{},{}]'.format(
            x_ind, y_ind)
        util.stack_loader.write_image_stack(cropped_stack,
                                            crop_path,
                                            f_ident,
                                            0,
                                            meta_data=down_meta.toList())
def createSupCrops_forDownsample():
    """"""
    main_path = util.ptjoin(util.SIM_DATA, 'cyto_sim_full')
    res_path_add = 'downsample_res_[0.2,0.2,0.2]'
    f_ident = 'cyto_sim_{:0>3}.tif'

    out_path_add = 'cyto_sim_crop_{}_{}'

    crop_diviser = 2

    path_in = util.ptjoin(main_path, res_path_add)

    in_stack = util.stack_loader.read_image_stack(path_in, f_ident, meta=False)
    in_meta = util.stack_loader.read_meta_data_only(path_in, f_ident)

    red_shape = [sh / crop_diviser for sh in in_stack.shape]
    meta_comment = in_meta.comment

    for x_ind in range(crop_diviser):
        for y_ind in range(crop_diviser):

            cur_path_out = util.ptjoin(util.SIM_DATA,
                                       out_path_add.format(x_ind, y_ind),
                                       res_path_add)
            print('Processing path: {}').format(cur_path_out)
            util.createAllPaths(cur_path_out)

            ind_slice = [
                slice(x_ind * red_shape[0], (x_ind + 1) * red_shape[0], 1),
                slice(y_ind * red_shape[1], (y_ind + 1) * red_shape[1], 1),
                slice(None, None, 1)
            ]

            cropped_stack = in_stack[ind_slice].copy()

            in_meta.comment = meta_comment + '; Cropped; Crop_index=[{},{}]'.format(
                x_ind, y_ind)
            util.stack_loader.write_image_stack(cropped_stack,
                                                cur_path_out,
                                                f_ident,
                                                0,
                                                meta_data=in_meta.toList())

    out_path_add = 'cyto_sim_crop_overlap_{}_{}'

    for x_ind in range(crop_diviser + 1):
        for y_ind in range(crop_diviser + 1):

            cur_path_out = util.ptjoin(util.SIM_DATA,
                                       out_path_add.format(x_ind, y_ind),
                                       res_path_add)
            print('Processing path:{}'.format(cur_path_out))
            util.createAllPaths(cur_path_out)

            ind_slice = [
                slice(x_ind * (red_shape[0] / 2),
                      (x_ind + 2) * (red_shape[0] / 2), 1),
                slice(y_ind * (red_shape[1] / 2),
                      (y_ind + 2) * (red_shape[1] / 2), 1),
                slice(None, None, 1)
            ]
            print(ind_slice)
            cropped_stack = in_stack[ind_slice].copy()

            in_meta.comment = meta_comment + '; Cropped; Crop_index=[{},{}]'.format(
                x_ind, y_ind)
            util.stack_loader.write_image_stack(cropped_stack,
                                                cur_path_out,
                                                f_ident,
                                                0,
                                                meta_data=in_meta.toList())
def test_single_step(test_gr_truth_path, test_gr_truth_fident, test_conv_path,
                     test_conv_fident, test_psf_path, test_psf_fident):
    """"""

    test_gr_truth, t_meta = st_l.read_image_stack(test_gr_truth_path,
                                                  test_gr_truth_fident,
                                                  meta=True)
    test_gr_truth = test_gr_truth[0:256, 0:256, 0:128]
    test_conv, t_meta = st_l.read_image_stack(test_conv_path,
                                              test_conv_fident,
                                              meta=True)
    test_psf, t_meta = st_l.read_image_stack(test_psf_path,
                                             test_psf_fident,
                                             meta=True)

    #print(test_psf)

    print('Ground Truth Shape: {}'.format(test_gr_truth.shape))
    print('Convoluted Import Shape: {}'.format(test_conv.shape))
    print('PSF shape: {}'.format(test_psf.shape))

    test_after_conv = cn.Convoluter(test_gr_truth,
                                    test_psf,
                                    conv_method='cpx_fft',
                                    debug_int=3)
    test_after_conv.convolute()

    #test_dec = sing_st.InverseFilter(test_after_conv.out, groundTruth= test_gr_truth, psf=test_psf, solveFor= 'sample', isPsfCentered= True, cutoff= 1e-3,
    #relativeCutoff= True, cutoffInFourierDomain= True, constraints= None,
    #useCpxFFT= False, debugInt=3, compareWithTruth= True)

    #test_dec = sing_st.WienerFilter(test_after_conv.out, groundTruth= test_gr_truth, psf=test_psf, noise = 1e-2,
    #relativeNoise= True, constraints= None, useCpxFFT= False, debugInt= 3,
    #compareWithTruth= True)

    test_dec = sing_st.RegularizedTikhonov(test_after_conv.out,
                                           psf=test_psf,
                                           sample=None,
                                           groundTruth=None,
                                           solveFor='sample',
                                           isPsfCentered=True,
                                           lam=1e-3,
                                           tolerance=1e-6,
                                           constraints=None,
                                           useCpxFFT=False,
                                           debugInt=3,
                                           compareWithTruth=False)

    test_dec.prepare()
    test_dec.solve()

    save_path = util.ptjoin(util.SIM_RECON, 'test_decon_single', 'Tikhonov')
    f_ident = 'recon_wiener_{:0>3}.tif'

    util.path_declarations.createAllPaths(save_path)

    test_dec.initSaveParameters(
        save_path,
        f_ident,
        orig_img_path=[test_conv_path, test_conv_fident],
        orig_psf_path=[test_psf_path, test_psf_fident],
        orig_sample_path=[None, None],
        orig_truth_path=[test_gr_truth_path, test_gr_truth_fident],
        overwrite=False)

    test_dec.saveSolution()

    #conv = np.pad(test_after_conv.out, [[8,8],[8,8],[8,8]], mode='constant', constant_values = 0)
    #conv = test_after_conv.out.copy()
    #conv = test_after_conv.out.copy()
    #psf = np.pad(test_psf, [[120,120],[120,120],[56,56]], mode='constant', constant_values = 0)
    #psf = np.pad(test_psf, [[0,240],[0,240],[0,112]], mode='constant', constant_values = 0)

    #psf = np.pad(test_psf, [[128,128],[128,128],[64,64]], mode='constant', constant_values = 0)
    #psf = np.fft.ifftshift(psf)

    #fig, ani = util.visu_util.imshow3D_ani(psf)
    #plt.show()

    #f_conv = np.fft.fftshift(np.fft.fftn(conv))
    #f_psf = np.fft.fftshift(np.fft.fftn(np.fft.ifftshift(psf)))
    #f_psf = np.fft.fftshift(np.fft.fftn(np.fft.ifftshift(psf)))

    #mag = f_psf*f_psf.conj()
    #mag[mag < 1e-6] = 1e-6

    #f_recon = f_recon / mag

    #recon = np.fft.ifftn(np.fft.ifftshift(f_recon)).real

    #fig, ani = util.visu_util.imshow3D_ani(recon[8:256+9,8:256+9,8:128+9])
    #fig, ani = util.visu_util.imshow3D_ani(test_dec.out)
    plt.show()
Exemple #25
0
def testFISTA():
    """"""

    #gauss_single = [0.05, 0.15, 0.25, 0.5]
    gauss_single = [0.05, 0.5]
    gauss_multi = [  #[0.05, 0., 0.15],
        #[0.05, 0., 0.2],
        [0.05, 0., 0.25],
        #[0.05, 0., 0.4],
        [0.1, 0., 0.15],
        #[0.1, 0., 0.2],
        #[0.1, 0., 0.25],
        #[0.1, 0., 0.4],
        [0.2, 0., 0.15],
        #[0.2, 0., 0.2],
        [0.2, 0., 0.25]
    ]
    #[0.2, 0., 0.4]]

    defocus = []
    """
    defocus = [[0.3, 2000, 400],
               #[0.3, 2000, 200],
               [0.3, 2000, 100],
               #[0.3, 800, 400],
               [0.3, 800, 200],
               #[0.3, 800, 100],
               [0.1, 2000, 400],
               #[0.1, 2000, 200],
               #[0.1, 2000, 100],
               #[0.1, 800, 400],
               [0.1, 800, 200],
               #[0.1, 800, 100],
               [0.05, 2000, 400],
               #[0.05, 2000, 200],
               [0.05, 2000, 100],
               #[0.05, 800, 400],
               #[0.05, 800, 200],
               [0.05, 800, 100]]    
    """

    dict_paths = []

    orig_path = util.ptjoin(util.SIM_DATA, 'cyto_sim_full',
                            'full_res_[0.4,0.4,0.4]')
    orig_fident = 'cyto_sim_{:0>3}.tif'

    for fl in gauss_single:
        conv_path = 'cyto_gauss_simple_sig-{:.2f}'.format(fl)
        conv_f_ident = 'cyto_conv_gauss_simple_{:0>3}.tif'

        #conv_path = util.ptjoin(util.SIM_CONVOLUTED, path, 'full_res_[0.2,0.2,0.2]')

        psf_path = 'gauss_simple_sig-{:.2f}'.format(fl)
        psf_f_ident = 'psf_gauss_simple_{:0>3}.tif'
        #psf_path = util.ptjoin(util.SIM_PSF, 'odd', psf_path, 'res_[0.2,0.2,0.2]')

        dict_paths.append({
            'conv_path': conv_path,
            'conv_fident': conv_f_ident,
            'psf_path': psf_path,
            'psf_fident': psf_f_ident
        })

    for lis in gauss_multi:
        conv_path = 'cyto_gauss_sig0-{0[0]:.2f}_sig1-{0[1]:.2f}_sig2-{0[2]:.2f}'.format(
            lis)
        conv_f_ident = 'cyto_conv_gauss_{:0>3}.tif'

        #conv_path = util.ptjoin(util.SIM_CONVOLUTED, path, 'full_res[0.2,0.2,0.2]')

        psf_path = 'gauss_sig0-{0[0]:.2f}_sig1-{0[1]:.2f}_sig2-{0[2]:.2f}'.format(
            lis)
        psf_f_ident = 'psf_gauss_{:0>3}.tif'
        #psf_path = util.ptjoin(util.SIM_PSF, 'odd', psf_path, 'res_[0.2,0.2,0.2]')

        dict_paths.append({
            'conv_path': conv_path,
            'conv_fident': conv_f_ident,
            'psf_path': psf_path,
            'psf_fident': psf_f_ident
        })

    for lis in defocus:
        conv_path = 'cyto_defocus_sig-{0[0]:.2f}_zi-{0[1]}_K-{0[2]}'.format(
            lis)
        conv_f_ident = 'cyto_conv_defocus_{:0>3}.tif'
        #conv_path = util.ptjoin(util.SIM_CONVOLUTED, path, 'full_res[0.2,0.2,0.2]')

        psf_path = 'defocussing_sig-{0[0]:.2f}_zi-{0[1]}_K-{0[2]}'.format(lis)
        psf_f_ident = 'psf_defocus_{:0>3}.tif'
        #psf_path = util.ptjoin(util.SIM_PSF, 'odd', psf_path, 'res_[0.2,0.2,0.2]')

        dict_paths.append({
            'conv_path': conv_path,
            'conv_fident': conv_f_ident,
            'psf_path': psf_path,
            'psf_fident': psf_f_ident
        })

    orig_stack, orig_meta = util.stack_loader.read_image_stack(orig_path,
                                                               orig_fident,
                                                               meta=True)

    #lambdas = [0.8, 0.85, 0.87, 0.9, 0.92, 0.94, 0.96, 0.98, 1., 1.02, 1.04, 1.06, 1.08, 1.1, 1.13, 1.15, 1.2]

    lambdas = [0.87, 0.94, 0.98, 1., 1.02, 1.06, 1.13]

    for paths in dict_paths:

        for lam in lambdas:
            conv_path = util.ptjoin(util.SIM_CONVOLUTED, paths['conv_path'],
                                    'full_res_[0.4,0.4,0.4]')
            psf_path = util.ptjoin(util.SIM_PSF, 'odd', paths['psf_path'],
                                   'res_[0.4,0.4,0.4]')

            psf_stack, psf_meta = util.stack_loader.read_image_stack(
                psf_path, paths['psf_fident'], meta=True)
            conv_stack, conv_meta = util.stack_loader.read_image_stack(
                conv_path, paths['conv_fident'], meta=True)

            recon_path = util.ptjoin(util.SIM_RECON, 'test_FISTA',
                                     paths['conv_path'], 'res_[0.4,0.4,0.4]')
            util.createAllPaths(recon_path)
            recon_fident = 'recon_{:0>3}.tif'

            fista = wave.FISTA(conv_stack,
                               psf=psf_stack,
                               groundTruth=orig_stack,
                               iterSteps=200,
                               saveIntermediateSteps=50,
                               compareWithTruth=True,
                               debugInt=3)
            fista.initSaveParameters(recon_path, recon_fident)

            fista.prepare()
            fista.solve()
            fista.saveSolution()
def test_iterative(test_gr_truth_path, test_gr_truth_fident, test_conv_path,
                   test_conv_fident, test_psf_path, test_psf_fident):
    """"""

    test_gr_truth, t_meta = st_l.read_image_stack(test_gr_truth_path,
                                                  test_gr_truth_fident,
                                                  meta=True)
    test_gr_truth = test_gr_truth[0:256, 0:256, 0:128]
    test_conv, t_meta = st_l.read_image_stack(test_conv_path,
                                              test_conv_fident,
                                              meta=True)
    test_psf, t_meta = st_l.read_image_stack(test_psf_path,
                                             test_psf_fident,
                                             meta=True)

    #print(test_psf)

    print('Ground Truth Shape: {}'.format(test_gr_truth.shape))
    print('Convoluted Import Shape: {}'.format(test_conv.shape))
    print('PSF shape: {}'.format(test_psf.shape))

    test_after_conv = cn.Convoluter(test_gr_truth,
                                    test_psf,
                                    conv_method='cpx_fft',
                                    debug_int=3)
    test_after_conv.convolute()

    #test_dec = iterative.AbstractIterative(test_after_conv.out, psf=test_psf, sample= None, groundTruth= None, solveFor= 'sample', initialGuess= 'WienerFilter',
    #algoName= 'AbstractIterative', iterSteps= 1000,
    #errTol= 1e-5, constraints= None, isPsfCentered= True,
    #useCpxFFT= False, debugInt= 3, compareWithTruth= False)

    #test_dec = iterative.Gold(test_after_conv.out, psf=test_psf, initialGuess='WienerFilter',
    #experimentalMode=False, iterSteps=10, debugInt = 3)

    test_dec = iterative.Gold(test_after_conv.out,
                              psf=test_psf,
                              groundTruth=test_gr_truth,
                              initialGuess='WienerFilter',
                              iterSteps=10,
                              debugInt=3,
                              compareWithTruth=True,
                              saveIntermediateSteps=2)

    #test_dec = iterative.JannsonVCittert(test_after_conv.out, psf=test_psf, initialGuess='WienerFilter',
    #iterSteps=10, errTol= 1e-5, gamma= 1., constraints= None,
    #isPsfCentered =True, useCpxFFT =False, debugInt=3,
    #compareWithTruth= False, saveIntermediateSteps= 0)

    #test_dec = iterative.Landweber(test_after_conv.out, psf=test_psf, initialGuess= 'WienerFilter',
    #iterSteps=10, errTol= 1e-5, gamma=1., isPsfCentered=True, useCpxFFT=False,
    #debugInt=3, compareWithTruth=False, saveIntermediateSteps=0)

    #test_dec = iterative.RichardsonLucy(test_after_conv.out, psf=test_psf, sample =None, groundTruth =None, solveFor ='sample', initialGuess ='orig-array',
    #iterSteps =10, errTol =1e-5, p =1., constraints =None,
    #isPsfCentered =True, useCpxFFT =False, debugInt =3, compareWithTruth= False, saveIntermediateSteps= 0)

    #test_dec = iterative.StarkParker(test_after_conv.out, psf=test_psf, sample= None, groundTruth= None, solveFor= 'sample', initialGuess= 'WienerFilter',
    #iterSteps=10, errTol= 1e-5, gamma= 1.0, vmin= -1, vmax= -1,
    #constraints= None, isPsfCentered= True, useCpxFFT= False, debugInt= 3,
    #compareWithTruth= False, saveIntermediateSteps= 0)

    #test_dec = iterative.TikhonovMiller(test_after_conv.out, psf=test_psf, sample= None, groundTruth= None, solveFor= 'sample', initialGuess= 'WienerFilter',
    #iterSteps=10, errTol= 1e-5, gamma= 1., lamb= 1.,
    #constraints= None, isPsfCentered= True, useCpxFFT= False,
    #debugInt= 3, compareWithTruth= False, saveIntermediateSteps= 0)

    #test_dec = iterative.ICTMi (test_after_conv.out, ps Int= 3, compareWithTruth= False, saveIntermediateSteps= 0)

    #test_dec.initSaveParameters(save_path, save_fident, intermediate_paths=['inter[IND]', None], None], None], None], None])
    save_path = util.ptjoin(util.SIM_RECON, 'test_decon_iter', 'Gold')
    f_ident = 'recon_wiener_{:0>3}.tif'

    util.path_declarations.createAllPaths(save_path)

    test_dec.initSaveParameters(
        save_path,
        f_ident,
        intermediate_path='inter_[IND]',
        orig_img_path=[test_conv_path, test_conv_fident],
        orig_psf_path=[test_psf_path, test_psf_fident],
        orig_sample_path=[None, None],
        orig_truth_path=[test_gr_truth_path, test_gr_truth_fident],
        overwrite=False)

    test_dec.prepare()
    test_dec.solve()

    test_dec.saveSolution()
def sample_noise_additions():
    """"""
    convs = {
        'defocus1': [
            'cyto_defocus_sig-0.10_zi-1000_K-200', ['res_[0.2,0.2,0.2]'],
            'cyto_conv_{:0>3}.tif', [['cnr', 30.], ['cnr', 10.], ['cnr', 5.]]
        ],
        'defocus2': [
            'cyto_defocus_sig-0.05_zi-2000_K-200', ['res_[0.2,0.2,0.2]'],
            'cyto_conv_{:0>3}.tif', [['cnr', 30.], ['cnr', 10.], ['cnr', 5.]]
        ],
        'defocus3': [
            'cyto_defocus_sig-0.05_zi-1000_K-200', ['res_[0.2,0.2,0.2]'],
            'cyto_conv_{:0>3}.tif', [['cnr', 30.], ['cnr', 10.], ['cnr', 5.]]
        ],
        'defocus4': [
            'cyto_defocus_sig-0.05_zi-800_K-100',
            ['res_[0.1,0.1,0.1]', 'res_[0.2,0.2,0.2]'], 'cyto_conv_{:0>3}.tif',
            [['cnr', 30.], ['cnr', 10.], ['cnr', 5.]]
        ],
        'gauss1': [
            'cyto_gauss_sig0-0.15_sig1-0.00_sig2-0.22',
            ['res_[0.1,0.1,0.1]', 'res_[0.2,0.2,0.2]'], 'cyto_conv_{:0>3}.tif',
            [['cnr', 30.], ['cnr', 10.], ['cnr', 5.]]
        ],
        'gauss_simple1': [
            'cyto_gauss_simple_sig-0.15',
            ['res_[0.1,0.1,0.1]', 'res_[0.2,0.2,0.2]'], 'cyto_conv_{:0>3}.tif',
            [['cnr', 30.], ['cnr', 10.], ['cnr', 5.]]
        ],
        'gauss_simple2': [
            'cyto_gauss_simple_sig-0.30', ['res_[0.1,0.1,0.1]'],
            'cyto_conv_{:0>3}.tif', [['cnr', 30.], ['cnr', 10.], ['cnr', 5.]]
        ],
    }

    main_path = util.SIM_CONVOLUTED

    for name, parameters in psfs.items():
        print('Processing Convoluted Image Stack: {}'.format(name))

        add_path = parameters[0]
        res_folders = parameters[1]
        f_ident = parameters[2]
        noise_params = parameters[3]

        for res in res_folders:

            for noise in noise_params:

                noise_free_path = util.ptjoin(main_path, add_path, res)
                new_path = util.ptjoin(
                    main_path, add_path,
                    '{}_{}-{}'.format(res, noise[0], noise[1]))

                util.createAllPaths(new_path)

                temp_stack = util.stack_loader.read_image_stack(
                    noise_free_path, f_ident, meta=True)

                t_noise_dict = {
                    'noise_def': convoluter.Noise_Adder.NOISE_DEF[noise[0]],
                    noise[0]: noise[1]
                }

                temp_noise = convoluter.Noise_Adder(temp_stack[0],
                                                    old_meta=temp_stack[1],
                                                    img_type='sample',
                                                    noise_type='gaussian',
                                                    noise_params=t_noise_dict,
                                                    debug_int=3)
                temp_noise.addNoise()

                temp_noise.initSaveParameters(
                    new_path,
                    f_ident,
                    orig_img_path=[noise_free_path, f_ident],
                    overwrite=True)
                temp_noise.saveSolution()