-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
PixelAccess class does not support Numpy int indexing #5048
Copy link
Copy link
Closed
Labels
Description
Hi developers, I happen to find out that PixelAcess class fails to use Numpy int as index, while Python built-in int, Python built-in float and even Numpy float all work fine. I'm using Python 3.6.1, Numpy 1.15.0, PIL 7.2.0.
An example is provided as follows.
code:
import numpy as np
from PIL import Image
import os
base = os.path.dirname(os.path.realpath(__file__))
im_path = os.path.join(base, 'xxxx.bmp')
pix = Image.open(im_path).load()
default_float_coor = [1.1, 9.9]
default_int_coor = [1,10]
numpy_float_coor = np.array([1.1, 9.9])
numpy_int_coor = np.array([1, 10])
print(type(pix))
print('pix at default_float_coor: ', pix[default_float_coor[0], default_float_coor[1]])
print('pix at default_int_coor: ', pix[default_int_coor[0], default_int_coor[1]])
print(type(numpy_float_coor[0]))
print('pix at numpy_float_coor: ', pix[numpy_float_coor[0], numpy_float_coor[1]])
print(type(numpy_int_coor[0]))
print('pix at numpy_int_coor: ', pix[numpy_int_coor[0],numpy_int_coor[1]])Output:
<class 'PixelAccess'>
pix at default_float_coor: (71, 71, 75)
pix at default_int_coor: (70, 70, 70)
<class 'numpy.float64'>
pix at numpy_float_coor: (71, 71, 75)
<class 'numpy.int32'>
Traceback (most recent call last):
File "e:/HanLab_MyLab/Updated Codes/PreProcessing/draft.py", line 22, in <module>
print('pix at numpy_int_coor: ', pix[numpy_int_coor[0],numpy_int_coor[1]])
TypeError: an integer is required
np.int64 fails too as I trialed.
It would add to much convenience if Numpy int could serve as index.
Thx.
Reactions are currently unavailable