Ejemplo n.º 1
0
 def it_deals_with_odd_divisibility():
     im = np.arange(5 * 6).reshape((5, 6))
     samples = imops.rolling_window(im, (3, 3), (2, 2))
     assert samples.shape == (2, 2, 3, 3)
     assert np.all(samples[0, 0] == [[0, 1, 2], [6, 7, 8], [12, 13, 14]])
     assert np.all(samples[1,
                           1] == [[15, 16, 17], [21, 22, 23], [27, 28, 29]])
Ejemplo n.º 2
0
 def it_returns_coords():
     im = np.arange(6 * 6).reshape((6, 6))
     _, coords = imops.rolling_window(im, (2, 2), (3, 3), return_coords=True)
     assert np.all(
         coords
         == [
             [[0, 0], [0, 2], [0, 4],],
             [[2, 0], [2, 2], [2, 4],],
             [[4, 0], [4, 2], [4, 4],],
         ]
     )
Ejemplo n.º 3
0
 def it_deals_with_a_stack():
     ims = np.stack((
         1 * (np.arange(6 * 6) + 1).reshape((6, 6)),
         10 * (np.arange(6 * 6) + 1).reshape((6, 6)),
         100 * (np.arange(6 * 6) + 1).reshape((6, 6)),
     ))
     samples = imops.rolling_window(ims, (2, 2), (3, 3)).astype(int)
     assert samples.shape == (3, 3, 3, 2, 2)
     assert np.all(samples[0, 0, 0, :, :] == [[1, 2], [7, 8]])
     assert np.all(samples[2, 0, 0, :, :] == [[100, 200], [700, 800]])
     assert np.all(samples[0, 2, 2, :, :] == [[29, 30], [35, 36]])
     assert np.all(samples[2, 2, 2, :, :] == [[2900, 3000], [3500, 3600]])
Ejemplo n.º 4
0
 def it_raises_on_illegal_window():
     with zest.raises(ValueError):
         imops.rolling_window(np.zeros((10, 10)), (3, 3), (2, 2))
Ejemplo n.º 5
0
 def it_deals_with_even_divisibility():
     im = np.arange(6 * 6).reshape((6, 6))
     samples = imops.rolling_window(im, (2, 2), (3, 3))
     assert samples.shape == (3, 3, 2, 2)
     assert np.all(samples[0, 0] == [[0, 1], [6, 7]])
     assert np.all(samples[2, 2] == [[28, 29], [34, 35]])