简体   繁体   English

如何在 Python 中检测黑屏中的坏点?

[英]How to detect dead pixel in black screen in Python?

Does anyone have a neat solution to detect the two dead pixels in the following image?有没有人有一个巧妙的解决方案来检测下图中的两个坏点? I tried looking for a white pixel by looking up all pixels to see which one has a sum of 255+255+255 on all 3 channels.我尝试通过查找所有像素来查找白色像素,以查看哪个像素在所有 3 个通道上的总和为 255+255+255。 But this solution is very time consuming, it almost took 20 seconds for the attached image.但是这个解决方案非常耗时,附加图像几乎需要 20 秒。 Any ideas?有任何想法吗? Thanks谢谢

Here is my current code:这是我当前的代码:

import cv2
from matplotlib import pyplot as plt
import numpy as np

imageName = "4cf2cafa5db54bfebbb67e9d99a65e5a_Black200_SN1000.png"

img = cv2.imread(imageName)


# calculate the sum of max RGB channels in each column of the image
sumMax = np.array([],dtype=np.int32)
for i in range(0,img.shape[1]):
    maxPixel = 0
    for m in range(0,img.shape[0]):
        totalPixel = 
np.int32(img[m,i,0])+np.int32(img[m,i,1])+np.int32(img[m,i,2])
        if totalPixel > maxPixel:
            maxPixel = totalPixel
    sumMax = np.append (sumMax,maxPixel)

plt.plot(sumMax)
plt.show()

在此处输入图像描述

Using numpy.argwhere (or numpy.where is an option):使用numpy.argwhere (或numpy.where是一个选项):

import numpy as np

img = np.zeros([50, 50, 3], dtype=np.uint8)

# white pixels
img[[20, 30], [20, 10], :] = 255
index = np.argwhere(img[..., :] == 255)

print(index)

result:结果:

[[20 20  0]
[20 20  1]
[20 20  2]
[30 10  0]
[30 10  1]
[30 10  2]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM