python

您所在的位置:网站首页 bootstrapvue教程 python

python

2022-12-17 14:57| 来源: 网络整理| 查看: 265

基本上,我有一个图像,我需要找到红色像素,并输出一个红色像素的图像,但在黑色背景上是白色的。我必须使用maplotlib,所以我首先使用plt.imread读取我的图像,并将其转换为一个numpy数组。主要问题是我不知道如何访问数组的第三维,RGB值本身所在的位置,并将它们赋给一个变量。我的形象是这样的:image我的输出应该是:output image到目前为止,我已经编写了这个代码,但是我不知道我做错了什么。上限和下限阈值应该检测像素,所以如果“red”高于上限阈值,红色像素将被检测到。我的嵌套for循环应该获取rgb_image的宽度和长度,并从中找到像素,但我很确定我没有正确使用它们。任何帮助将不胜感激!

import numpy as np import matplotlib.pyplot as plt def find_red_pixels(map_filename,upper_threshold=100,lower_threshold=50): rgb_image = plt.imread(map_filename) for x in range(0,rgb_image[1]): for y in range(0,rgb_image[0]): rgb_image = rgb_image * 255 red = rgb_image[...,0] green = rgb_image[...,1] = 0 blue = rgb_image[...,2] = 0 if (red > upper_threshold).any() and (green < lower_threshold).any() and (blue < lower_threshold).any(): plt.imshow(red) plt.show() print(find_red_pixels('./data/map.png'))


【本文地址】


今日新闻


推荐新闻


    CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3