Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PixelAccess class does not support Numpy int indexing #5048

Closed
X-Bruce-Y opened this issue Nov 20, 2020 · 4 comments · Fixed by #5206
Closed

PixelAccess class does not support Numpy int indexing #5048

X-Bruce-Y opened this issue Nov 20, 2020 · 4 comments · Fixed by #5206
Labels

Comments

@X-Bruce-Y
Copy link

X-Bruce-Y commented Nov 20, 2020

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.

@UrielMaD
Copy link
Contributor

Hello @radarhere I'd like to take this issue

@radarhere
Copy link
Member

Feel free to create a PR!

@radarhere
Copy link
Member

I've created PR #5206 to resolve this.

@X-Bruce-Y
Copy link
Author

I've created PR #5206 to resolve this.

Grateful to know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants