Mahotas – 使用高斯差分的二值图像边缘
在本文中,我们将了解如何借助 DoG 算法在 mahotas 中对二值图像进行边缘处理。在成像科学中,高斯差分 (DoG) 是一种特征增强算法,它涉及从原始图像的另一个模糊版本中减去一个模糊版本。
In order to do this we will use mahotas.dog
method
Syntax : mahotas.dog(img)
Argument : It takes binary image object as argument
Return : It returns image object
下面是实现
# 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