UKRIN-MAPS / ukat

UKRIN Kidney Analysis Toolbox

Home Page:https://www.nottingham.ac.uk/research/groups/spmic/research/uk-renal-imaging-network/ukrin-maps.aspx

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

to_nifti method

alexdaniel654 opened this issue · comments

Would be nice to have a to_nifti method in the mapping class' as it would save lots of lines of very similar code. Something along the lines of

mapper.to_nifti(base_file_name='sub_01_t1', maps='all', affine=affine) would generate sub_01_t1_t1_map.nii.gz, sub_01_t1_m1_err.nii.gz, sub_01_t1_m0_map.nii.gz, sub_01_t1_m0_err.nii.gz, sub_01_t1_eff_map.nii.gz and sub_01_t1_eff_errnii.gz

and

mapper.to_nifti(base_file_name='sub_01_t1', maps=['m0', 'eff'], affine=affine) would generate sub_01_t1_m0_map.nii.gz and sub_01_t1_eff_map.nii.gz

Not something I plan in implementing imminently, just a bit of a mind dump while I remember.

I might have a look at this, it's an interesting suggestion. So we would have a .to_nifti method per mapping class in order to "dump" the different outputs (final and intermediate)?

I'd only do it for final outputs (and id make it optional as to which output you save, most of the time you wouldn't bother saving the maps of confidence intervals.) but yes, essentially.

An example of where it would be useful, below is the 3p T1 mapping code I wrote to process the ISMRM data. There's more code for exporting the niftis then there is to import data, generate a mask and calculate the T1 maps.

    t1_raw_img = nib.load(os.path.join(data_dir, '02301__WIP_T1_SE_EPI_SENSE_orig.nii.gz'))
    affine = t1_raw_img.affine
    data = t1_raw_img.get_fdata()
    mask = data[:, :, :, 0]>5000
    ti = np.arange(100, 1801, 100) + 53.7
    tss = -53.7
    
    t1_mapper_3p = T1(data, ti, multithread=True, parameters=3, tss=tss, mask=mask)
    
    vol_to_png(t1_mapper_3p.t1_map, os.path.join(png_dir, 'T1', 't1_3p'), clim=(250, 2750), cmap='inferno') # Export the t1 map as pngs.

    # Everything from here down is just exporting niftis
    t1_img = nib.Nifti1Image(t1_mapper_3p.t1_map, affine)
    nib.save(t1_img, os.path.join(nii_dir, 't1_3p_map.nii.gz'))
    t1_err_img = nib.Nifti1Image(t1_mapper_3p.t1_err, affine)
    nib.save(t1_err_img, os.path.join(nii_dir, 't1_3p_err.nii.gz'))
    m0_img = nib.Nifti1Image(t1_mapper_3p.m0_map, affine)
    nib.save(m0_img, os.path.join(nii_dir, 't1_3p_m0_map.nii.gz'))
    m0_err_img = nib.Nifti1Image(t1_mapper_3p.m0_err, affine)
    nib.save(m0_err_img, os.path.join(nii_dir, 't1_3p_m0_err.nii.gz'))
    t1_eff_img = nib.Nifti1Image(t1_mapper_3p.eff_map, affine)
    nib.save(t1_eff_img, os.path.join(nii_dir, 't1_3p_eff_map.nii.gz'))
    t1_eff_err_img = nib.Nifti1Image(t1_mapper_3p.eff_err, affine)
    nib.save(t1_eff_err_img, os.path.join(nii_dir, 't1_3p_eff_err.nii.gz'))