def test_dilation(self): map_mask = MapMask(self.fixture, resolution=0.1) # This is where we put the foreground in the fixture, so this should be true by design. self.assertTrue(map_mask.is_on_mask(2, 2)) # Go 1 meter to the right. Obviously not on the mask. self.assertFalse(map_mask.is_on_mask(2, 3)) # But if we dilate by 1 meters, we are on the dilated mask. self.assertTrue(map_mask.is_on_mask(2, 3, dilation=1)) # x direction self.assertTrue(map_mask.is_on_mask(3, 2, dilation=1)) # y direction self.assertTrue( map_mask.is_on_mask(2 + np.sqrt(1 / 2), 2 + np.sqrt(1 / 2), dilation=1)) # diagonal # If we dilate by 0.9 meter, it is not enough. self.assertFalse(map_mask.is_on_mask(2, 3, dilation=0.9))
def test_native_resolution(self): # Load mask and assert that the map_mask = MapMask(self.fixture, resolution=0.1) # This is where we put the foreground in the fixture, so this should be true by design. self.assertTrue(map_mask.is_on_mask(2, 2)) # Each pixel is 10 x 10 cm, so if we step less than 5 cm in either direction we are still on foreground. # Note that we add / subtract a "small number" to break numerical ambiguities along the edges. self.assertTrue(map_mask.is_on_mask(2 + self.half_lt, 2)) self.assertTrue(map_mask.is_on_mask(2 - self.half_lt, 2)) self.assertTrue(map_mask.is_on_mask(2, 2 + self.half_lt)) self.assertTrue(map_mask.is_on_mask(2, 2 - self.half_lt)) # But if we step outside this range, we should get false self.assertFalse(map_mask.is_on_mask(2 + self.half_gt, 2)) self.assertFalse(map_mask.is_on_mask(2 + self.half_gt, 2)) self.assertFalse(map_mask.is_on_mask(2, 2 + self.half_gt)) self.assertFalse(map_mask.is_on_mask(2, 2 + self.half_gt))