参考文献: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]
- for x=0 to w-1 do
代码实现如下:
def scale_interpolation(filename):
"""func:to further reduce the impact of the background pixels,
each image row is linearly stretched (see above mentioned Algorithm 1)
keeping only foreground pixels
"""
image = cv2.imread(filename,-1)
height,width = image.shape[0],image.shape[1]
rows = np.vsplit(image,height)
img_res = []
#rows[i].shape------(1,100)
for row in rows:
row = np.squeeze(row)
#index = np.where(np.not_equal(row,0.0))
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)
#print(x_min,x_max)
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
可视化效果
鉴于关于深度数据处理方法的文献较少,欢迎大家分享和讨论,谢谢!