开发者

how to get correct order of the image when converted to numpy array?

开发者 https://www.devze.com 2023-04-06 08:18 出处:网络
I am reading the image from the disk and I am converting it to a numpy array im=Image.open(infile) i开发者_如何学运维mdata = scipy.misc.fromimage(im)

I am reading the image from the disk and I am converting it to a numpy array

im=Image.open(infile)
i开发者_如何学运维mdata = scipy.misc.fromimage(im)

but the image is mirrored like it is stored on the disk.

How to read it in a correct order.

Thanks a lot.


If it is upside down:

imagedata = imagedata[::-1, :]

If it is swapped left to right:

imagedata = imagedata[:, ::-1]

And if it is transposed (flipped at the diagonal):

imagedata = imagedata.T

If you have more dimensions more (color, alpha, ...) flipping can be done by

imagedata = imagedata[::-1, ... ]

or

imagedata = imagedata[:, ::-1, ... ]

"..." is not a placeholder for something I do not know, but an implemented feature in numpy.

0

精彩评论

暂无评论...
验证码 换一张
取 消