def test_unmask(size=5):
    rng = check_random_state(42)
    for ndim in range(1, 4):
        shape = [size] * ndim
        mask = np.zeros(shape).astype(np.bool)
        mask[rng.rand(*shape) > .8] = 1
        support = rng.randn(mask.sum())
        full = _unmask(support, mask)
        np.testing.assert_array_equal(full.shape, shape)
        np.testing.assert_array_equal(full[mask], support)
Пример #2
0
def test_unmask(size=5):
    rng = check_random_state(42)
    for ndim in range(1, 4):
        shape = [size] * ndim
        mask = np.zeros(shape).astype(np.bool)
        mask[rng.rand(*shape) > 0.8] = 1
        support = rng.randn(mask.sum())
        full = _unmask(support, mask)
        np.testing.assert_array_equal(full.shape, shape)
        np.testing.assert_array_equal(full[mask], support)
Пример #3
0
def to_niimgs(X, dim):
    p = np.prod(dim)
    assert_equal(len(dim), 3)
    assert_true(X.shape[-1] <= p)
    mask = np.zeros(p).astype(np.bool)
    mask[:X.shape[-1]] = 1
    assert_equal(mask.sum(), X.shape[1])
    mask = mask.reshape(dim)
    X = np.rollaxis(np.array([_unmask(x, mask) for x in X]), 0, start=4)
    affine = np.eye(4)
    return nibabel.Nifti1Image(X, affine), nibabel.Nifti1Image(
        mask.astype(np.float), affine)