IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Python Discussion :

Ouverture image Landsat matplotlib


Sujet :

Python

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2012
    Messages
    160
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2012
    Messages : 160
    Points : 41
    Points
    41
    Par défaut Ouverture image Landsat matplotlib
    Bonsoir,


    Je suis débutant en python, et j'aimerai ouvrir une image Landsat TIFF (taille importante). J'utilise l'éditeur Canopy sous Windows 7, et voici mon programme très simple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
     
    from matplotlib import pyplot
    from matplotlib import pyplot as plt
    im=plt.imread('LE72160152001246EDC00_B8.TIF')
    plt.imshow(im)
    plt.show(im)
    Mais bon le programme plante complet, la fenêtre de figure s'ouvre mais rien ne s'affiche (ne répond plus). (même si j'enleve le plt.show(im)).
    En fait je suis plus à l'aise en matlab, du coup avec le programme suivant cela marche bien sous matlab :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
     
    imread('LE71490352001241SGS00_B8.TIF');
    figure
    im=imread('LE71490352001241SGS00_B8.TIF');
    imshow(im)
    Du coup, je me suis dit que python ne gère pas de la même manière les images.
    J'ai donc regardé le type d'image (sous matlab) :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
      Name          Size                   Bytes  Class    Attributes
     
      im        14301x15781            225684081  uint8
    Je ne comprend pas très bien du coup. Est-ce que quelqu'un pourrais m'aider pour faire ce truc simple?

    Merci d'avance

  2. #2
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2012
    Messages
    160
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2012
    Messages : 160
    Points : 41
    Points
    41
    Par défaut
    Ah et j'ai oublié les messages d'erreurs :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
    ---------------------------------------------------------------------------
    ValueError                                Traceback (most recent call last)
    C:\Users\Romain\AppData\Local\Enthought\Canopy\App\appdata\canopy-1.1.0.1371.win-x86_64\lib\site-packages\IPython\utils\py3compat.pyc in execfile(fname, glob, loc)
        174             else:
        175                 filename = fname
    --> 176             exec compile(scripttext, filename, 'exec') in glob, loc
        177     else:
        178         def execfile(fname, *where):
     
    C:\Users\Romain\Desktop\Cosi-corr\ouvert_image2.py in <module>()
          9 im=plt.imread('LE72160152001246EDC00_B8.TIF')
         10 plt.imshow(im)
    ---> 11 plt.show(im)
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\pyplot.pyc in show(*args, **kw)
        143     """
        144     global _show
    --> 145     _show(*args, **kw)
        146 
        147 
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\backend_bases.pyc in __call__(self, block)
         88 
         89         if block is not None:
    ---> 90             if block:
         91                 self.mainloop()
         92                 return
     
    ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
    Et avec la commande im.any() ou im.all() :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
     
     
    plt.imshow(im.any())
    ---------------------------------------------------------------------------
    TypeError                                 Traceback (most recent call last)
    <ipython-input-7-e5b2c05b0eec> in <module>()
    ----> 1 plt.imshow(im.any())
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\pyplot.pyc in imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, hold, **kwargs)
       2890                         vmax=vmax, origin=origin, extent=extent, shape=shape,
       2891                         filternorm=filternorm, filterrad=filterrad,
    -> 2892                         imlim=imlim, resample=resample, url=url, **kwargs)
       2893         draw_if_interactive()
       2894     finally:
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\axes.pyc in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, shape, filternorm, filterrad, imlim, resample, url, **kwargs)
       7297                        filterrad=filterrad, resample=resample, **kwargs)
       7298 
    -> 7299         im.set_data(X)
       7300         im.set_alpha(alpha)
       7301         self._set_artist_props(im)
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\image.pyc in set_data(self, A)
        427         if (self._A.ndim not in (2, 3) or
        428             (self._A.ndim == 3 and self._A.shape[-1] not in (3, 4))):
    --> 429             raise TypeError("Invalid dimensions for image data")
        430 
        431         self._imcache = None
     
    TypeError: Invalid dimensions for image data

  3. #3
    Membre éclairé
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Janvier 2013
    Messages
    388
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : Conseil

    Informations forums :
    Inscription : Janvier 2013
    Messages : 388
    Points : 692
    Points
    692
    Par défaut
    Salut,
    L'erreur vient de la méthode show. Il faut faire :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    ...
    plt.imshow(im)
    plt.show()
    ...
    Pas besoin de all ni any.

  4. #4
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2012
    Messages
    160
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2012
    Messages : 160
    Points : 41
    Points
    41
    Par défaut
    Et non, voilàs ce qu'il se passe avec ce que tu m'a suggérés :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
     
    ---------
    MemoryError                               Traceback (most recent call last)
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\backends\backend_qt4.pyc in resizeEvent(self, event)
        297         self.figure.set_size_inches( winch, hinch )
        298         FigureCanvasBase.resize_event(self)
    --> 299         self.draw()
        300         self.update()
        301         QtGui.QWidget.resizeEvent(self, event)
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\backends\backend_qt4agg.pyc in draw(self)
        146         # causes problems with code that uses the result of the
        147         # draw() to update plot elements.
    --> 148         FigureCanvasAgg.draw(self)
        149         self.update()
        150 
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\backends\backend_agg.pyc in draw(self)
        449 
        450         try:
    --> 451             self.figure.draw(self.renderer)
        452         finally:
        453             RendererAgg.lock.release()
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
         52     def draw_wrapper(artist, renderer, *args, **kwargs):
         53         before(artist, renderer)
    ---> 54         draw(artist, renderer, *args, **kwargs)
         55         after(artist, renderer)
         56 
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\figure.pyc in draw(self, renderer)
       1032         dsu.sort(key=itemgetter(0))
       1033         for zorder, a, func, args in dsu:
    -> 1034             func(*args)
       1035 
       1036         renderer.close_group('figure')
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
         52     def draw_wrapper(artist, renderer, *args, **kwargs):
         53         before(artist, renderer)
    ---> 54         draw(artist, renderer, *args, **kwargs)
         55         after(artist, renderer)
         56 
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\axes.pyc in draw(self, renderer, inframe)
       2084 
       2085         for zorder, a in dsu:
    -> 2086             a.draw(renderer)
       2087 
       2088         renderer.close_group('axes')
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\artist.pyc in draw_wrapper(artist, renderer, *args, **kwargs)
         52     def draw_wrapper(artist, renderer, *args, **kwargs):
         53         before(artist, renderer)
    ---> 54         draw(artist, renderer, *args, **kwargs)
         55         after(artist, renderer)
         56 
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\image.pyc in draw(self, renderer, *args, **kwargs)
        362                               " correctly with this backend.")
        363 
    --> 364             im = self.make_image(renderer.get_image_magnification())
        365             if im is None:
        366                 return
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\image.pyc in make_image(self, magnification)
        586         im, xmin, ymin, dxintv, dyintv, sx, sy = \
        587             self._get_unsampled_image(self._A, [_x1, _x2, _y1, _y2],
    --> 588                                       transformed_viewLim)
        589 
        590         fc = self.axes.patch.get_facecolor()
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\image.pyc in _get_unsampled_image(self, A, image_extents, viewlim)
        202             else:
        203                 if self._rgbacache is None:
    --> 204                     x = self.to_rgba(self._A, bytes=False)
        205                     # Avoid side effects: to_rgba can return its argument
        206                     # unchanged.
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\cm.pyc in to_rgba(self, x, alpha, bytes)
        259         x = ma.asarray(x)
        260         x = self.norm(x)
    --> 261         x = self.cmap(x, alpha=alpha, bytes=bytes)
        262         return x
        263 
     
    C:\Users\Romain\AppData\Local\Enthought\Canopy\User\lib\site-packages\matplotlib\colors.pyc in __call__(self, X, alpha, bytes)
        605                 # override its alpha just as for any other value.
        606 
    --> 607         rgba = np.empty(shape=xa.shape + (4,), dtype=lut.dtype)
        608         lut.take(xa, axis=0, mode='clip', out=rgba)
        609                     #  twice as fast as lut[xa];
     
    MemoryError:
    C'est assez bizarre d'avoir memory error : j'ai une machine avec 6GO de ram, un processeur 4 coeurs i7...je ne vois pas ce que je peux faire de plus, et cela s'ouvre sans probleme sur matlab !

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2012
    Messages
    160
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2012
    Messages : 160
    Points : 41
    Points
    41
    Par défaut
    Personne n'a d'idées, de conseils ?

  6. #6
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 283
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 283
    Points : 36 770
    Points
    36 770
    Par défaut
    Citation Envoyé par romainmill Voir le message
    Personne n'a d'idées, de conseils ?
    Comment faire tomber en marche un programme qui plante parce qu'il n'arrive pas a allouer assez de mémoire (virtuelle) lorsqu'on lui demande d'afficher un TIFF de +200Mo?

    Si vous utilisez un OS 64 bits et un Python 64 bits, il faut vérifier que l'OS permet d'allouer une quantité de mémoire virtuelle supérieure a celle que demande l'affichage du TIFF (via Python/Canopy).

    Pour les détails du "comment" faire tout ça, c'est essentiellement de l'administration système, des tests d'allocation de mémoire virtuelle.
    Ce qui savent traînent en général dans les forum OS.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  7. #7
    Expert éminent
    Avatar de fred1599
    Homme Profil pro
    Lead Dev Python
    Inscrit en
    Juillet 2006
    Messages
    3 813
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Lead Dev Python
    Secteur : Arts - Culture

    Informations forums :
    Inscription : Juillet 2006
    Messages : 3 813
    Points : 7 102
    Points
    7 102
    Par défaut
    Il est aussi conseillé d'utiliser les outils adéquates (j'y connais pas grand chose mais avec un peu de recherches...) pour faire ce genre de travail et il se trouve qu'une bibliothèque (GDAL) libre existe.

    Il ne suffit plus que de retrouver une API Python pour cette librairie grâce à notre ami google, et le résultat est le suivant : GDAL API python

    Il en existe peut-être/sans doute d'autres, il faut chercher...

    Bonne continuation.
    Celui qui trouve sans chercher est celui qui a longtemps cherché sans trouver.(Bachelard)
    La connaissance s'acquiert par l'expérience, tout le reste n'est que de l'information.(Einstein)

  8. #8
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 283
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 283
    Points : 36 770
    Points
    36 770
    Par défaut
    Citation Envoyé par fred1599 Voir le message
    Il est aussi conseillé d'utiliser les outils adéquates (j'y connais pas grand chose mais avec un peu de recherches...) pour faire ce genre de travail et il se trouve qu'une bibliothèque (GDAL) libre existe.
    Canopy est un bon framework, il inclut aussi GDAL.
    Après que veut faire le PO... mystère.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  9. #9
    Expert éminent

    Homme Profil pro
    Inscrit en
    Octobre 2008
    Messages
    4 300
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2008
    Messages : 4 300
    Points : 6 780
    Points
    6 780
    Par défaut
    Salut,

    Il y a une raison pour utiliser Matplotlib ?

    Tu veux tracer par dessus l'image ou simplement l'afficher ?

    Parce que, une TIFF de 228 Mo, il n'y a aucune raison que ça coince, avec la plupart des frameworks graphiques.

    Tu as le lien pour cette image ?

  10. #10
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2012
    Messages
    160
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2012
    Messages : 160
    Points : 41
    Points
    41
    Par défaut
    Merci pour vos réponses ! du coup je vais regarder un peu du côté des forums OS alors.

    VinsS, je cherche à afficher l'image, mais je veux aussi tracer par dessus.

    Le lien ? en fait ces images sont téléchargeable via l'USGS http://glovis.usgs.gov/.

    mais je peux envoyer par mail aussi.

  11. #11
    Expert éminent sénior
    Homme Profil pro
    Architecte technique retraité
    Inscrit en
    Juin 2008
    Messages
    21 283
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Manche (Basse Normandie)

    Informations professionnelles :
    Activité : Architecte technique retraité
    Secteur : Industrie

    Informations forums :
    Inscription : Juin 2008
    Messages : 21 283
    Points : 36 770
    Points
    36 770
    Par défaut
    Citation Envoyé par romainmill Voir le message
    VinsS, je cherche à afficher l'image, mais je veux aussi tracer par dessus.
    La vraie question est de savoir si matplotlib est l'outil le plus adapte pour ce que vous voulez faire (compare CGAL déjà mentionne).
    Passez du temps a comprendre pourquoi l'image ne s'affiche pas avec matplotlib a peu d’intérêt sans ca.

    - W
    Architectures post-modernes.
    Python sur DVP c'est aussi des FAQs, des cours et tutoriels

  12. #12
    Membre du Club
    Profil pro
    Inscrit en
    Avril 2012
    Messages
    160
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2012
    Messages : 160
    Points : 41
    Points
    41
    Par défaut
    J'utilise canopy express, et il ne comprend ni le module CGAL ni le module GDAL.

    Je vais voir comment installer ces bibliothèques du coup.

Discussions similaires

  1. ouverture image jointe impossible
    Par wrdaniel dans le forum Outlook
    Réponses: 5
    Dernier message: 07/08/2008, 10h43
  2. ouverture image dynamique
    Par wootz dans le forum Général JavaScript
    Réponses: 2
    Dernier message: 03/05/2007, 14h24
  3. ouverture image nouvelle fenêtre
    Par Gary_Stoupy dans le forum Général JavaScript
    Réponses: 9
    Dernier message: 06/03/2007, 10h43
  4. ouverture image binaire
    Par mathieutlse dans le forum Langage
    Réponses: 2
    Dernier message: 10/01/2003, 11h05

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo