From 06c2ed9d83657d4a2d6224a5f79ed7d395909513 Mon Sep 17 00:00:00 2001 From: Tony S Yu Date: Thu, 9 Feb 2012 10:37:32 -0500 Subject: [PATCH] DOC: Add example of bad dtype conversion. --- doc/source/user_guide/data_types.txt | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/doc/source/user_guide/data_types.txt b/doc/source/user_guide/data_types.txt index da7f2ed4..1db55543 100644 --- a/doc/source/user_guide/data_types.txt +++ b/doc/source/user_guide/data_types.txt @@ -30,7 +30,14 @@ but, for efficiency, *may return an image of a different dtype* (see `Output types`_). If you need a particular dtype, ``skimage`` provides utility functions that convert dtypes and properly rescale image intensities (see `Input types`_). You should **never use** ``astype`` on an image, because it -violates these assumptions about the dtype range. +violates these assumptions about the dtype range:: + + >>> from skimage import img_as_float + >>> image = np.arange(0, 50, 10, dtype=np.uint8) + >>> print image.astype(np.float) # These float values are out of range. + [ 0. 10. 20. 30. 40.] + >>> print img_as_float(image) + [ 0. 0.03921569 0.07843137 0.11764706 0.15686275] Input types