深度圖預處理方法之線性插值
阿新 • • 發佈:2018-12-11
參考文獻:Deep_Head_Pose_Estimation_from_Depth_Data for In-car Automotive Applications
演算法步驟
Algorithm 1 Linear Interpolation Algorithm
procedure
- w : image width
- for row in image rows do
- x_min = first foreground pixel in row
- x_max = last foreground pixel in row
- for x=0 to w-1 do
- x_src = x/(w-1)*(x_max-x_min)
- x_1 = floor(x_src)
- x_2 = x_1+1
- if x_2<=w then
- lambda = x_2 - x_src
- row_out[x]=row[x_1]lambda+row[x_2]*(1-lambda)
- else
- row_out[x]=row[x_1]
- x_src = x/(w-1)*(x_max-x_min)
- for x=0 to w-1 do
程式碼實現如下:
def scale_interpolation(filename): image = cv2.imread(filename,-1) height,width = image.shape[0],image.shape[1] #水平分割影象 rows = np.vsplit(image,height) img_res = [] for row in rows: row = np.squeeze(row) # get the foreground piexls index(nonzeros index) index = np.argwhere(row) #如果該行深度值全為零,則該行不處理 if index.size ==0: row_result=np.zeros_like(row) else: x_min = np.min(index) x_max = np.max(index) row_result=np.zeros_like(row) for col in range(width): x_src = col/(width-1)*(x_max-x_min) x_1 = int(np.floor(x_src)) x_2 = x_1 + 1 if x_2 < width: alpha = x_2 - x_src row_result[col] = row[x_1]*alpha+row[x_2]*(1-alpha) else: row_result[col] = row[x_1] img_res.append(row_result) img_res= np.vstack(img_res) return img_res