def smooth_image(img, fwhm):
    """ Smooth image `img` by FWHM `fwhm`
    """
    # Make sure time axis is last
    img = as_xyz_image(img)
    fwhm = np.asarray(fwhm)
    if fwhm.size == 1:
        fwhm = np.ones(3, ) * fwhm
    # 4x4 affine
    affine = xyz_affine(img)
    # Voxel sizes in the three spatial axes
    RZS = affine[:3, :3]
    vox = np.sqrt(np.sum(RZS**2))
    # Smoothing in terms of voxels
    vox_fwhm = fwhm / vox
    vox_sd = fwhm2sigma(vox_fwhm)
    # Do the smoothing
    data = img.get_data()
    sm_data = snd.gaussian_filter(data, list(vox_sd) + [0])
    return Image(sm_data, img.coordmap)
Ejemplo n.º 2
0
def smooth_image(img, fwhm):
    """ Smooth image `img` by FWHM `fwhm`
    """
    # Make sure time axis is last
    img = as_xyz_image(img)
    fwhm = np.asarray(fwhm)
    if fwhm.size == 1:
        fwhm = np.ones(3,) * fwhm
    # 4x4 affine
    affine = xyz_affine(img)
    # Voxel sizes in the three spatial axes
    RZS = affine[:3, :3]
    vox = np.sqrt(np.sum(RZS ** 2))
    # Smoothing in terms of voxels
    vox_fwhm = fwhm / vox
    vox_sd = fwhm2sigma(vox_fwhm)
    # Do the smoothing
    data = img.get_data()
    sm_data = snd.gaussian_filter(data, list(vox_sd) + [0])
    return Image(sm_data, img.coordmap)
Ejemplo n.º 3
0
def test_sigma_fwhm():
    # ensure that fwhm2sigma and sigma2fwhm are inverses of each other        
    fwhm = np.arange(1.0, 5.0, 0.1)
    sigma = np.arange(1.0, 5.0, 0.1)
    yield assert_true, np.allclose(sigma2fwhm(fwhm2sigma(fwhm)), fwhm)
    yield assert_true, np.allclose(fwhm2sigma(sigma2fwhm(sigma)), sigma)