好吧,所以我試圖採取圖像的紅色通道,並將其繪製(最好是3d)到圖像。圖像是480x640(或左右),並從網絡攝像頭拍攝。我目前使用scipy,numpy和python來獲取圖像,提取他的紅色通道並處理它。這一切都有效。發生繪製圖像通過強度的紅色通道
然而,當我嘗試繪製它,2個不同的問題,這取決於我如何嘗試繪圖:
1)寬度不匹配,它不喜歡的圖像不是正方形。
2)它只繪製圖像的一行(x val = 0,所有y vals)。
我附上了相關的代碼。評論無處不在,因爲當我嘗試不同的方式。
fig = plt.figure()
#ax = Axes3D(fig)
#ax = fig.add_subplot(111, projection='3d')
X = [range(480), range(480)]
Y = [range(480), range(480)]
#X = range(len(self.R))
#Y = range(len(self.R))
'''
surf = ax.plot_surface(X, Y, np.resize(self.R, (480, 480)) , rstride=1, cstride=10, cmap=cm.jet, linewidth=0, antialiased=False)
ax.set_zlim3d(0.0, 255.0)
ax.w_zaxis.set_major_locator(LinearLocator(100))
ax.w_zaxis.set_major_formatter(FormatStrFormatter('%.03f'))
m = cm.ScalarMappable(cmap=cm.jet)
m.set_array(self.frame_in)
fig.colorbar(m)
np.savetxt("tmp.txt", self.R)
'''
#np.savetxt("tmp.out", self.R[0])
#np.savetxt("tmp.out1", self.R[1])
#np.savetxt("tmp.txt", self.frame_in, "[ %s ]", "\t")
#plt.subplot(212)
#x, y = self.R.shape
#x = range(x)
#y = range(y)
#X, Y = np.meshgrid(x, y)
plt.scatter(X, Y, self.R)
#plt.pcolormesh(self.R)
#plt.colorbar()
#ax.scatter(x, y, self.R, c='r', marker='o')
plt.show()
如果需要,我可以清理代碼,但我希望每個人都能看到我嘗試過的多種方式。我錯過了一些真正愚蠢的簡單嗎?它沒有任何意義,它將與第一行一起工作,而不是全部。
在此先感謝!
你可以發佈一個可運行的代碼,也許使用生成的圖像?請添加最少的額外代碼,但可運行的內容會有所幫助。 – tom10 2014-09-26 19:32:15
你有圖像的矩陣嗎?在任何情況下,具有[nx,ny,4]形狀的圖像都可以傳遞給matplotlib.pyplot.imshow。 [nx,ny,0]是R通道,[nx,ny,1]是G通道,[nx,ny,2]是B通道。 [nx,ny,3]是透明度的「alpha」通道。如果您傳遞的圖像爲[nx,ny]形狀,則會假定其中一些可用的色彩圖... – Alejandro 2014-10-01 17:30:56