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

How to detect dead pixel in black screen in Python?

有没有人有一个巧妙的解决方案来检测下图中的两个坏点?我尝试通过查找所有像素来寻找白色像素,以查看哪个像素在所有 3 个通道上的总和为 255+255+255。但是这个解决方案非常耗时,附上的图片几乎用了 20 秒。有任何想法吗? 谢谢

这是我当前的代码:

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()

使用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)

结果:

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