p5
p5 copied to clipboard
load_image data has incorrect shape ?
Describe the bug
Loading an image it seems to me the _data
numpy array has the wrong shape, at least it feels this way to me but I can be off.
To Reproduce
from p5 import size, load_image, load_pixels, image, run
from p5.core.image import PImage
akira_w = 200
akira_h = 89
def setup():
global img, sorted
size(2 * akira_w, akira_h)
img = load_image("akira.png")
sorted = PImage(akira_w, akira_h)
sorted.load_pixels()
with load_pixels():
# fillme = np.random.random_integers(0, 255, (240,240,4))
fillme = img._data
print(fillme.shape)
for x in range(akira_w):
for y in range(akira_h):
sorted[x, y] = fillme[y][x]
def draw():
image(img, (0, 0), (akira_w, akira_h))
image(sorted, (akira_w, 0), (akira_w, akira_h))
if __name__ == "__main__":
run()
this code ends up with this image:
it feels akward to have to reverse x and y above in sorted[x, y] = fillme[y][x]
Expected behavior
I would expect to write sorted[x, y] = fillme[x][y]
to have the image copied properly
Screenshots see above
System information:
- p5 release (version number or latest commit): 0.7.0
- Python version: 3.8.5
- Operating system: debian buster
Additional context Add any other context about the problem here.
I see what you mean: [y][x] vs [x][y].
Is _data an implementation detail to be rationalized -- or is it part of the API?
At a quick look, this might have something to do with PIL Image? At any rate, some internal reshape mapping seems to be intentional:
https://github.com/p5py/p5/blob/d7a160ac66361e06b6db70a0436cb365693ebaf3/p5/core/image.py#L179
Numpy doesn’t have a sense of ‘direction’, just axis 1, axis 2, .... axis n.
Numpy expects position as [row][col]. On the screen/canvas, a pixels is [y rows down][x cola across]. Hence, [y][x]
On Sat, Sep 12, 2020 at 6:08 PM Jeremy Douglass [email protected] wrote:
I see what you mean: [y][x] vs [x][y].
Is _data an implementation detail to be rationalized -- or is it part of the API?
At a quick look, this might have something to do with PIL Image? At any rate, some internal reshape mapping seems to be intentional:
https://github.com/p5py/p5/blob/d7a160ac66361e06b6db70a0436cb365693ebaf3/p5/core/image.py#L179
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/p5py/p5/issues/243#issuecomment-691577203, or unsubscribe https://github.com/notifications/unsubscribe-auth/AP6TTJ4ZG7FENRV6NU3X5JLSFQEO7ANCNFSM4QMAUMAQ .