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

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

可视化效果

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值