灰度图像中的斑点检测(略图)

2024-05-16 21:52:29 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用了scikit教程(http://scikit-image.org/docs/dev/auto_examples/plot_blob.html)来处理blob检测。我把代码改成了高斯差

from matplotlib import pyplot as plt
from skimage import data
from skimage.feature import blob_dog
from skimage.color import rgb2gray

image = data.imread('Img.png')

blobs_dog = blob_dog(image, max_sigma=30, threshold=.1)

blobs = [blobs_dog]
colors = ['red']
titles = ['Difference of Gaussian']
sequence = zip(blobs, colors, titles)

for blobs, color, title in sequence:
    fig, ax = plt.subplots(1, 1)
    ax.set_title(title)
    ax.imshow(image, interpolation='nearest')
    for blob in blobs:
        y, x, r = blob
        c = plt.Circle((x, y), r, color=color, linewidth=1, fill=False)
        ax.add_patch(c)

plt.show()

现在我的问题是:我使用了一个灰度图像(我没有用rgb2gray函数修改它),但是当我运行代码时,作为输出,我有一个“彩色”的图像(几乎所有的青色都带有一些红色和黄色的斑点)。 如果我使用RGB图像,然后将其转换为灰度,我不会有问题。为什么会这样?在


Tags: 代码from图像imageimportdatatitleplt