pillow provides size
to examine the resolution of an image.
>> from PIL import Image
>> img = Image.open('Lenna.png')
>> img.size
(512, 512)
is there a way to examine how many memory the image is occupying? is the image using 512*512*4 Bytes memory?
You could use the
sys
library to get the size of an object in bytes. The difference with Kai's answer is that he's calculating the size of the image on the disk, while this calculates the size of the loaded python object (with all its metadata):EDIT: After seeing this website,
sys.getsizeof()
seems to work mainly for primitive types.You could have a look at a more thorough implementation (
deep_getsizeof()
) here .This post gives also a lot of details.
And finally, there is also the
pympler
library that provides tools to calculate the RAM memory used by an object.or