網站首頁 編程語言 正文
引言
對圖像進行形態學變換。變換對象一般為灰度圖或二值圖,功能函數放在morphology子模塊內。
1、膨脹(dilation)
原理:一般對二值圖像進行操作。找到像素值為1的點,將它的鄰近像素點都設置成這個值。1值表示白,0值表示黑,因此膨脹操作可以擴大白色值范圍,壓縮黑色值范圍。一般用來擴充邊緣或填充小的孔洞。
功能函數:skimage.morphology.dilation(image,?selem=None)
selem表示結構元素,用于設定局部區域的形狀和大小。
from skimage import data
import skimage.morphology as sm
import matplotlib.pyplot as plt
img=data.checkerboard()
dst1=sm.dilation(img,sm.square(5)) #用邊長為5的正方形濾波器進行膨脹濾波
dst2=sm.dilation(img,sm.square(15)) #用邊長為15的正方形濾波器進行膨脹濾波
plt.figure('morphology',figsize=(8,8))
plt.subplot(131)
plt.title('origin image')
plt.imshow(img,plt.cm.gray)
plt.subplot(132)
plt.title('morphological image')
plt.imshow(dst1,plt.cm.gray)
plt.subplot(133)
plt.title('morphological image')
plt.imshow(dst2,plt.cm.gray)
分別用邊長為5或15的正方形濾波器對棋盤圖片進行膨脹操作,結果如下:
可見濾波器的大小,對操作結果的影響非常大。一般設置為奇數。
除了正方形的濾波器外,濾波器的形狀還有一些,現列舉如下:
morphology.square: 正方形
morphology.disk: ?平面圓形
morphology.ball: 球形
morphology.cube: 立方體形
morphology.diamond: 鉆石形
morphology.rectangle: 矩形
morphology.star: 星形
morphology.octagon: 八角形
morphology.octahedron: 八面體
注意,如果處理圖像為二值圖像(只有0和1兩個值),則可以調用:
skimage.morphology.binary_dilation(image,?selem=None)
用此函數比處理灰度圖像要快。
2、腐蝕(erosion)
函數:skimage.morphology.erosion(image,?selem=None)
selem表示結構元素,用于設定局部區域的形狀和大小。
和膨脹相反的操作,將0值擴充到鄰近像素。擴大黑色部分,減小白色部分。可用來提取骨干信息,去掉毛刺,去掉孤立的像素。
from skimage import data
import skimage.morphology as sm
import matplotlib.pyplot as plt
img=data.checkerboard()
dst1=sm.erosion(img,sm.square(5)) #用邊長為5的正方形濾波器進行膨脹濾波
dst2=sm.erosion(img,sm.square(25)) #用邊長為25的正方形濾波器進行膨脹濾波
plt.figure('morphology',figsize=(8,8))
plt.subplot(131)
plt.title('origin image')
plt.imshow(img,plt.cm.gray)
plt.subplot(132)
plt.title('morphological image')
plt.imshow(dst1,plt.cm.gray)
plt.subplot(133)
plt.title('morphological image')
plt.imshow(dst2,plt.cm.gray)
注意,如果處理圖像為二值圖像(只有0和1兩個值),則可以調用:
skimage.morphology.binary_erosion(image,?selem=None)
用此函數比處理灰度圖像要快。
3、開運算(opening)
函數:skimage.morphology.openning(image,?selem=None)
selem表示結構元素,用于設定局部區域的形狀和大小。
先腐蝕再膨脹,可以消除小物體或小斑塊。
from skimage import io,color
import skimage.morphology as sm
import matplotlib.pyplot as plt
img=color.rgb2gray(io.imread('d:/pic/mor.png'))
dst=sm.opening(img,sm.disk(9)) #用邊長為9的圓形濾波器進行膨脹濾波
plt.figure('morphology',figsize=(8,8))
plt.subplot(121)
plt.title('origin image')
plt.imshow(img,plt.cm.gray)
plt.axis('off')
plt.subplot(122)
plt.title('morphological image')
plt.imshow(dst,plt.cm.gray)
plt.axis('off')
注意,如果處理圖像為二值圖像(只有0和1兩個值),則可以調用:
skimage.morphology.binary_opening(image,?selem=None)
用此函數比處理灰度圖像要快。
4、閉運算(closing)
函數:skimage.morphology.closing(image,?selem=None)
selem表示結構元素,用于設定局部區域的形狀和大小。
先膨脹再腐蝕,可用來填充孔洞。
from skimage import io,color
import skimage.morphology as sm
import matplotlib.pyplot as plt
img=color.rgb2gray(io.imread('d:/pic/mor.png'))
dst=sm.closing(img,sm.disk(9)) #用邊長為5的圓形濾波器進行膨脹濾波
plt.figure('morphology',figsize=(8,8))
plt.subplot(121)
plt.title('origin image')
plt.imshow(img,plt.cm.gray)
plt.axis('off')
plt.subplot(122)
plt.title('morphological image')
plt.imshow(dst,plt.cm.gray)
plt.axis('off')
注意,如果處理圖像為二值圖像(只有0和1兩個值),則可以調用:
skimage.morphology.binary_closing(image,?selem=None)
用此函數比處理灰度圖像要快。
5、白帽(white-tophat)
函數:skimage.morphology.white_tophat(image,?selem=None)
selem表示結構元素,用于設定局部區域的形狀和大小。
將原圖像減去它的開運算值,返回比結構化元素小的白點
from skimage import io,color
import skimage.morphology as sm
import matplotlib.pyplot as plt
img=color.rgb2gray(io.imread('d:/pic/mor.png'))
dst=sm.white_tophat(img,sm.square(21))
plt.figure('morphology',figsize=(8,8))
plt.subplot(121)
plt.title('origin image')
plt.imshow(img,plt.cm.gray)
plt.axis('off')
plt.subplot(122)
plt.title('morphological image')
plt.imshow(dst,plt.cm.gray)
plt.axis('off')
6、黑帽(black-tophat)
函數:skimage.morphology.black_tophat(image,?selem=None)
selem表示結構元素,用于設定局部區域的形狀和大小。
將原圖像減去它的閉運算值,返回比結構化元素小的黑點,且將這些黑點反色。
from skimage import io,color
import skimage.morphology as sm
import matplotlib.pyplot as plt
img=color.rgb2gray(io.imread('d:/pic/mor.png'))
dst=sm.black_tophat(img,sm.square(21))
plt.figure('morphology',figsize=(8,8))
plt.subplot(121)
plt.title('origin image')
plt.imshow(img,plt.cm.gray)
plt.axis('off')
plt.subplot(122)
plt.title('morphological image')
plt.imshow(dst,plt.cm.gray)
plt.axis('off')
原文鏈接:https://www.cnblogs.com/denny402/p/5132677.html
相關推薦
- 2022-03-17 C#實現多文件打包壓縮(.Net?Core)_C#教程
- 2022-04-15 玩數據必備Python庫之numpy使用詳解_python
- 2022-05-18 Python學習之異常中的finally使用詳解_python
- 2022-07-21 StreamX 部署 Flink Stream 應用
- 2022-11-06 關于useEffect的第二個參數解讀_React
- 2022-04-03 深入了解Python如何操作MongoDB_python
- 2022-02-24 開機時自動運行批處理
- 2022-06-02 Apache?Hudi基于華米科技應用湖倉一體化改造_服務器其它
- 最近更新
-
- window11 系統安裝 yarn
- 超詳細win安裝深度學習環境2025年最新版(
- Linux 中運行的top命令 怎么退出?
- MySQL 中decimal 的用法? 存儲小
- get 、set 、toString 方法的使
- @Resource和 @Autowired注解
- Java基礎操作-- 運算符,流程控制 Flo
- 1. Int 和Integer 的區別,Jav
- spring @retryable不生效的一種
- Spring Security之認證信息的處理
- Spring Security之認證過濾器
- Spring Security概述快速入門
- Spring Security之配置體系
- 【SpringBoot】SpringCache
- Spring Security之基于方法配置權
- redisson分布式鎖中waittime的設
- maven:解決release錯誤:Artif
- restTemplate使用總結
- Spring Security之安全異常處理
- MybatisPlus優雅實現加密?
- Spring ioc容器與Bean的生命周期。
- 【探索SpringCloud】服務發現-Nac
- Spring Security之基于HttpR
- Redis 底層數據結構-簡單動態字符串(SD
- arthas操作spring被代理目標對象命令
- Spring中的單例模式應用詳解
- 聊聊消息隊列,發送消息的4種方式
- bootspring第三方資源配置管理
- GIT同步修改后的遠程分支