查看“︁闭运算”︁的源代码
←
闭运算
跳转到导航
跳转到搜索
因为以下原因,您没有权限编辑该页面:
您请求的操作仅限属于该用户组的用户执行:
用户
您可以查看和复制此页面的源代码。
[[File:Closing.png|right|thumb|如果選擇灰色圓盤當 B(kernel),對兩個深藍色的正方形做closing,會多出淺藍色的部分.]] 在數學形態學中,集合B對集合''A''的Closing是先dilation再用erosion。 : <math>A\bullet B = (A\oplus B)\ominus B, \, </math> <math>\oplus</math>和<math>\ominus</math>分别表示dilation和erosion。 在影像處理中,closing和[[开运算 (形态学)|opening]]是用來對影像除噪,這邊通常A就是我們輸入的影像,B則是kernel。 == 特性 == * Idempotent,即<math>(A\bullet B)\bullet B=A\bullet B</math> . * Increasing,如果<math>A\subseteq C</math> , 然後<math>A\bullet B \subseteq C\bullet B</math> . * Extensive,即<math>A\subseteq A\bullet B</math> . * Translation invariant. == 實作 == 這邊對binary image做closing的操作,kernel為5*5大小,4個角落被去掉。 closing不一定要先dilation一次再用erosion一次,也可以使用closing = dilation k times + erosion k times。 當想要closing的洞比較大時,可以使用更高的k次。<syntaxhighlight lang="python3"> def dilation(img): img1 = np.zeros((img.shape[0], img.shape[1]), dtype="int") for i in range(img.shape[0]): for j in range(img.shape[1]): if img[i][j]>0: row = i-2; col = j-2; # The octogonal 4-5-5-5-4 kernel for w in range(5): for h in range(5): if ( w==0 and h==0 ) or ( w==0 and h==4 ) or ( w==4 and h==0 ) or ( w==4 and h==4 ): continue else: i2 = row + w; j2 = col + h; if i2 >= 0 and j2 >= 0 and i2 < img.shape[0] and j2 < img.shape[1]: img1[i2][j2] = 255 return img1 def erosion(img): img1 = np.zeros((img.shape[0], img.shape[1]), dtype="int") for i in range(img.shape[0]): for j in range(img.shape[1]): flag = 0 row = i-2; col = j-2; # The octogonal 4-5-5-5-4 kernel for w in range(5): for h in range(5): if ( w==0 and h==0 ) or ( w==0 and h==4 ) or ( w==4 and h==0 ) or ( w==4 and h==4 ): continue else: i2 = row + w; j2 = col + h; if i2 > 0 and j2 > 0 and i2 < img.shape[0] and j2 < img.shape[1]: if img[i2][j2] == 0: flag = 1 if flag == 0: img1[i][j] = 255 return img1 def closing(img): return erosion(dilation(img)) </syntaxhighlight> == 參考 == * ''Image Analysis and Mathematical Morphology'' by Jean Serra, {{ISBN|0-12-637240-3}} (1982) * ''Image Analysis and Mathematical Morphology, Volume 2: Theoretical Advances'' by Jean Serra, {{ISBN|0-12-637241-1}} (1988) * ''An Introduction to Morphological Image Processing'' by Edward R. Dougherty, {{ISBN|0-8194-0845-X}} (1992) [[Category:數位幾何學]] [[Category:数学形态学]]
该页面使用的模板:
Template:ISBN
(
查看源代码
)
返回
闭运算
。
导航菜单
个人工具
登录
命名空间
页面
讨论
不转换
查看
阅读
查看源代码
查看历史
更多
搜索
导航
首页
最近更改
随机页面
MediaWiki帮助
特殊页面
工具
链入页面
相关更改
页面信息