【问题标题】:How to find zero crossings in the Laplacian of Gaussian of an image如何在图像的高斯拉普拉斯算子中找到零交叉
【发布时间】:2020-05-16 11:27:54
【问题描述】:

我需要只使用我的方法和 matplotlib OpenCV 和 NumPy 构建一个 LoG 文件管理器(但不是为了帮助计算而执行过滤器的内置函数)

def edgeDetectionZeroCrossingLOG(img: np.ndarray) -> (np.ndarray):
    """
    Detecting edges using the "ZeroCrossingLOG" method
    :param I: Input image
    :return: :return: Edge matrix
    """
    kernel = np.ndarray((3, 3))
    b_img = blurImage1(img, kernel)
    k = np.array([[0, 1, 0],
                  [1, -4, 1],
                  [0, 1, 0]])
    img_dervative = conv2D(img, k)
    ***Zero-Crossing***

步骤:

  1. 使用高斯滤波器对图像进行模糊处理
def blurImage1(in_image: np.ndarray, kernel_size: np.ndarray) -> np.ndarray:
    """
    Blur an image using a Gaussian kernel
    :param inImage: Input image
    :param kernelSize: Kernel size
    :return: The Blurred image
    """

    gaussian = np.ndarray(kernel_size)
    sigma = 0.3 * ((kernel_size[0] - 1) * 0.5 - 1) + 0.8
    for x in range(0, kernel_size[0]):
        for y in range(0, kernel_size[1]):
            gaussian[x, y] = math.exp(-((x ** 2 + y ** 2) / (2.0 * sigma ** 2))) / (math.pi * (sigma ** 2) * 2)
    return conv2D(in_image, gaussian)
  1. 使用推导拉普拉斯核 Ix,Iy
    k = np.array([[0, 1, 0],
                  [1, -4, 1],
                  [0, 1, 0]])
  1. 需要在图像的 2D 数组中找到所有“过零”,并将它们标记为 1,其余为 0

我的主要问题是过零,我找不到解决办法。

我需要检查所有没有阈值的交叉口 -> { (-+),(+-),(-0+),(+0-)},并且每个交叉口都设为 1,其余的则为零。

(卷积也是我实现的函数conv2D)

【问题讨论】:

  • 查找所有正像素,对于每个像素,查看它是否具有负值或零值邻居。如果是这样,则两者之间存在过零。
  • 如此嵌套?跑遍整个 img?
  • 是的。至少在第一个实现中。一旦你有这个工作,你可以看看矢量化它的选项,但首先让它工作。

标签: python image-processing computer-vision laplacianofgaussian


【解决方案1】:

在我自己实际实现之后,我偶然发现了这个线程。如果您使用 scikit-image,这相当简单。我先上代码,再过一遍

from skimage.filters import laplace
import numpy as np

lap = np.sign(laplace(image))
lap = np.pad(lap, ((0, 1), (0, 1)))
diff_x = lap[:-1, :-1] - lap[:-1, 1:] < 0
diff_y = lap[:-1, :-1] - lap[1:, :-1] < 0

edges =  np.logical_or(diff_x, diff_y).astype(float)

首先我们找到拉普拉斯算子并取它的符号,因为我们对值不感兴趣,然后继续用零填充最后一列和行,以进行卷积。 然后我们继续沿 x 轴检查是否有来自- =&gt; + 的交叉点。只需将比较更改为相反的更改。连续检查三个状态的想法可以类似地完成,其中比较必须评估为True才能成为1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-02
    • 1970-01-01
    • 2019-05-08
    相关资源
    最近更新 更多