[SciPy-user] 16-bit images and ndimage filters

Pavlo Shchelokovskyy shchelokovskyy@gmail....
Fri Apr 10 10:58:29 CDT 2009


Hi all,
I'm experiencing strange behaviour of SciPy concerning the subject.

I need to process a 16-bit png image. The PIL is installed and
scipy.misc.imread loads the image just fine as int32 numpy array. But
then filters from scipy.ndimage give me the error "RuntimeError: array
type 5 not supported". Only after converting the image back and forth
(i.e. to float and back to int32) the error is gone.

So I do not know whether this problem is of PIL or SciPy but it seems
that we have two different int32-types.

I'm using Python 2.5.4 with NumPy 1.3, SciPy 0.7 and PIL 1.1.6 on Vista

Here is an example:

Python 2.5.4 (r254:67916, Dec 23 2008, 15:10:54) [MSC v.1310 32 bit
(Intel)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from scipy.ndimage import gaussian_filter
>>> from scipy.misc import imread
>>> from scipy import asarray, asfarray, int32
>>> img = imread('16bit.png')
>>> img.dtype
dtype('int32')
>>> gaussian_filter(img, 1)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Python25\lib\site-packages\scipy\ndimage\filters.py", line
268, in gaussian_filter
    mode, cval)
  File "C:\Python25\lib\site-packages\scipy\ndimage\filters.py", line
220, in gaussian_filter1d
    return correlate1d(input, weights, axis, output, mode, cval, 0)
  File "C:\Python25\lib\site-packages\scipy\ndimage\filters.py", line
129, in correlate1d
    origin)
RuntimeError: array type 5 not supported
>>> imgi = asarray(asfarray(img), int32)
>>> imgi.dtype
dtype('int32')
>>> gaussian_filter(imgi,1)
array([[11181, 11194, 11240, ..., 11412, 11451, 11438],
       [11332, 11328, 11350, ..., 11429, 11467, 11445],
       [11419, 11433, 11442, ..., 11437, 11451, 11411],
       ...,
       [11373, 11373, 11354, ..., 11688, 11712, 11728],
       [11486, 11472, 11461, ..., 11725, 11737, 11777],
       [11556, 11545, 11535, ..., 11834, 11807, 11803]])


More information about the SciPy-user mailing list