Exemple #1
0
def ve_step(ppm, data, mask, mu, sigma, prior, alpha=1., beta=0.0): 
    """
    posterior = e_step(gaussians, prior, data, posterior=None)    

    data are assumed masked. 
    """
    lik = np.zeros(np.shape(prior))
    for i in range(ntissues): 
        lik[:,i] = prior[:,i] * gaussian(data, mu[i], sigma[i])

    # Normalize
    X, Y, Z = mask
    ppm[X, Y, Z] = lik 

    if beta == 0.0: 
        ppm_sum = ppm[mask].sum(1)
        for i in range(ntissues): 
            ppm[X, Y, Z, i] /= ppm_sum
 
    else: 
        print('  .. MRF correction')
        XYZ = np.array((X, Y, Z), dtype='int') 
        ppm = finalize_ve_step(ppm, lik, XYZ, beta)

    return ppm
import numpy as np 
from nipy.neurospin.segmentation.mrf_module import finalize_ve_step

dx, dy, dz, K = 10, 10, 10, 4

ppm = np.random.rand(dx, dy, dz, K)

XYZ = np.mgrid[dx/2-dx/4:dx/2+dx/4,dy/2-dy/4:dy/2+dy/4,dz/2-dz/4:dz/2+dz/4]
XYZ = np.reshape(XYZ, (3, np.prod(XYZ.shape[1:])))

lik = np.random.rand(XYZ.shape[1], K)

finalize_ve_step(ppm, lik, XYZ, 0.)