一、腐蝕與膨脹
1.1 腐蝕操作
import cv2 import numpy as np img = cv2.imread('DataPreprocessing/img/dige.png') cv2.imshow("img", img) cv2.waitKey(0) cv2.destroyAllWindows()
dige.png原圖1展示(註: 沒有原圖的可以截圖下來保存本地。
#腐蝕1輪次之後~ (iterations = 1)
kernel = np.ones((3, 3), np.uint8) erosion = cv2.erode(img, kernel, iterations=1) cv2.imshow('erosion', erosion) cv2.waitKey(0) cv2.destroyAllWindows()
腐蝕結果展示圖2:
腐蝕圓多次的效果,以及腐蝕原理
pie = cv2.imread('DataPreprocessing/img/pie.png') cv2.imshow('pie', pie) cv2.waitKey(0) cv2.destroyAllWindows()
pie.png原圖3:
腐蝕原理, 其中濾波器的大小越大腐蝕的程度越大圖4:
kernel = np.ones((30, 30), np.uint8) erosion_1 = cv2.erode(pie, kernel, iterations=1) erosion_2 = cv2.erode(pie, kernel, iterations=2) erosion_3 = cv2.erode(pie, kernel, iterations=3) res = np.hstack((erosion_1, erosion_2, erosion_3)) cv2.imshow('res', res) cv2.waitKey(0) cv2.destroyAllWindows()
圓腐蝕三次結果展示圖5:
1.2 膨脹操作
kernel = np.ones((3, 3), np.uint8) dige_dilate = erosion dige_dilate = cv2.dilate(erosion, kernel, iterations=1) cv2.imshow('dilate', dige_dilate) cv2.waitKey(0) cv2.destroyAllWindows()
膨脹之前圖2,發現線條變粗,跟原圖對比的線條相差無幾,但是沒了那些長須裝的噪音,圖6:
膨脹圓多次的效果,以及膨脹原理與腐蝕相反,有白點的濾波器則濾波器內資料全變為白色。
pie = cv2.imread('DataPreprocessing/img/pie.png') kernel = np.ones((30, 30), np.uint8) dilate_1 = cv2.dilate(pie, kernel, iterations=1) dilate_2 = cv2.dilate(pie, kernel, iterations=2) dilate_3 = cv2.dilate(pie, kernel, iterations=3) res = np.hstack((dilate_1, dilate_2, dilate_3)) cv2.imshow('res', res) cv2.waitKey(0) cv2.destroyAllWindows()
膨脹圓3次的結果展示,圖7:
# 开:先腐蚀,再膨胀
img = cv2.imread('DataPreprocessing/img/dige.png')
kernel = np.ones((5, 5), np.uint8)
opening = cv2.morphologyEx(img, cv2.MORPH_OPEN, kernel)
cv2.imshow('opening', opening)
cv2.waitKey(0)
cv2.destroyAllWindows()
將原圖1,先腐蝕,再膨脹,得到開運算結果圖8:
# 闭:先膨胀,再腐蚀
img = cv2.imread('DataPreprocessing/img/dige.png')
kernel = np.ones((5, 5), np.uint8)
closing = cv2.morphologyEx(img, cv2.MORPH_CLOSE, kernel)
cv2.imshow('closing', closing)
cv2.waitKey(0)
cv2.destroyAllWindows()
將原圖1,先膨脹,再腐蝕,得到開運算結果圖9:
# 梯度=膨胀-腐蚀 pie = cv2.imread('DataPreprocessing/img/pie.png') kernel = np.ones((7, 7), np.uint8) dilate = cv2.dilate(pie, kernel, iterations=5) erosion = cv2.erode(pie, kernel, iterations=5) res = np.hstack((dilate, erosion)) cv2.imshow('res', res) cv2.waitKey(0) cv2.destroyAllWindows() gradient = cv2.morphologyEx(pie, cv2.MORPH_GRADIENT, kernel) cv2.imshow('gradient', gradient) cv2.waitKey(0) cv2.destroyAllWindows()得到梯度運算結果
圖10:
禮帽= 原始輸入-開運算結果
# 礼帽 img = cv2.imread('DataPreprocessing/img/dige.png') tophat = cv2.morphologyEx(img, cv2.MORPH_TOPHAT, kernel) cv2.imshow('tophat', tophat) cv2.waitKey(0) cv2.destroyAllWindows()得到禮帽結果
圖11:
#4.2 黑帽
# 黑帽 img = cv2.imread('DataPreprocessing/img/dige.png') blackhat = cv2.morphologyEx(img, cv2.MORPH_BLACKHAT, kernel) cv2.imshow('blackhat ', blackhat) cv2.waitKey(0) cv2.destroyAllWindows()###得到禮帽結果###圖12:####### ##########
以上是Python+OpenCV之形態學的操作方法是什麼的詳細內容。更多資訊請關注PHP中文網其他相關文章!

Arraysinpython,尤其是Vianumpy,ArecrucialInsCientificComputingfortheireftheireffertheireffertheirefferthe.1)Heasuedfornumerericalicerationalation,dataAnalysis和Machinelearning.2)Numpy'Simpy'Simpy'simplementIncressionSressirestrionsfasteroperoperoperationspasterationspasterationspasterationspasterationspasterationsthanpythonlists.3)inthanypythonlists.3)andAreseNableAblequick

你可以通過使用pyenv、venv和Anaconda來管理不同的Python版本。 1)使用pyenv管理多個Python版本:安裝pyenv,設置全局和本地版本。 2)使用venv創建虛擬環境以隔離項目依賴。 3)使用Anaconda管理數據科學項目中的Python版本。 4)保留系統Python用於系統級任務。通過這些工具和策略,你可以有效地管理不同版本的Python,確保項目順利運行。

numpyarrayshaveseveraladagesoverandastardandpythonarrays:1)基於基於duetoc的iMplation,2)2)他們的aremoremoremorymorymoremorymoremorymoremorymoremoremory,尤其是WithlargedAtasets和3)效率化,效率化,矢量化函數函數函數函數構成和穩定性構成和穩定性的操作,製造

數組的同質性對性能的影響是雙重的:1)同質性允許編譯器優化內存訪問,提高性能;2)但限制了類型多樣性,可能導致效率低下。總之,選擇合適的數據結構至關重要。

到CraftCraftExecutablePythcripts,lollow TheSebestPractices:1)Addashebangline(#!/usr/usr/bin/envpython3)tomakethescriptexecutable.2)setpermissionswithchmodwithchmod xyour_script.3)

numpyArraysareAreBetterFornumericalialoperations andmulti-demensionaldata,而learthearrayModuleSutableforbasic,內存效率段

numpyArraySareAreBetterForHeAvyNumericalComputing,而lelethearRayModulesiutable-usemoblemory-connerage-inderabledsswithSimpleDatateTypes.1)NumpyArsofferVerverVerverVerverVersAtility andPerformanceForlargedForlargedAtatasetSetsAtsAndAtasEndCompleXoper.2)

ctypesallowscreatingingangandmanipulatingc-stylarraysinpython.1)usectypestoInterfacewithClibrariesForperfermance.2)createc-stylec-stylec-stylarraysfornumericalcomputations.3)passarraystocfunctions foreforfunctionsforeffortions.however.however,However,HoweverofiousofmemoryManageManiverage,Pressiveo,Pressivero


熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

SecLists
SecLists是最終安全測試人員的伙伴。它是一個包含各種類型清單的集合,這些清單在安全評估過程中經常使用,而且都在一個地方。 SecLists透過方便地提供安全測試人員可能需要的所有列表,幫助提高安全測試的效率和生產力。清單類型包括使用者名稱、密碼、URL、模糊測試有效載荷、敏感資料模式、Web shell等等。測試人員只需將此儲存庫拉到新的測試機上,他就可以存取所需的每種類型的清單。

mPDF
mPDF是一個PHP庫,可以從UTF-8編碼的HTML產生PDF檔案。原作者Ian Back編寫mPDF以從他的網站上「即時」輸出PDF文件,並處理不同的語言。與原始腳本如HTML2FPDF相比,它的速度較慢,並且在使用Unicode字體時產生的檔案較大,但支援CSS樣式等,並進行了大量增強。支援幾乎所有語言,包括RTL(阿拉伯語和希伯來語)和CJK(中日韓)。支援嵌套的區塊級元素(如P、DIV),

SublimeText3 Linux新版
SublimeText3 Linux最新版

記事本++7.3.1
好用且免費的程式碼編輯器

DVWA
Damn Vulnerable Web App (DVWA) 是一個PHP/MySQL的Web應用程序,非常容易受到攻擊。它的主要目標是成為安全專業人員在合法環境中測試自己的技能和工具的輔助工具,幫助Web開發人員更好地理解保護網路應用程式的過程,並幫助教師/學生在課堂環境中教授/學習Web應用程式安全性。 DVWA的目標是透過簡單直接的介面練習一些最常見的Web漏洞,難度各不相同。請注意,該軟體中