📜  Mahotas – 使用高斯差分的二值图像边缘

📅  最后修改于: 2022-05-13 01:54:45.736000             🧑  作者: Mango

Mahotas – 使用高斯差分的二值图像边缘

在本文中,我们将了解如何借助 DoG 算法在 mahotas 中对二值图像进行边缘处理。在成像科学中,高斯差分 (DoG) 是一种特征增强算法,它涉及从原始图像的另一个模糊版本中减去一个模糊版本。

下面是实现

# importing required libraries
import mahotas as mh
import numpy as np
from pylab import imshow, show
    
# creating region
# numpy.ndarray
regions = np.zeros((10, 10), bool)
    
# setting 1 value to the region
regions[:3, :3] = 1
regions[6:, 6:] = 1
    
# getting labeled function
labeled, nr_objects = mh.label(regions)
    
# showing the image with interpolation = 'nearest'
print("Binary Image")
imshow(labeled, interpolation ='nearest')
show()
   
# getting edges using dog algo
dog = mahotas.dog(labeled)
   
# showing image
print("Edges using DoG algo")
imshow(dog)
show()

输出 :

Binary Image

Edges using DoG algo

另一个例子

# importing required libraries
import mahotas as mh
import numpy as np
from pylab import imshow, show
    
# creating region
# numpy.ndarray
regions = np.zeros((10, 10), bool)
    
# setting 1 value to the region
regions[1, :2] = 1
regions[5:8, 6: 8] = 1
regions[8, 0] = 1
    
# getting labeled function
labeled, nr_objects = mh.label(regions)
    
# showing the image with interpolation = 'nearest'
print("Image")
imshow(labeled, interpolation ='nearest')
show()
   
# getting edges
dog = mahotas.dog(labeled)
   
# showing image
print("Edges using DoG algo")
imshow(dog)
show()

输出 :

Binary Image

Edges using DoG algo