Example #1
0
def test_slice_from_3d():
    # Resample a 3d image, returning a zslice, yslice and xslice
    #
    # This example creates a coordmap that coincides with
    # a given z, y, or x slice of an image, and checks that
    # resampling agrees with the data in the given slice.
    shape = (100,90,80)
    g = AffineTransform.from_params('ijk',
                                    'xyz',
                                    np.diag([0.5,0.5,0.5,1]))
    img = Image(np.ones(shape), g)
    img.get_data()[50:55,40:55,30:33] = 3
    I = np.identity(4)
    zsl = slices.zslice(26,
                        ((0,49.5), 100),
                        ((0,44.5), 90),
                        img.reference)
    ir = resample(img, zsl, I, (100, 90))
    assert_array_almost_equal(ir.get_data(), img[:,:,53].get_data())
    ysl = slices.yslice(22,
                        ((0,49.5), 100),
                        ((0,39.5), 80),
                        img.reference)
    ir = resample(img, ysl, I, (100, 80))
    assert_array_almost_equal(ir.get_data(), img[:,45,:].get_data())
    xsl = slices.xslice(15.5,
                        ((0,44.5), 90),
                        ((0,39.5), 80),
                        img.reference)
    ir = resample(img, xsl, I, (90, 80))
    assert_array_almost_equal(ir.get_data(), img[32,:,:].get_data())
Example #2
0
def test_box_slice():
    t = xslice(5, ([0, 9], 10), ([0, 9], 10))
    yield assert_array_almost_equal(t.affine,
                                    [[ 0.,  0.,  5.],
                                     [ 1.,  0.,  0.],
                                     [ 0.,  1.,  0.],
                                     [ 0.,  0.,  1.]])
    t = yslice(4, ([0, 9], 10), ([0, 9], 10))
    yield assert_array_almost_equal(t.affine,
                                    [[ 1.,  0.,  0.],
                                     [ 0.,  0.,  4.],
                                     [ 0.,  1.,  0.],
                                     [ 0.,  0.,  1.]])
    t = zslice(3, ([0, 9], 10), ([0, 9], 10))
    yield assert_array_almost_equal(t.affine,
                                    [[ 1.,  0.,  0.],
                                     [ 0.,  1.,  0.],
                                     [ 0.,  0.,  3.],
                                     [ 0.,  0.,  1.]])
Example #3
0
def test_slice_from_3d():
    # Resample a 3d image, returning a zslice, yslice and xslice
    #
    # This example creates a coordmap that coincides with
    # a given z, y, or x slice of an image, and checks that
    # resampling agrees with the data in the given slice.
    shape = (100, 90, 80)
    g = AffineTransform.from_params('ijk', 'xyz', np.diag([0.5, 0.5, 0.5, 1]))
    img = Image(np.ones(shape), g)
    img.get_data()[50:55, 40:55, 30:33] = 3
    I = np.identity(4)
    zsl = slices.zslice(26, ((0, 49.5), 100), ((0, 44.5), 90), img.reference)
    ir = resample(img, zsl, I, (100, 90))
    assert_array_almost_equal(ir.get_data(), img[:, :, 53].get_data())
    ysl = slices.yslice(22, ((0, 49.5), 100), ((0, 39.5), 80), img.reference)
    ir = resample(img, ysl, I, (100, 80))
    assert_array_almost_equal(ir.get_data(), img[:, 45, :].get_data())
    xsl = slices.xslice(15.5, ((0, 44.5), 90), ((0, 39.5), 80), img.reference)
    ir = resample(img, xsl, I, (90, 80))
    assert_array_almost_equal(ir.get_data(), img[32, :, :].get_data())
Example #4
0
def test_slice_from_3d():
    # Resample a 3d image, returning a zslice, yslice and xslice
    #
    # This example creates a coordmap that coincides with
    # the 10th slice of an image, and checks that
    # resampling agrees with the data in the 10th slice.
    shape = (100, 90, 80)
    g = AffineTransform.from_params("ijk", "xyz", np.diag([0.5, 0.5, 0.5, 1]))
    i = Image(np.ones(shape), g)
    i[50:55, 40:55, 30:33] = 3
    a = np.identity(4)
    zsl = slices.zslice(26, ((0, 44.5), 90), ((0, 39.5), 80), i.reference)
    ir = resample(i, zsl, a, (90, 80))
    yield assert_true(np.allclose(np.asarray(ir), np.asarray(i[53])))
    ysl = slices.yslice(22, (0, 49.5), (0, 39.5), i.reference, (100, 80))
    ir = resample(i, ysl.coordmap, a, ysl.shape)
    yield assert_true(np.allclose(np.asarray(ir), np.asarray(i[:, 45])))
    xsl = slices.xslice(15.5, (0, 49.5), (0, 44.5), i.reference, (100, 90))
    ir = resample(i, xsl.coordmap, a, xsl.shape)
    yield assert_true(np.allclose(np.asarray(ir), np.asarray(i[:, :, 32])))
Example #5
0
    def test_box_slice(self):
        coordmap = Affine.identity(names)
        t = zslice(5, [0, 9], [0, 9], coordmap.output_coords, (10,10))
        assert_almost_equal(t.coordmap.affine, [[ 0.,  0.,  5.],
                                                [ 1.,  0.,  0.],
                                                [ 0.,  1.,  0.],
                                                [ 0.,  0.,  1.]])
        

        t = yslice(4, [0, 9], [0, 9], coordmap.output_coords, (10,10))
        assert_almost_equal(t.coordmap.affine, [[ 1.,  0.,  0.],
                                                [ 0.,  0.,  4.],
                                                [ 0.,  1.,  0.],
                                                [ 0.,  0.,  1.]])
        
        t = xslice(3, [0, 9], [0, 9], coordmap.output_coords, (10,10))
        assert_almost_equal(t.coordmap.affine, [[ 1.,  0.,  0.],
                                                [ 0.,  1.,  0.],
                                                [ 0.,  0.,  3.],
                                                [ 0.,  0.,  1.]])