Only clip for ndimage.map_coordinates case

This commit is contained in:
Johannes Schönberger
2013-10-02 17:10:46 +02:00
parent 3e3a52331d
commit beeb597ddf
+11 -9
View File
@@ -1052,15 +1052,17 @@ def warp(image, inverse_map=None, map_args={}, output_shape=None, order=1,
out = ndimage.map_coordinates(image, coords, prefilter=prefilter,
mode=mode, order=order, cval=cval)
# The spline filters sometimes return results outside [0, 1],
# so clip to ensure valid data
clipped = np.clip(out, 0, 1)
# The spline filters sometimes return results outside [0, 1],
# so clip to ensure valid data
clipped = np.clip(out, 0, 1)
if mode == 'constant' and not (0 <= cval <= 1):
clipped[out == cval] = cval
if mode == 'constant' and not (0 <= cval <= 1):
clipped[out == cval] = cval
if clipped.ndim == 3 and orig_ndim == 2:
# remove singleton dim introduced by atleast_3d
return clipped[..., 0]
out = clipped
if out.ndim == 3 and orig_ndim == 2:
# remove singleton dimension introduced by atleast_3d
return out[..., 0]
else:
return clipped
return out