資源簡介
輸入圖片轉為灰度圖,使用numpy將其轉化為數字矩陣
用matplot將矩陣在三維空間中繪制出來
什么情況,好久不看下載積分怎么變成8了,太過分了吧,我設置的是3積分啊
用matplot將矩陣在三維空間中繪制出來
什么情況,好久不看下載積分怎么變成8了,太過分了吧,我設置的是3積分啊

代碼片段和文件信息
#?-*-?coding:?utf-8?-*-
import?numpy?as?np
import?cv2?as?cv
import?matplotlib.pyplot?as?plt
from?mpl_toolkits.mplot3d?import?Axes3D
from?matplotlib?import?cm
from?matplotlib.ticker?import?LinearLocator?FormatStrFormatter
fig?=?plt.figure(figsize=(1612))
ax?=?fig.gca(projection=“3d“)
img?=?cv.imread(“pic/tina.jpg“)
img?=?cv.cvtColor(imgcv.COLOR_BGR2GRAY)
imgd?=?np.array(img)??????#?image類?轉?numpy
#?準備數據
sp?=?img.shape
h?=?int(sp[0])#height(rows)?of?image
w?=?int(sp[1])#width(colums)?of?image
x?=?np.arange(0w1)
y?=?np.arange(0h1)
xy?=?np.meshgrid(xy)
z?=?imgd
surf?=?ax.plot_surface(x?y?z?cmap=cm.coolwarm)??#?cmap指color?map
#?自定義z軸
ax.set_zlim(-10?255)
ax.zaxis.set_major_locator(LinearLocator(10))??#?z軸網格線的疏密,刻度的疏密,20表示刻度的個數
ax.zaxis.set_major_formatter(FormatStrFormatter(‘%.02f‘))??#?將z的value字符串轉為float,保留2位小數
#?設置坐標軸的label和標題
ax.set_xlabel(‘x‘?size=15)
ax.set_ylabel(‘y‘?size=15)
ax.set_zlabel(‘z‘?size=15)
ax.set_title(“Surface?plot“?weight=‘bold‘?size=20)
#?添加右側的色卡條
fig.colorbar(surf?shrink=0.6?aspect=8)??#?shrink表示整體收縮比例,aspect僅對bar的寬度有影響,aspect值越大,bar越窄
plt.show()
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????文件???????7909??2018-07-02?13:13??plot3D\pic\12.jpg
?????文件??????49319??2018-07-02?14:05??plot3D\pic\hi.jpg
?????文件??????44877??2018-07-02?14:06??plot3D\pic\ko.jpg
?????文件??????13297??2018-07-02?11:22??plot3D\pic\redcore.jpg
?????文件??????23232??2018-07-02?14:00??plot3D\pic\tina.jpg
?????文件??????97634??2018-07-02?11:42??plot3D\pic\tree.jpg
?????文件???????1318??2018-07-05?16:05??plot3D\plot3D.py
?????目錄??????????0??2018-07-02?14:36??plot3D\pic
?????目錄??????????0??2018-07-06?10:56??plot3D
-----------?---------??----------?-----??----
???????????????237586????????????????????9
評論
共有 條評論