深度图预处理方法之线性插值

版权声明:未经本人许可,不得用于商业用途及传统媒体。转载请注明出处! https://blog.csdn.net/qikaihuting/article/details/82805798

参考文献: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]

代码实现如下:

    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

可视化效果

在这里插入图片描述
鉴于关于深度数据处理方法的文献较少,欢迎大家分享和讨论,谢谢!

猜你喜欢

转载自blog.csdn.net/qikaihuting/article/details/82805798