From 3fa227e1b691068c0abeb8177abedc481a0a644e Mon Sep 17 00:00:00 2001 From: Bruno Madeira Date: Tue, 13 Aug 2024 01:01:39 +0100 Subject: [PATCH] updated patch_search.py - make clearer that there are two different cases; avoid misleading var name and len check when not using tolerance. --- patch_search.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/patch_search.py b/patch_search.py index 4c27cf0..2157447 100644 --- a/patch_search.py +++ b/patch_search.py @@ -102,8 +102,11 @@ def find_patch_vx(ref_block_left, ref_block_right, ref_block_top, ref_block_bott templ=ref_block_bottom[:overlap, :], method=template_method)) err_mat = compute_errors(blks_diffs, version) - zeroless_err_mat = err_mat[err_mat > 0 if tolerance > 0 else True] # ignore zeroes to enforce tolerance usage - min_val = np.min(zeroless_err_mat) if len(zeroless_err_mat) > 0 else 0 # mind edge case where all are zero + if tolerance > 0: + # attempt to ignore zeroes in order to apply tolerance, but mind edge case (e.g., blank image) + min_val = np.min(pos_vals) if (pos_vals := err_mat[err_mat > 0]).size > 0 else 0 + else: + min_val = np.min(err_mat) y, x = np.nonzero(err_mat <= (1.0 + tolerance) * min_val) c = rng.integers(len(y)) y, x = y[c], x[c]