Convert a large PIL image to a numpy array

Consider the following script:

from PIL import Image import numpy as np im = Image.new("F", (512, 512), 0.) 

The result is

 >>> np.asarray(im) array([[ 0., 0., 0., ..., 0., 0., 0.], [ 0., 0., 0., ..., 0., 0., 0.], [ 0., 0., 0., ..., 0., 0., 0.], ..., [ 0., 0., 0., ..., 0., 0., 0.], [ 0., 0., 0., ..., 0., 0., 0.], [ 0., 0., 0., ..., 0., 0., 0.]], dtype=float32) 

as i expected. However, if I have a larger image, say im = Image.new("F", (10240, 8600), 0.) , the conversion results in an array with the PIL image as the only element:

 >>> np.asarray(im) array(<PIL.Image.Image image mode=F size=10240x8600 at 0x122D8A08>, dtype=object) 

Is this normal behavior? Is there a workaround? Running Python 2.7 and PIL 1.1.7 on a computer running Windows 7. On Unix, the problem does not occur.

+6
source share

Source: https://habr.com/ru/post/956641/


All Articles