Negative coordinate? #9372
-
|
Hello, I use Pillow with my pupils in computer science class. It's a good exercise for visualizing matrices and coordinates. This is the first time I've encountered the problem of negative coordinates. For example, this code correctly returns an image with horizontal symmetry. from PIL import Image
image=Image.open("image-test.png")
L,H =image.size
#L'image a une résolution de L en largeur et H en hauteur
image_sym = Image.new("RGB",(L,H)) # création de l’image destination
#en RGB (rouge, vert, bleu)
# Inversion de l'image
for y in range(H): #
for x in range(L):#
p = image.getpixel((x,y)) #
image_sym.putpixel((x,-y),p) #
image_sym.show()I'm trying to understand why with the source code on github, but I don't have much time to look at everything, and the documentation on the coordinate system is rather brief. One might think of Python slices ([-1]), but these are tuples. thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
From the code, the reason for this behaviour is actually not in Python. In our Python code, we move into C at the line Line 2106 in 0a1d6c3 From there, our C code attempts to fix your negative co-ordinates at Lines 1868 to 1873 in 0a1d6c3 |
Beta Was this translation helpful? Give feedback.
-
|
Thanks, any reason for that ? (because my pupils shouted "IT works" despite of those negative coordinate) |
Beta Was this translation helpful? Give feedback.
A user proposed the change in #3406 'so we can get the last pixels easily'.
It was released as part of Pillow 5.4.0 - https://pillow.readthedocs.io/en/stable/releasenotes/5.4.0.html#negative-indexes-in-pixel-access