From 91c697c5f79984b77aae1927a559c1884181c546 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Sch=C3=B6nberger?= Date: Wed, 24 Dec 2014 17:28:44 +0100 Subject: [PATCH] Handle special case of 1 pixel image --- skimage/transform/_warps.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/skimage/transform/_warps.py b/skimage/transform/_warps.py index a27c1d42..5a9c8aa2 100644 --- a/skimage/transform/_warps.py +++ b/skimage/transform/_warps.py @@ -88,18 +88,23 @@ def resize(image, output_shape, order=1, mode='constant', cval=0, clip=True, else: # 2-dimensional interpolation - # 3 control points necessary to estimate exact AffineTransform - src_corners = np.array([[1, 1], [1, rows], [cols, rows]]) - 1 - dst_corners = np.zeros(src_corners.shape, dtype=np.double) - # take into account that 0th pixel is at position (0.5, 0.5) - dst_corners[:, 0] = col_scale * (src_corners[:, 0] + 0.5) - 0.5 - dst_corners[:, 1] = row_scale * (src_corners[:, 1] + 0.5) - 0.5 + if rows == 1 and cols == 1: + tform = AffineTransform(translation=(orig_cols / 2.0 - 0.5, + orig_rows / 2.0 - 0.5)) + else: + # 3 control points necessary to estimate exact AffineTransform + src_corners = np.array([[1, 1], [1, rows], [cols, rows]]) - 1 + dst_corners = np.zeros(src_corners.shape, dtype=np.double) + # take into account that 0th pixel is at position (0.5, 0.5) + dst_corners[:, 0] = col_scale * (src_corners[:, 0] + 0.5) - 0.5 + dst_corners[:, 1] = row_scale * (src_corners[:, 1] + 0.5) - 0.5 - tform = AffineTransform() - tform.estimate(src_corners, dst_corners) + tform = AffineTransform() + tform.estimate(src_corners, dst_corners) out = warp(image, tform, output_shape=output_shape, order=order, - mode=mode, cval=cval, clip=clip, preserve_range=preserve_range) + mode=mode, cval=cval, clip=clip, + preserve_range=preserve_range) return out