日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Python數(shù)學形態(tài)學實例分析

系統(tǒng) 1908 0

本文實例講述了Python數(shù)學形態(tài)學。分享給大家供大家參考,具體如下:

一 原始隨機圖像

1、代碼

            
import numpy as np
import matplotlib.pyplot as plt
square = np.zeros((32,32))#全0數(shù)組
square[10:20,10:20]=1#把其中一部分設置為1
x, y =(32*np.random.random((2,15))).astype(np.int)#隨機位置
square[x,y]=1#把隨機位置設置為1
plt.imshow(square)#原始隨機圖像
plt.show()


          

2、運行結果

Python數(shù)學形態(tài)學實例分析_第1張圖片

二 開運算

1、代碼

            
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
square = np.zeros((32,32))#全0數(shù)組
square[10:20,10:20]=1#把其中一部分設置為1
x, y =(32*np.random.random((2,15))).astype(np.int)#隨機位置
square[x,y]=1#把隨機位置設置為1
open_square = ndimage.binary_opening(square)#開運算
plt.imshow(open_square)
plt.show()


          

2、運行結果

Python數(shù)學形態(tài)學實例分析_第2張圖片

三 膨脹運算

1、代碼

            
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
square = np.zeros((32,32))#全0數(shù)組
square[10:20,10:20]=1#把其中一部分設置為1
x, y =(32*np.random.random((2,15))).astype(np.int)#隨機位置
square[x,y]=1#把隨機位置設置為1
eroded_square = ndimage.binary_erosion(square)#膨脹運算
plt.imshow(eroded_square)
plt.show()


          

2、運行結果

Python數(shù)學形態(tài)學實例分析_第3張圖片

四 閉運算

1、代碼

            
import numpy as np
import matplotlib.pyplot as plt
from scipy import ndimage
square = np.zeros((32,32))#全0數(shù)組
square[10:20,10:20]=1#把其中一部分設置為1
x, y =(32*np.random.random((2,15))).astype(np.int)#隨機位置
square[x,y]=1#把隨機位置設置為1
closed_square = ndimage.binary_closing(square)#閉運算
plt.imshow(closed_square)
plt.show()


          

2、運行結果

Python數(shù)學形態(tài)學實例分析_第4張圖片

更多關于Python相關內容感興趣的讀者可查看本站專題:《Python數(shù)學運算技巧總結》、《Python數(shù)據(jù)結構與算法教程》、《Python函數(shù)使用技巧總結》、《Python字符串操作技巧匯總》及《Python入門與進階經典教程》

希望本文所述對大家Python程序設計有所幫助。


更多文章、技術交流、商務合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 白山市| 丰顺县| 太原市| 宜城市| 乌苏市| 鄂托克旗| 准格尔旗| 澎湖县| 怀宁县| 固镇县| 疏附县| 曲麻莱县| 桑植县| 南靖县| 忻州市| 朔州市| 阆中市| 涞水县| 简阳市| 鄂托克前旗| 寻乌县| 佛教| 陆丰市| 达孜县| 广宗县| 岳西县| 山东省| 宜宾县| 兴山县| 龙山县| 璧山县| 昂仁县| 上栗县| 西乌| 台北县| 察雅县| 渑池县| 荣成市| 吴桥县| 江口县| 平阳县|