# How to get the depth of 3D image?

**URL:** <https://discourse.vtk.org/t/how-to-get-the-depth-of-3d-image/12690>\
**Category:** Development\
**Created:** [November 13, 2023, 9:35am UTC](https://discourse.vtk.org/t/how-to-get-the-depth-of-3d-image/12690 "2023-11-13T09:35:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![learn\_forever](https://discourse.vtk.org/user_avatar/discourse.vtk.org/learn_forever/32/754_2.png) [@learn\_forever](https://discourse.vtk.org/u/learn_forever)\
**Post date:** [November 13, 2023, 9:35am UTC](https://discourse.vtk.org/t/how-to-get-the-depth-of-3d-image/12690/1 "2023-11-13T09:35:55Z")

</div>

Hi:  
I rendered a 3D image using vtk. The result looks as follows:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/c/c852f464109c4ace755b1d378be41fce7ad0556b.jpeg)

I want to get a depth map for abve image. Currently I used vtkWorldPointPicker to pick each pixel on the screen, and then got the real position through vtkWorldPointPicker .GetPickPosition(). But it takes too much time to traverse each pixel in the image.  
I was wondering maybe there is an esay way to get the depth map of the image quickly. Any clues would be appreciated.

---

<div class="post-metadata">

**Author:** ![dcthomp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dcthomp/32/60_2.png) [@dcthomp](https://discourse.vtk.org/u/dcthomp)\
**Post date:** [November 14, 2023, 4:28am UTC](https://discourse.vtk.org/t/how-to-get-the-depth-of-3d-image/12690/2 "2023-11-14T04:28:34Z")

</div>

Create a [`vtkWindowToImageFilter`](https://vtk.org/doc/nightly/html/classvtkWindowToImageFilter.html) and call `SetInputBufferTypeToZBuffer()`; then when you fetch the filter’s output image, each pixel should be filled with a depth value.
