2017-10-26 11 views
0

좌표 및 불일치 배열에서 불량 픽셀 위치를 제거하고 싶습니다. 그러므로 나는 약간의 코드를 썼다. 그러나 약간의 시간이 걸렸고 약간의 시간이 걸렸다. 이 코드의 주요 아이디어는 불일치 값 -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] 

답변

0

유효한 마스크 !=-17을 생성하십시오. 이 마스크를 사용하여 X-Y 좌표가 될 유효한 행 col 인덱스를 가져옵니다. 마지막으로 마스크 또는 행을 사용하여 입력 배열에 색인화하고 필터링 된 데이터 배열에 대한 열 인덱스를 지정합니다. 따라서, 당신은 그 평평한 사업을 모두 할 필요가 없습니다.

따라서, 구현 될 것이다 -

mask = disp != -17 
yCoords, xCoords = np.where(mask) # or np.nonzero(mask) 
dispPoints = disp[yCoords, xCoords] # or disp[mask]