Esempio n. 1
0
def perform_tissue_classification(tiv, vem_iters, beta, scheme='mf',
                                  noise='gauss', freeze_prop=False, 
                                  labels=('CSF','GM','WM'), mixmat=None): 
    """
    perform probabilistic tissue classification on TIV 
    """
    tiv_ = AffineImage(tiv.get_data(), tiv.get_affine(), 'scanner') 
    ppm_img_, _ = brain_segmentation(tiv_, beta=beta, niters=vem_iters, 
                                     labels=labels, mixmat=mixmat, 
                                     noise=noise, freeze_prop=freeze_prop, 
                                     scheme=scheme)

    count_tiv = len(np.where(tiv.get_data() > 0)[0])
    return Nifti1Image(ppm_img_.get_data()[..., 1], tiv.get_affine()), \
        Nifti1Image(ppm_img_.get_data()[..., 0], tiv.get_affine()), \
        count_tiv
Esempio n. 2
0
# Labels
labels = []
labels += ['CSF' for k in range(k_csf)]
labels += ['GM' for k in range(k_gm)]
labels += ['WM' for k in range(k_wm)]
mixmat = []
mixmat += [[1, 0, 0] for k in range(k_csf)]
mixmat += [[0, 1, 0] for k in range(k_gm)]
mixmat += [[0, 0, 1] for k in range(k_wm)]
mixmat = np.array(mixmat)

# Perform tissue classification
ppm_img, label_img = brain_segmentation(img,
                                        mask_img=mask_img,
                                        beta=beta, niters=niters,
                                        labels=labels, mixmat=mixmat,
                                        noise=noise, freeze_prop=freeze_prop,
                                        scheme=SCHEME)
outfile = join(mkdtemp(), 'hard_classif.nii')
save_image(label_img, outfile)
print('Label image saved in: %s' % outfile)

# Compute fuzzy Dice indices if a 3-class fuzzy model is provided
if not args.probc == None and \
        not args.probg == None and \
        not args.probw == None:
    print('Computing Dice index')
    gpm = [load_image(args.probc),
           load_image(args.probg),
           load_image(args.probw)]
    d = fuzzy_dice(gpm, ppm_img, np.where(mask_img.get_data() > 0))