From 9cc95703513b137c304514f09867aea4c869748b Mon Sep 17 00:00:00 2001 From: "Steinar H. Gunderson" Date: Fri, 6 Jul 2018 00:45:53 +0200 Subject: [PATCH] Reject motion search if we go beyond the image boundary; seems to fix most of the bad edge behavior. --- motion_search.frag | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/motion_search.frag b/motion_search.frag index a417834..262dca5 100644 --- a/motion_search.frag +++ b/motion_search.frag @@ -137,8 +137,14 @@ void main() u -= (H_inv * du) * inv_image_size; } - // Reject if we moved too far. - if (length((u - initial_u) * image_size) > patch_size) { + // Reject if we moved too far. Also reject if the patch goes out-of-bounds + // (the paper does not mention this, but the code does, and it seems to be + // critical to avoid really bad behavior at the edges). + if ((length((u - initial_u) * image_size) > patch_size) || + u.x * image_size.x < -(patch_size * 0.5f) || + (1.0 - u.x) * image_size.x < -(patch_size * 0.5f) || + u.y * image_size.y < -(patch_size * 0.5f) || + (1.0 - u.y) * image_size.y < -(patch_size * 0.5f)) { u = initial_u; } -- 2.39.2