ValueError: Images of type float must be between -1 and 1.

Hi, I am having a problem trying to create an image object from an array. The problem is the array extends beyond -1 and 1. The pixel values are raw 32bit float values from a detector. array.dtype float32 summary(array) Mean: 0.00656827 Min: -6.1125 Median: 1.09516e-08 Max: 3.69815 image = skimage.img_as_float(array) File "/home/user/anaconda2/lib/python2.7/site-packages/skimage/util/dtype.py", line 291, in img_as_float return convert(image, np.float64, force_copy) File "/home/user/anaconda2/lib/python2.7/site-packages/skimage/util/dtype.py", line 195, in convert raise ValueError("Images of type float must be between -1 and 1.") ValueError: Images of type float must be between -1 and 1 I am using version 0.11.3 via anaconda on fedora 23 Sometimes I can get img_as_float to work if I use astype on the array first, but then it doesn't seem to change the values, and then skimage.io.Image() will fail with a similar error Thanks in advance for any help.

An update, the values are not 32 bit from the detector, the detector is 16bit. But the images have been aligned by a previous program, so they are interpolated to 32 bit precision. On Monday, February 8, 2016 at 8:38:14 PM UTC-5, Christopher wrote:
Hi, I am having a problem trying to create an image object from an array. The problem is the array extends beyond -1 and 1. The pixel values are raw 32bit float values from a detector.
array.dtype float32
summary(array) Mean: 0.00656827
Min: -6.1125 Median: 1.09516e-08 Max: 3.69815
image = skimage.img_as_float(array)
File "/home/user/anaconda2/lib/python2.7/site-packages/skimage/util/dtype.py", line 291, in img_as_float return convert(image, np.float64, force_copy) File "/home/user/anaconda2/lib/python2.7/site-packages/skimage/util/dtype.py", line 195, in convert raise ValueError("Images of type float must be between -1 and 1.") ValueError: Images of type float must be between -1 and 1
I am using version 0.11.3 via anaconda on fedora 23
Sometimes I can get img_as_float to work if I use astype on the array first, but then it doesn't seem to change the values, and then skimage.io.Image() will fail with a similar error
Thanks in advance for any help.

Hi Christopher! In some cases, skimage has to assume a certain input range for images, so that things like display brightness and type conversions are consistent between images. In cases like yours, this can get in the way. A few questions: - why are you using img_as_float at all, if your image is already float? - if img_as_float is being called by a particular function that you need, what is that function? - Does it have a `preserve_range` keyword argument? If so, try setting it to True. If it turns out that you're using a valid function for input of arbitrary ranges and still getting an error, that's a bug and we should raise an issue on github. Let us know! Juan. PS: If at all possible, you should think about switching to Python 3 for your main environment. =) On Tue, Feb 9, 2016 at 12:40 PM, Christopher <spagodo@gmail.com> wrote:
An update, the values are not 32 bit from the detector, the detector is 16bit. But the images have been aligned by a previous program, so they are interpolated to 32 bit precision.
On Monday, February 8, 2016 at 8:38:14 PM UTC-5, Christopher wrote:
Hi, I am having a problem trying to create an image object from an array. The problem is the array extends beyond -1 and 1. The pixel values are raw 32bit float values from a detector.
array.dtype float32
summary(array) Mean: 0.00656827
Min: -6.1125 Median: 1.09516e-08 Max: 3.69815
image = skimage.img_as_float(array)
File "/home/user/anaconda2/lib/python2.7/site-packages/skimage/util/dtype.py", line 291, in img_as_float return convert(image, np.float64, force_copy) File "/home/user/anaconda2/lib/python2.7/site-packages/skimage/util/dtype.py", line 195, in convert raise ValueError("Images of type float must be between -1 and 1.") ValueError: Images of type float must be between -1 and 1
I am using version 0.11.3 via anaconda on fedora 23
Sometimes I can get img_as_float to work if I use astype on the array first, but then it doesn't seem to change the values, and then skimage.io.Image() will fail with a similar error
Thanks in advance for any help.
-- You received this message because you are subscribed to the Google Groups "scikit-image" group. To unsubscribe from this group and stop receiving emails from it, send an email to scikit-image+unsubscribe@googlegroups.com. To post to this group, send email to scikit-image@googlegroups.com. To view this discussion on the web, visit https://groups.google.com/d/msgid/scikit-image/d8581def-a4fd-4b4c-bcab-71abf... <https://groups.google.com/d/msgid/scikit-image/d8581def-a4fd-4b4c-bcab-71abfc8fabca%40googlegroups.com?utm_medium=email&utm_source=footer> .
For more options, visit https://groups.google.com/d/optout.
participants (2)
-
Christopher
-
Juan Nunez-Iglesias