python - 从Python的图片中获取所需的部分,然后找到该部分中的缺陷像素

标签 python opencv python-imaging-library

我正在做一个项目,在该项目中,我必须根据该屏幕的图像查找该屏幕的缺陷像素。现在,我已经使用opencv并为轮廓应用了蒙版,得到了屏幕区域以及缺陷像素。但是我被困在寻找缺陷像素的位置。为了找到我使用过的有缺陷的像素,红色是主要颜色:

现在,我需要找到未附加在“data_red”中和轮廓内的红色像素的位置。期待解决方案!预先感谢您。
红色= [i代表Image_data中的i]
为我穿红色衣服:
如果我> 175:
data_red.append(i)

The image before applying the mask, after applying the mask, only the red part remains red and others become black

现在,我需要显示不满足条件> 175的红色像素位置。

最佳答案

使用 Numpy

import numpy as np

# get red from somewhere
red_np = np.array(red)
data_red = red_np[red_np > 175]

# and for the ones not appended
not_appended = np.argwhere(data_red <= 175)

这将返回一个numpy数组,其数组data_red中所有元素的值均低于175。

关于python - 从Python的图片中获取所需的部分,然后找到该部分中的缺陷像素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51381661/

相关文章:

c++ - 如何计算 OpenCV 中矩阵的直方图?

python - 获取图像模式 PIL Python

python - 等到加载器消失 python selenium

android - 如何使用 Android Studio 设置 OpenCV v3.4.0

c++ - 如何从 Python 使用 OpenCV 的 C++ 函数?

python - 如何将灰度图像转换为像素值列表?

python - 调整大小时使用 PIL 保留图像的 exif 数据(创建缩略图)

python - 如何打包 python 应用程序以使其可 pip 安装?

python - Caffe 提供的 AlexNet 模型

Python 埃拉托斯特尼筛法不起作用