Example #1
0
 def test_boundary_single(self):
     c = ConnectedRegion(shape=(1,1), value=1, rowptr=[0, 2], colptr=[0, 1])
     y, x = crh.outside_boundary(c)
     assert_array_equal(iarr.to_list(x),
                        [-1, 0, 1, -1, 1, -1, 0, 1])
     assert_array_equal(iarr.to_list(y),
                        [-1, -1, -1, 0, 0, 1, 1, 1])
Example #2
0
    def test_outside_boundary_beyond_border(self):
        c = ConnectedRegion(shape=(2, 2),
                            value=1,
                            rowptr=[0, 2, 4],
                            colptr=[0, 1, 1, 2])
        assert_array_equal(crh.todense(c), np.eye(2))

        y, x = crh.outside_boundary(c)
        assert_array_equal(iarr.to_list(y),
                           [-1, -1, -1, 0, 0, 0, 1, 1, 1, 2, 2, 2])
        assert_array_equal(iarr.to_list(x),
                           [-1, 0, 1, -1, 1, 2, -1, 0, 2, 0, 1, 2])
Example #3
0
    def test_outside_boundary(self):
        y, x = crh.outside_boundary(self.c)
        assert_array_equal(iarr.to_list(x),
                           [1, 2, 3, 4, 5, -1, 0, 1, 3, 5, -1,
                            3, 4, 5, -1, 0, 1, 5, 1, 2, 3, 4, 5])
        assert_array_equal(iarr.to_list(y),
                           [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2,
                            2, 2, 2, 3, 3, 3, 3, 4, 4, 4, 4, 4])

        c = ConnectedRegion(shape=(1, 5),
                            rowptr=[0, 2],
                            colptr=[2, 3])

        [0, 0, 1, 0, 0]
        y, x = crh.outside_boundary(c)
        assert_array_equal(iarr.to_list(x),
                           [1, 2, 3, 1, 3, 1, 2, 3])
        assert_array_equal(iarr.to_list(y),
                           [-1, -1, -1, 0, 0, 1, 1, 1])
Example #4
0
from lulu import int_array

c = ConnectedRegion(shape=(5,5),
                    value=1, start_row=1,
                    rowptr=[0,4,6,10,14],
                    colptr=[2,3,4,5,0,5,0,1,2,5,0,2,3,5])

print crh.todense(c)

dense = np.zeros((7,7,3))
dense[1:6, 1:6, 0] = crh.todense(c)

plt.subplot(1, 2, 1)
plt.imshow(dense, interpolation='nearest')
plt.title('Connected region')
plt.xticks([])
plt.yticks([])

ii, jj = crh.outside_boundary(c)
dense_outside = dense.copy()
for i, j in zip(int_array.to_list(ii), int_array.to_list(jj)):
    dense_outside[i + 1, j + 1] = [0, 1, 0]

plt.subplot(1, 2, 2)
plt.imshow(dense_outside, interpolation='nearest')
plt.title('Outside boundary')
plt.xticks([])
plt.yticks([])

plt.show()