Pour déterminer la taille d'une image avec python il existe plusieurs solutions. Le plus simple est d'utiliser scipy comme ceci:
>>> from scipy import misc
>>> M = misc.imread('lena.png')
>>> M.shape
(512, 512, 3)
Dans l'exemple ci-dessus l'image est lena.png dont les dimensions sont 512*512 qu'on peut obtenir:
>>> DIM = M.shape
>>> DIM[0]
512
>>> DIM[1]
512
L'autre possibilité est de passer par PIL:
>>> from PIL import Image
>>> img = Image.open('lena.png')
>>> img.size
(512, 512)
Recherches associées
Liens | Site |
---|---|
scipy.misc.imread | scipy doc |
Image manipulation and processing using Numpy and Scipy | Scipy Doc |
python - RGB matrix of an image | stackoverflow |
convert rgb image to grayscale in python | stackoverflow |
PIL | PIL |
How do I get the picture size with PIL? | stackoverflow |
How to obtain image size using standard Python class (without using external library)? | stackoverflow |