Exemple #1
0
def test_defaults_3D():
    img = image.fromarray(np.ones(array3D_shape), 'kji', 'zyx')
    yield assert_true, isinstance(img._data, np.ndarray)
    yield assert_true, img.ndim == 3
    yield assert_true, img.shape == array3D_shape
    # ndarray's do not have a header
    yield assert_raises, AttributeError, getattr, img, 'header'
    yield assert_true, img.affine.shape == (4,4)
    yield assert_true, img.affine.diagonal().all() == 1
Exemple #2
0
def test_defaults_2D():
    data = np.ones(array2D_shape)
    img = image.fromarray(data, 'kj', 'yx')
    yield assert_true, isinstance(img._data, np.ndarray)
    yield assert_true, img.ndim == 2
    yield assert_true, img.shape == array2D_shape
    yield assert_raises, AttributeError, getattr, img, 'header'
    yield assert_true, img.affine.shape == (3,3)
    yield assert_true, img.affine.diagonal().all() == 1
Exemple #3
0
def test_defaults_4D():
    data = np.ones(array4D_shape)
    names = ['time', 'zspace', 'yspace', 'xspace']
    img = image.fromarray(data, names, names)
    yield assert_true, isinstance(img._data, np.ndarray)
    yield assert_true, img.ndim == 4
    yield assert_true, img.shape == array4D_shape
    yield assert_raises, AttributeError, getattr, img, 'header'
    yield assert_true, img.affine.shape == (5,5)
    yield assert_true, img.affine.diagonal().all() == 1
Exemple #4
0
def test_merge_images():
    #  Check that merge_images works, and that the CoordinateMap
    #  instance is first one in the list.
    data = np.ones((2,3,4))
    img = image.fromarray(data, 'ijk', 'xyz')
    mimg = merge_images([img for i in range(4)])
    yield assert_equal, mimg.shape, (4,) + img.shape
    yield nptest.assert_almost_equal, mimg.affine[1:,1:], img.affine
    yield nptest.assert_almost_equal, mimg.affine[0], np.array([1,0,0,0,0])
    yield nptest.assert_almost_equal, mimg.affine[:,0], np.array([1,0,0,0,0])
    # A list with different CoordinateMaps -- the merged images
    # takes the first one
    naffine = Affine(np.diag([-2,-4,-6,1.]),
                     img.coordmap.input_coords,
                     img.coordmap.output_coords)
    nimg = Image(np.asarray(img), naffine)
    mimg = merge_images([nimg, img, img, img])
    yield assert_equal, mimg.shape, (4,) + img.shape
    yield nptest.assert_almost_equal, mimg.affine[1:,1:], nimg.affine
    yield nptest.assert_almost_equal, mimg.affine[0], np.array([1,0,0,0,0])
    yield nptest.assert_almost_equal, mimg.affine[:,0], np.array([1,0,0,0,0])
Exemple #5
0
volFile = '/chb/tmp/kihotest.nii'
trkFile = '/chb/tmp/kihotest.trk'
mappedTrkFile = '/chb/tmp/kihotest_mapped.trk'

# volume
testArr = np.zeros((10, 10, 10))

r = 0
for i in range(testArr.shape[0]):
    for j in range(testArr.shape[1]):
        for k in range(testArr.shape[2]):
            r += 1
            testArr[i, j, k] = r

img = image.fromarray(testArr, 'ijk', 'xyz')

save_image(img, volFile)

# trk file
fibers = []

# 2,5,6
# 3,5,7
# 2,6,7
# 8,7,3
# 9,5,4
points = np.array([[2, 5, 6], [3, 5, 7], [2, 6, 7], [8, 7, 3], [9, 5, 4]],
                  dtype=np.float32)

fibers.append((points, None, None))
Exemple #6
0
volFile = '/chb/tmp/kihotest.nii'
trkFile = '/chb/tmp/kihotest.trk'
mappedTrkFile = '/chb/tmp/kihotest_mapped.trk'


# volume
testArr = np.zeros( ( 10, 10, 10 ) )

r = 0
for i in range( testArr.shape[0] ):
  for j in range( testArr.shape[1] ):
    for k in range( testArr.shape[2] ):
      r += 1
      testArr[i, j, k] = r

img = image.fromarray( testArr, 'ijk', 'xyz' )

save_image( img, volFile )


# trk file
fibers = []

# 2,5,6
# 3,5,7
# 2,6,7
# 8,7,3
# 9,5,4
points = np.array( [[2, 5, 6], [3, 5, 7], [2, 6, 7], [8, 7, 3], [9, 5, 4]], dtype=np.float32 )

fibers.append( ( points, None, None ) )