Bonjour à tous,

je suis de retour^^. Je souhaiterais récupérer l'image générée par la transformée de Hough (qui permet de récupérer les lignes d'une image).

J'ai utilisé Skimage une librairie parfaite pour mon application.
Enfin, j'arrive bien évidemment à générer la transformée maintenant j'aimerais récupérer l'image avec uniquement les droites.
voici le code que j'ai imaginé , cependant je reste bloqué dans l'application des formules inverses de la transformée.
Selon,
Code hough_transform skimage et le site sur la fonction, elle retourne
H : 2-D ndarray of uint64 Hough transform accumulator.
distances : ndarray
Distance values.
theta : ndarray
Angles at which the transform was computed.
Normalement, je devrais pouvoir récupérer les x et y pour dessiner ensuite les lignes, voilà que cela se corse car je devrais appliquer des formules de ce genre : yl = d[x]/np.sin(angles[x]) - xl/np.tan(angles[x])
xl = d[x]/np.cos(angles[x]) - yl * np.sin(angles[x])
.
Cependant , je suis coincé car pour yl , il me faut xl et vice versa.

J'espère avoir été assez claire, je vous remercie d'avance pour votre aide.
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
 
 
class TestWidget(QtGui.QWidget):
    def __init__(self, parent=None):
        QtGui.QWidget.__init__(self, parent)
        self.scene = QtGui.QGraphicsScene()
        self.view = QtGui.QGraphicsView(self.scene)
        self.view.setBackgroundBrush(QtGui.QBrush(QtCore.Qt.darkGray))
        self.button = QtGui.QPushButton("Do test")
 
        layout = QtGui.QVBoxLayout()
        layout.addWidget(self.button)
        layout.addWidget(self.view)
        self.setLayout(layout)
        self.width = 100
        self.height = 200
        self.button.clicked.connect(self.do_test)
 
    def do_test(self):
        # an empty image
        fname = "C:\Users\Guillaume\Qt\workspaceQt\Test\Pics\molThreeClean.bmp"
        image = data.imread(fname, True, None)#data.camera()    
 
        theta = np.linspace(-np.pi / 2, np.pi / 2, 180)
 
        out,angles,d = hough(image, None)
 
        # precompute the sin and cos of the angles
        cos_theta = np.cos(theta)
        sin_theta = np.sin(theta)
        yl = []
        xl = []
        for x in xrange(self.width):
                yl = d[x]/np.sin(angles[x]) - x/np.tan(angles[x])
                print " value yl", yl 
                print "value xl",d[x]/np.cos(angles[x]) - yl * np.sin(angles[x])
#                yl.append()
#                xl.append(d[x]/np.cos(angles[x]) - yl * np.sin(angles[x]))
#         
#        pm = QtGui.QPixmap(self.width,self.height)
#        pm.fill(QtCore.Qt.transparent)
#        p = QtGui.QPainter(pm)
#       
#        for i in xrange(self.width):
#            p.setPen(QtGui.QColor(QtCore.Qt.black))
#            p.drawPoint(xl[i],yl[i])
#                
#                    
#        p.end()
#        print "loop end"
#        pixmap = QtGui.QPixmap(self.width,self.height)
#        p = QtGui.QPainter(pixmap)
#        p.drawPixmap(0,0,pm)
#        p.end()
#        
#    
#        print "display in run"
#        self.display_image(pixmap)
        self.plot(image)
 
    def plot(self,image):
        out,angles,d = hough(image, None)
        plt.subplot(1, 2, 1)
 
        plt.imshow(image, cmap=plt.cm.gray)
        plt.title('Input image')
 
        plt.subplot(1, 2, 2)
        plt.imshow(out, cmap=plt.cm.bone,
               extent=(d[0], d[-1],
                       np.rad2deg(angles[0]), np.rad2deg(angles[-1])))
        plt.title('Hough transform')
        plt.xlabel('Angle (degree)')
        plt.ylabel('Distance (pixel)')
 
        plt.subplots_adjust(wspace=0.4)
        plt.show()
    def display_image(self, pixMap):
        self.scene.clear()
        self.scene.setSceneRect(0,0,self.width,self.height)
        self.scene.addPixmap(pixMap)
 
        self.scene.update()
        self.save_image(pixMap.toImage())
    def save_image(self,img):
        img.save("C:\Users\xxx\Qt\workspaceQt\Test\Pics\Savings\skeletons\molThreeCleanSkull.bmp","BMP",-1)
if __name__ == "__main__":
    app = QtGui.QApplication(sys.argv)
    widget = TestWidget()
    widget.resize(640, 480)
    widget.show()
 
    sys.exit(app.exec_())