如何在Python中检测黑屏中的死像素?
是否有人有一个简洁的解决方案来检测下图中的两个死像素?我试图通过查找所有像素来查找白色像素,以查看哪一个像素在所有3个通道上的总和为255+255+255。但是这个解决方案非常耗时,附加的图像几乎需要20秒。有什么想法吗? 谢谢 这是我目前的代码:如何在Python中检测黑屏中的死像素?,python,opencv,image-processing,cv2,Python,Opencv,Image Processing,Cv2,是否有人有一个简洁的解决方案来检测下图中的两个死像素?我试图通过查找所有像素来查找白色像素,以查看哪一个像素在所有3个通道上的总和为255+255+255。但是这个解决方案非常耗时,附加的图像几乎需要20秒。有什么想法吗? 谢谢 这是我目前的代码: import cv2 from matplotlib import pyplot as plt import numpy as np imageName = "4cf2cafa5db54bfebbb67e9d99a65e5a_Black200_SN
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
是一个选项):
结果:
[[20 20 0]
[20 20 1]
[20 20 2]
[30 10 0]
[30 10 1]
[30 10 2]]
您使用了什么代码?@SimonCrane更新了问题中的代码。我想您正在查找
np.argwhere
[[20 20 0]
[20 20 1]
[20 20 2]
[30 10 0]
[30 10 1]
[30 10 2]]