在數學形態學中,集合B對集合A的Closing是先dilation再用erosion。
: A\bullet B = (A\oplus B)\ominus B, \,
\oplus和\ominus分别表示dilation和erosion。
在影像處理中,closing和opening是用來對影像除噪,這邊通常A就是我們輸入的影像,B則是kernel。
特性
- Idempotent,即(A\bullet B)\bullet B=A\bullet B .
- Increasing,如果A\subseteq C , 然後A\bullet B \subseteq C\bullet B .
- Extensive,即A\subseteq A\bullet B .
- Translation invariant.
實作
這邊對binary image做closing的操作,kernel為5*5大小,4個角落被去掉。
closing不一定要先dilation一次再用erosion一次,也可以使用closing = dilation k times + erosion k times。
當想要closing的洞比較大時,可以使用更高的k次。
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 0 and j2 > 0 and i2
參考
- Image Analysis and Mathematical Morphology by Jean Serra, (1982)
- Image Analysis and Mathematical Morphology, Volume 2: Theoretical Advances by Jean Serra, (1988)
- An Introduction to Morphological Image Processing by Edward R. Dougherty, (1992)
评论 (0)