首页 > 解决方案 > 问题:如何在图片中找到边缘,使用 numpy 函数

问题描述

我想在图片中找到“边缘”。为了澄清术语边缘,边缘是颜色变化超过某个阈值的任何像素。

为了解决这个问题,我收到了一些指导方针:

我很长时间没有使用 python,所以这对我来说是一项艰巨的工作。任何人都可以帮忙吗?我在想:首先制作一个计算 2 个像素之间距离的函数。像这样:def what_is_distance_between_pixels(image, pixel1, pixel2)

然后创建一个对所有像素执行上述功能的函数。但我不确定这是否可行。像这样的东西(草图):

def distance_between_all_pixels(image, threshold):
    height = image.shape[0] 
    width = image.shape[1]
    colour = image.shape[2]
    for y in range(0,height):
        for x in range(0,width):
            for z in range(0,colour):
                distance = what_is_distance_between_pixels(image, image[y,x,z], image[y+1,x,z])
                if distance > threshold:
                    image[x,y,z] = 0
                distance_2 = what_is_distance_between_pixels(image, image[y,x,z], image[y,x+1,z])
                if distance_2 > threshold:
                    image[x,y,z] = 0

有谁知道如何解决这个问题?我希望我能很好地解释我的问题。

标签: imagenumpypython-3.7

解决方案


推荐阅读