Skip to content

Adjustment to depth_map.py file. #4

@Jiahao-Ma

Description

@Jiahao-Ma

The essence of creating dense depth map is to calculate weighted depth information according to the distance of neighborhood. The original repo is based on inverse distance weighted. When it comes to the distance calculation, I have mads some adjustments, replacing the np.round() with np.int32(). Also, in the double loop statements, I have deleted - grid - 1.
`

  def dense_map(Pts, n, m, grid):
      ng = 2 * grid + 1
      mX = np.zeros((m,n)) + np.float("inf")
      mY = np.zeros((m,n)) + np.float("inf")
      mD = np.zeros((m,n))
      mX[np.int32(Pts[1]),np.int32(Pts[0])] = Pts[0] - np.int32(Pts[0])#np.round(Pts[0])  # NOTICE
      mY[np.int32(Pts[1]),np.int32(Pts[0])] = Pts[1] - np.int32(Pts[1])#np.round(Pts[1])  # NOTICE
      mD[np.int32(Pts[1]),np.int32(Pts[0])] = Pts[2]
      
      KmX = np.zeros((ng, ng, m - ng, n - ng))
      KmY = np.zeros((ng, ng, m - ng, n - ng))
      KmD = np.zeros((ng, ng, m - ng, n - ng))
      
      for i in range(ng):
          for j in range(ng):
              KmX[i,j] = mX[i : (m - ng + i), j : (n - ng + j)] + i #- grid - 1  # NOTICE
              KmY[i,j] = mY[i : (m - ng + i), j : (n - ng + j)] + j #- grid - 1  # NOTICE
              KmD[i,j] = mD[i : (m - ng + i), j : (n - ng + j)]
      S = np.zeros_like(KmD[0,0])
      Y = np.zeros_like(KmD[0,0])

      # Inverse distance weighted
      for i in range(ng):
          for j in range(ng):
              s = 1/np.sqrt(KmX[i,j] * KmX[i,j] + KmY[i,j] * KmY[i,j])
              Y = Y + s * KmD[i,j]
              S = S + s
      
      S[S == 0] = 1
      out = np.zeros((m,n))
      out[grid + 1 : -grid, grid + 1 : -grid] = Y/S
      return out

`

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions