Exemple #1
0
 def test_build_multi(self):
     line = coord_path.line
     l1 = coord_path.build(line((0, 0), (0, 2)))
     l2 = coord_path.build(line((0, 2), (0, 4)))
     l = coord_path.build(l1, l2)
     assert_array_almost_equal(
         l, np.array([[0, 0], [0, 1], [0, 2], [0, 3], [0, 4]]))
Exemple #2
0
 def test_build(self):
     line = coord_path.line
     l = coord_path.build(line((0, 0), (0, 3)))
     assert_array_almost_equal(l, np.array([[0, 0], [0, 1], [0, 2], [0,
                                                                     3]]))
     l = coord_path.build(line((3, 0), (0, 0)))
     assert_array_almost_equal(l, np.array([[3, 0], [2, 0], [1, 0], [0,
                                                                     0]]))
Exemple #3
0
 def test_build_multi(self):
     line = coord_path.line
     l1 = coord_path.build(line((0, 0), (0, 2)))
     l2 = coord_path.build(line((0, 2), (0, 4)))
     l = coord_path.build(l1, l2)
     assert_array_almost_equal(l, np.array([[0, 0],
                                            [0, 1],
                                            [0, 2],
                                            [0, 3],
                                            [0, 4]]))
Exemple #4
0
 def test_build(self):
     line = coord_path.line
     l = coord_path.build(line((0, 0), (0, 3)))
     assert_array_almost_equal(l, np.array([[0, 0],
                                            [0, 1],
                                            [0, 2],
                                            [0, 3]]))
     l = coord_path.build(line((3, 0), (0, 0)))
     assert_array_almost_equal(l, np.array([[3, 0],
                                            [2, 0],
                                            [1, 0],
                                            [0, 0]]))
Exemple #5
0
 def test_colour_cut(self):
     p = coord_path.build(coord_path.line((0, 0), (0, 0)))
     image = np.arange(27).reshape((3, 3, 3))
     cp = cut.along_path(p,image, shape=(3, 3), centre=(0, 0))
     cut_img = cp.next()
     assert_equal(cut_img.shape, (3, 3, 3))
     assert_equal(cut_img[:], image[:])
Exemple #6
0
 def test_colour_cut(self):
     p = coord_path.build(coord_path.line((0, 0), (0, 0)))
     image = np.arange(27).reshape((3, 3, 3))
     cp = cut.along_path(p, image, shape=(3, 3), centre=(0, 0))
     cut_img = cp.next()
     assert_equal(cut_img.shape, (3, 3, 3))
     assert_equal(cut_img[:], image[:])
Exemple #7
0
    def test_centre_cut(self):
        p = coord_path.build(coord_path.line((1, 1), (1, 1)))
        image = np.arange(12).reshape((4, 3))
        cp = cut.along_path(p, image, shape=(3, 3))

        cut_img = cp.next()
        assert_equal(cut_img.shape, (3, 3))
        assert_array_almost_equal(cut_img, [[0, 1, 2], [3, 4, 5], [6, 7, 8]])
Exemple #8
0
 def test_rectangle(self):
     rect = coord_path.rectangle((0, 0), (1, 1))
     r = coord_path.build(rect)
     assert_array_almost_equal(r, [[0, 0],
                                   [1, 0],
                                   [1, 1],
                                   [0, 1],
                                   [0, 0]])
Exemple #9
0
    def test_centre_cut(self):
        p = coord_path.build(coord_path.line((1, 1), (1, 1)))
        image = np.arange(12).reshape((4,3))
        cp = cut.along_path(p, image, shape=(3,3))

        cut_img = cp.next()
        assert_equal(cut_img.shape, (3,3))
        assert_array_almost_equal(cut_img, [[0, 1, 2],
                                            [3, 4, 5],
                                            [6, 7, 8]])
Exemple #10
0
import supreme.io
from supreme.geometry import coord_path as cp
from supreme.config import data_path

def add_path(img,p,col=[1.,0,0]):
    img[p[:,0],p[:,1]] = np.array(col)*255

def add_line(img,c0,c1,col=[1.,0,0]):
    p = cp.build(cp.line(c0,c1))
    add_path(img,p,col)

img = supreme.io.imread(os.path.join(data_path, 'toystory/toystory000.png'))
shape = np.array(img.shape[:2])-1
height,width = shape
centre = shape/2.
add_line(img,(0,0),centre)
add_line(img,centre,(0,width),[0.,1,0])
add_line(img,centre,(height,width),[.9,.6,.6])
add_line(img,centre,(height,0),[.4,.7,.8])
add_path(img,cp.build(cp.circle(centre,50)),[0.9,0.9,0])

add_path(img,cp.build(cp.spline(((0,0),(height,80),(140,200),(150,80)))),
         [0.9,0.9,0.9])

add_path(img,cp.build(cp.spline(((0,0),(height/2.,0),(height/2.,width),(height,width)))),
         [0.6,0.7,0.9])

plt.imshow(img,interpolation='nearest')
plt.title('Trajectories of several coordinate paths')
plt.show()
Exemple #11
0
 def test_dtype(self):
     p = coord_path.build(coord_path.line((0, 0), (0, 0)))
     image = np.arange(12).reshape((4, 3)).astype(np.uint8)
     cut_img = cut.along_path(p, image).next()
     assert_equal(image.dtype, cut_img.dtype)
Exemple #12
0
 def test_ftype(self):
     line = coord_path.line
     l = coord_path.build(line((0, 0), (0, 3)))
     assert_equal(np.dtype(type(l[0][0])), np.dtype(SC.itype))
Exemple #13
0
 def test_dtype(self):
     p = coord_path.build(coord_path.line((0, 0), (0, 0)))
     image = np.arange(12).reshape((4, 3)).astype(np.uint8)
     cut_img = cut.along_path(p, image).next()
     assert_equal(image.dtype, cut_img.dtype)
Exemple #14
0
 def test_nodupes(self):
     line = coord_path.line
     l = coord_path.build(line((0, 0), (5, 5)))
     lr = np.round_(l)
     for i,coord in enumerate(l[:-1]):
         assert(np.any(coord != l[i+1]))
Exemple #15
0
    img[p[:, 0], p[:, 1]] = np.array(col) * 255


def add_line(img, c0, c1, col=[1., 0, 0]):
    p = cp.build(cp.line(c0, c1))
    add_path(img, p, col)


img = supreme.io.imread(os.path.join(data_path, 'toystory/toystory000.png'))
shape = np.array(img.shape[:2]) - 1
height, width = shape
centre = shape / 2.
add_line(img, (0, 0), centre)
add_line(img, centre, (0, width), [0., 1, 0])
add_line(img, centre, (height, width), [.9, .6, .6])
add_line(img, centre, (height, 0), [.4, .7, .8])
add_path(img, cp.build(cp.circle(centre, 50)), [0.9, 0.9, 0])

add_path(img, cp.build(cp.spline(
    ((0, 0), (height, 80), (140, 200), (150, 80)))), [0.9, 0.9, 0.9])

add_path(
    img,
    cp.build(
        cp.spline(((0, 0), (height / 2., 0), (height / 2., width),
                   (height, width)))), [0.6, 0.7, 0.9])

plt.imshow(img, interpolation='nearest')
plt.title('Trajectories of several coordinate paths')
plt.show()
Exemple #16
0
 def test_return_indexable(self):
     line = coord_path.line
     l = coord_path.build(line((0, 0), (5, 5)))
     assert_equal(len(l[1]), 2)
Exemple #17
0
 def test_ftype(self):
     line = coord_path.line
     l = coord_path.build(line((0, 0), (0, 3)))
     assert_equal(np.dtype(type(l[0][0])), np.dtype(SC.itype))
Exemple #18
0
 def test_return_indexable(self):
     line = coord_path.line
     l = coord_path.build(line((0, 0), (5, 5)))
     assert_equal(len(l[1]), 2)
Exemple #19
0
 def test_nodupes(self):
     line = coord_path.line
     l = coord_path.build(line((0, 0), (5, 5)))
     lr = np.round_(l)
     for i, coord in enumerate(l[:-1]):
         assert (np.any(coord != l[i + 1]))
Exemple #20
0
def add_line(img,c0,c1,col=[1.,0,0]):
    p = cp.build(cp.line(c0,c1))
    add_path(img,p,col)
Exemple #21
0
 def test_rectangle(self):
     rect = coord_path.rectangle((0, 0), (1, 1))
     r = coord_path.build(rect)
     assert_array_almost_equal(r, [[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]])
Exemple #22
0
 def test_outside(self):
     p = coord_path.build(coord_path.line((4, 4), (4, 4)))
     image = np.arange(12).reshape((4, 3))
     cp = cut.along_path(p,image,shape=(5, 5),centre=(0, 0))
     list(cp)
Exemple #23
0
def add_line(img, c0, c1, col=[1., 0, 0]):
    p = cp.build(cp.line(c0, c1))
    add_path(img, p, col)
Exemple #24
0
 def test_outside(self):
     p = coord_path.build(coord_path.line((4, 4), (4, 4)))
     image = np.arange(12).reshape((4, 3))
     cp = cut.along_path(p, image, shape=(5, 5), centre=(0, 0))
     list(cp)