[Numpy-discussion] Question about slicing
jorgesmbox-ml@yah...
jorgesmbox-ml@yah...
Sat May 16 03:42:50 CDT 2009
Hi,
I am just starting with numpy, pyhton and related others. I work on image processing basically. Now, my question is: what is the expected behaviour when slicing a view of an array? The following example might give some background on what I tried to do and the results obatined (which I don't understand):
I read an image with PIL but, for whatever reason (different conventions I suppose), it comes upside down. This doesn't change when (I don't know the exact term for this) transforming the image to ndarray with 'array(img)'. I don't feel comfortable working with upside down images, so this had to be fixed. I tried to be smart and avoid copying the whole image:
aimg = array(img)[::-1]
and it worked!, but I am interested actually in sub-regions of this image, so the next I did was:
roi = aimg[10:20,45:50,:]
And to my surprise the result was like if I was slicing the original, upside down, image instead of aimg. Can someone explain me what's going on here? I searched and looked at the documentation but I couldn't find an answer. Maybe I am not looking properly. Is the only way to turn the image to perform a copy?
Thanks,
Jorge
More information about the Numpy-discussion
mailing list