def infer_occlusion(self, flow_forward, flow_backward): """Get a 'soft' occlusion mask from the forward and backward flow.""" occlusion_mask = smurf_utils.compute_occlusions(flow_forward, flow_backward, self._occlusion_estimation, occlusions_are_zeros=False) return occlusion_mask
def test_fb_consistency_no_occlusion_no_borders(self): # Test that fb_consistency with boundaries_are_occluded=False # marks everything unoccluded when flows are fb-consistent. # Flows points right and up by 4. flow_01 = tf.ones((4, 64, 64, 2), tf.float32) * 4. # Flow points left and down by 4. flow_10 = -flow_01 occlusion_mask = smurf_utils.compute_occlusions( flow_01, flow_10, occlusion_estimation='brox', boundaries_occluded=False, occlusions_are_zeros=False) self._assertAllEqual(occlusion_mask, tf.zeros_like(occlusion_mask))
def test_wang_no_occlusion_no_borders(self): # Test that wang with boundaries_are_occluded=False marks everything # unoccluded when backward flow is perfectly smooth. # Flows points right and up by 4. flow_01 = tf.ones((4, 64, 64, 2), tf.float32) * 4. # Flow points left and down by 2 flow_10 = -flow_01 * .5 occlusion_mask = smurf_utils.compute_occlusions( flow_01, flow_10, occlusion_estimation='wang', boundaries_occluded=False, occlusions_are_zeros=False) # NOTE(austinstone): Wang marks things as unoccluded if there is a backward # flow vector pointing to it, even if the forward / backward flow is # highly inconsistent. In this case, everything is marked as unoccluded # because every pixel either has a backward flow pixel pointing to it # or the forward flow vector points off the edge of the image. self._assertAllEqual(occlusion_mask, tf.zeros_like(occlusion_mask))
def test_fb_consistency_occlusion_no_borders(self): # Test that fb_consistency with boundaries_are_occluded=False marks # everything except boundaries as occluded when flows are not fb-consistent. # Flows points right and up by 4 flow_01 = tf.ones((4, 64, 64, 2), tf.float32) * 4. # Flows points left and down by 2 flow_10 = -flow_01 * .5 occlusion_mask = smurf_utils.compute_occlusions( flow_01, flow_10, occlusion_estimation='brox', boundaries_occluded=False, occlusions_are_zeros=False) self._assertAllEqual(occlusion_mask[:, 4:-4, 4:-4, :], tf.ones_like(occlusion_mask[:, 4:-4, 4:-4, :])) self._assertAllEqual(occlusion_mask[:, -4:, :, :], tf.zeros_like(occlusion_mask[:, -4:, :, :])) self._assertAllEqual(occlusion_mask[:, :, -4:, :], tf.zeros_like(occlusion_mask[:, :, -4:, :]))
def test_wang_no_occlusion(self): # Test that wang with boundaries_are_occluded=True marks everything # unoccluded except for parts where flow vectors point off the edges # when the backward flow is perfectly smooth. # flows points right and up by 4 flow_01 = tf.ones((4, 64, 64, 2), tf.float32) * 4. # flow points left and down by 2 flow_10 = -flow_01 * .5 occlusion_mask = smurf_utils.compute_occlusions( flow_01, flow_10, occlusion_estimation='wang', boundaries_occluded=True, occlusions_are_zeros=False) self._assertAllEqual(occlusion_mask[:, :, -2:, :], tf.ones_like(occlusion_mask[:, :, -2:, :])) self._assertAllEqual(occlusion_mask[:, -2:, :, :], tf.ones_like(occlusion_mask[:, -2:, :, :])) self._assertAllEqual(occlusion_mask[:, :-2, :-2, :], tf.zeros_like(occlusion_mask[:, :-2, :-2, :]))