좌표 및 불일치 배열에서 불량 픽셀 위치를 제거하고 싶습니다. 그러므로 나는 약간의 코드를 썼다. 그러나 약간의 시간이 걸렸고 약간의 시간이 걸렸다. 이 코드의 주요 아이디어는 불일치 값 -17이 포함 된 모든 배열 항목을 제거하고자하는 것입니다. 내 2000x2000 이미지의 픽셀 좌표 배열에서도 마찬가지입니다. 다음은 마스크와 병합 배열을 사용하는 코드입니다. (결국 x, y 및 잘못된 픽셀의 항목과 좌표를 포함하지 않는 동일한 순서로 정렬 된 불일치 값을 포함하는 3 개의 배열을 원합니다.) 이 코드를 개선하는 데 도움이되는 정보를 주셔서 감사합니다!잘못된 픽셀 위치를 추출하기위한 np.array의 효율적인 마스킹 (Python 2.7)
#define 2000x2000 index arrays
xyIdx = np.mgrid[0:disp.shape[0],0:disp.shape[1]]
xIdx = xyIdx[1]
yIdx = xyIdx[0]
#flatten indice-arrays and the disparity-array
xIdxFlat = xIdx.flatten()
yIdxFlat = yIdx.flatten()
dispFlat = disp.flatten()
#create mask with all values = 1 'true'
mask = np.ones(dispFlat.shape, dtype='bool')
#create false entrys in the mask wherever the minimum disparity or better
#said a bad pixel is located
for x in range(0,len(dispFlat)):
if dispFlat[x] == -17:
mask[x] = False
#mask the arrays and remove the entries that belong to the bad pixels
xCoords = np.zeros((xIdxFlat[mask].size), dtype='float64')
xCoords[:] = xIdxFlat[mask]
yCoords = np.zeros((yIdxFlat[mask].size), dtype='float64')
yCoords[:] = yIdxFlat[mask]
dispPoints = np.zeros((dispFlat[mask].size), dtype='float64')
dispPoints[:] = dispFlat[mask]