image - 问题:如何在图片中找到边缘,使用 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
有谁知道如何解决这个问题?我希望我能很好地解释我的问题。
解决方案
推荐阅读
- date - 如何在 nuxtjs 中设置服务器日期配置
- php - 如何将数据库表数据按两列分组并输出为json?
- mule - 请求不包含“文件”部分或“元数据”部分
- java - Executor Thread Pool - 限制队列大小和最旧的出队
- c++ - 将数据库存储在动态位置并使用我部署的应用程序访问它
- azure-cosmosdb - 同一 Azure Cosmos DB 一次运行其他时间显示消息大小太大
- javascript - 如何在 Chrome 检查器中使用 XPath 子字符串函数?
- c# - 如何将 WPF UserControl 留在 UserControl 中的某处?
- scala - 无法从 Sqoop 创建的 Spark 中的序列文件创建数据帧
- python - 同时在两个 Python 脚本之间导入函数