From 10283f5bb2b72b8b35d385636654c0a7f6f68fd0 Mon Sep 17 00:00:00 2001 From: Aaron LI Date: Wed, 26 Oct 2016 20:35:16 +0800 Subject: utils/rotate.py: Fix two bugs which cause wrong results * Fix the wrong output shape: wrongly swap the row and column * Fix the area mapping method, which may give zero values when the index of the input is integer, which cause problem to calculate the overlapping areas. --- fg21sim/utils/rotate.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/fg21sim/utils/rotate.py b/fg21sim/utils/rotate.py index b89365c..84e4f9d 100644 --- a/fg21sim/utils/rotate.py +++ b/fg21sim/utils/rotate.py @@ -61,10 +61,10 @@ def rotate_center(imgin, angle, interp=True, reshape=True, fill_value=0.0): if reshape: dest = np.dot(corners.astype(np.float64), mrotate) # XXX: ``numba`` does not support ``np.max()`` with arguments - minc = np.min(dest[:, 0]) - minr = np.min(dest[:, 1]) - maxc = np.max(dest[:, 0]) - maxr = np.max(dest[:, 1]) + minr = np.min(dest[:, 0]) + minc = np.min(dest[:, 1]) + maxr = np.max(dest[:, 0]) + maxc = np.max(dest[:, 1]) nr = int(maxr - minr + 0.5) nc = int(maxc - minc + 0.5) else: @@ -110,6 +110,15 @@ def rotate_center(imgin, angle, interp=True, reshape=True, fill_value=0.0): # Use area mapping of the 4 closest input pixels idx_rf, idx_cf = np.floor(p_in).astype(np.int64) idx_rc, idx_cc = np.ceil(p_in).astype(np.int64) + # NOTE: + # It is possible that ``p_in[0]`` and/or ``p_in[1]`` + # are just integers, which cause ``idx_rf == idx_rc`` + # and/or ``idx_cf == idx_cc``, which further lead to + # the calculated pixel value ``p_val = 0``. + if idx_rf == idx_rc: + idx_rc += 1 + if idx_cf == idx_cc: + idx_cc += 1 # Calculate the overlapping areas p_r, p_c = p_in p4_area = np.array([(idx_rc - p_r) * (idx_cc - p_c), -- cgit v1.2.2