Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import sys, os, numpy
- sys.path.append(r"D:\tools\OSGeo4W64\apps\Python27")
- os.environ['PATH'] = r"D:\tools\OSGeo4W64\bin"
- import networkx as nx
- from PIL import Image
- import matplotlib.pyplot as plt
- # lire une matrice (Adjacency matrix)
- # à partir d'une image
- # https://en.wikipedia.org/wiki/Adjacency_matrix
- im = Image.open(r"raster/matrix.png")
- # matrix.png
- # 0 1 2 3 4 5 <- noeuds
- #
- # 0 0 1 0 0 1 0
- # 1 1 0 1 0 1 0
- # 2 0 1 0 1 0 0
- # 3 0 0 1 0 1 1
- # 4 1 1 0 1 0 0
- # 5 0 0 0 1 0 0
- imarray = numpy.array(im)
- extract = imarray[:,:,0]
- A=numpy.matrix(extract)
- # on va créer le graphe à partir de la matrice
- # on divise par 255 (le max) pour avoir des poinds allant
- # de 0 à 1
- G=nx.from_numpy_matrix(A/255.0)
- nx.draw(G, with_labels=True)
- plt.show()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement