Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjustment to depth_map.py file. #4

Open
Jiahao-Ma opened this issue Dec 2, 2021 · 1 comment
Open

Adjustment to depth_map.py file. #4

Jiahao-Ma opened this issue Dec 2, 2021 · 1 comment

Comments

@Jiahao-Ma
Copy link

Jiahao-Ma commented Dec 2, 2021

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

`

@charlielito
Copy link

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

`

did you see any big difference using this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants