Merge pull request #477 from JDWarner/convert_dtype_to_astype

Use `image.astype(dtype)` instead of `dtype(image)`
This commit is contained in:
Tony S Yu
2013-03-21 20:11:15 -07:00
+5 -5
View File
@@ -176,7 +176,7 @@ def convert(image, dtype, force_copy=False, uniform=False):
if kind_in == 'b':
# from binary image, to float and to integer
result = dtype(image)
result = image.astype(dtype)
if kind != 'f':
result *= dtype(dtype_range[dtype][1])
return result
@@ -195,7 +195,7 @@ def convert(image, dtype, force_copy=False, uniform=False):
# floating point -> floating point
if itemsize_in > itemsize:
prec_loss()
return dtype(image)
return image.astype(dtype)
# floating point -> integer
prec_loss()
@@ -218,7 +218,7 @@ def convert(image, dtype, force_copy=False, uniform=False):
image *= (imax - imin + 1.0) / 2.0
np.floor(image, out=image)
np.clip(image, imin, imax, out=image)
return dtype(image)
return image.astype(dtype)
if kind == 'f':
# integer -> floating point
@@ -236,7 +236,7 @@ def convert(image, dtype, force_copy=False, uniform=False):
image *= 2.0
image += 1.0
image /= imax_in - imin_in
return dtype(image)
return image.astype(dtype)
if kind_in == 'u':
if kind == 'i':
@@ -262,7 +262,7 @@ def convert(image, dtype, force_copy=False, uniform=False):
image -= imin_in
image = _scale(image, 8 * itemsize_in, 8 * itemsize, copy=False)
image += imin
return dtype(image)
return image.astype(dtype)
def img_as_float(image, force_copy=False):