How to resize a depth map from size [400,400] into size [60,60]?

Viewed 1264

I have a depth map image which was obtained using a kinect camera. In that image I have selected a region of size [400,400] and stored it as another image. Now, I would like to know how to resize this image into a size of [x,y] in python.

2 Answers

Same as a normal image

import cv2
import matplotlib.pyplot as plt

image = cv2.imread(path_to_your_image) # Insert your image address here
resized = cv2.resize(image, (x, y),  interpolation = cv2.INTER_NEAREST) 

plt.imshow(resized)
plt.show()

I don't recommend to reduce resolution of depth map the same way like it is done for images. Imagine a scene with a small object 5 m before the wall:

  • Using bicubic/bilinear algorithms you will get depth of something between the object and the wall. In reality there is just a free space in between.
  • Using nearest-neighbor interpolation is better but you are ignoring a lot of information and in some cases it may happed that the object just disappears.

The best approach is to use the Mode function. Divide the original depth map into windows. Each window will represent one pixel in the downsized map. For each of them calculate the most frequent depth value. You can use Python's statistics.mode() function.

Related