斑点检测

斑点在图像中的暗区域是亮的,或者是亮区域的暗。在本例中,使用3种算法检测斑点。本例中使用的图像是哈勃极深场。图像中的每个亮点都是恒星或星系。

高斯拉普拉斯(对数)

这是最准确、最慢的方法。它计算标准差依次递增的高斯图像的拉普拉斯,并将其堆叠在一个立方体中。斑点是此多维数据集中的局部最大值。由于卷积过程中的核大小较大,因此检测较大的斑点特别慢。仅检测到暗背景上的明亮斑点。看见 skimage.feature.blob_log() 以供使用。

高斯差(DOG)

这是LOG方法的一个更快的近似值。在这种情况下,图像随着标准差的增加而变得模糊,并且两个连续模糊的图像之间的差被堆叠在一个立方体中。对于检测较大的斑点,该方法具有与LOG方法相同的缺点。人们又一次认为水滴在黑暗中是明亮的。看见 skimage.feature.blob_dog() 以供使用。

黑森行列式(DoH)

这是最快的方法。它通过在图像的黑森行列式的矩阵中找到极大值来检测斑点。检测速度与斑点的大小无关,因为在内部实现使用盒过滤器而不是卷积。检测到黑暗中的明亮以及明亮斑点上的黑暗。缺点是无法准确检测到小斑点(<3px)。看见 skimage.feature.blob_doh() 以供使用。

Laplacian of Gaussian, Difference of Gaussian, Determinant of Hessian
from math import sqrt
from skimage import data
from skimage.feature import blob_dog, blob_log, blob_doh
from skimage.color import rgb2gray

import matplotlib.pyplot as plt


image = data.hubble_deep_field()[0:500, 0:500]
image_gray = rgb2gray(image)

blobs_log = blob_log(image_gray, max_sigma=30, num_sigma=10, threshold=.1)

# Compute radii in the 3rd column.
blobs_log[:, 2] = blobs_log[:, 2] * sqrt(2)

blobs_dog = blob_dog(image_gray, max_sigma=30, threshold=.1)
blobs_dog[:, 2] = blobs_dog[:, 2] * sqrt(2)

blobs_doh = blob_doh(image_gray, max_sigma=30, threshold=.01)

blobs_list = [blobs_log, blobs_dog, blobs_doh]
colors = ['yellow', 'lime', 'red']
titles = ['Laplacian of Gaussian', 'Difference of Gaussian',
          'Determinant of Hessian']
sequence = zip(blobs_list, colors, titles)

fig, axes = plt.subplots(1, 3, figsize=(9, 3), sharex=True, sharey=True)
ax = axes.ravel()

for idx, (blobs, color, title) in enumerate(sequence):
    ax[idx].set_title(title)
    ax[idx].imshow(image)
    for blob in blobs:
        y, x, r = blob
        c = plt.Circle((x, y), r, color=color, linewidth=2, fill=False)
        ax[idx].add_patch(c)
    ax[idx].set_axis_off()

plt.tight_layout()
plt.show()

脚本的总运行时间: (0分2.090秒)

Gallery generated by Sphinx-Gallery