.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "auto_examples/basics/demo_lidar.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_auto_examples_basics_demo_lidar.py: Single photon lidar operator for depth ranging. =================================================== In this example we show how to use the :class:`deepinv.physics.SinglePhotonLidar` forward model. .. GENERATED FROM PYTHON SOURCE LINES 8-19 .. code-block:: Python import deepinv as dinv import torch import matplotlib.pyplot as plt # Use matplotlib config from deepinv to get nice plots from deepinv.utils.plotting import config_matplotlib config_matplotlib() .. GENERATED FROM PYTHON SOURCE LINES 20-38 Create forward model ----------------------------------------------- We create a lidar model with 100 bins per pixel and a Gaussian impulse response function with a standard deviation of 2 bins. The forward model for the case of a single depth per pixel is defined as (e.g. see `this paper `_): .. math:: y_{i,j,t} = \mathcal{P}(h(t-d_{i,j}) r_{i,j} + b_{i,j}) where :math:`\mathcal{P}` is the Poisson noise model, :math:`h(t)` is a Gaussian impulse response function at time :math:`t`, :math:`d_{i,j}` is the depth of the scene at pixel :math:`(i,j)`, :math:`r_{i,j}` is the intensity of the scene at pixel :math:`(i,j)` and :math:`b_{i,j}` is the background noise at pixel :math:`(i,j)`. .. GENERATED FROM PYTHON SOURCE LINES 38-44 .. code-block:: Python device = dinv.utils.get_freer_gpu() if torch.cuda.is_available() else "cpu" bins = 100 irf_sigma = 2 physics = dinv.physics.SinglePhotonLidar(bins=bins, sigma=irf_sigma, device=device) .. GENERATED FROM PYTHON SOURCE LINES 45-56 Generate toy signal and measurement ----------------------------------------------- We generate a toy signal with a single peak per pixel located around the 50th bin and a signal-to-background ratio of 10%. Signals should have size (B, 3, H, W) where the first channel contains the depth of the scene, the second channel contains the intensity of the scene and the third channel contains the per pixel background noise levels. The measurement associated with a signal has size (B, bins, H, W). .. GENERATED FROM PYTHON SOURCE LINES 56-74 .. code-block:: Python sbr = 0.1 signal = 50 bkg_level = signal / sbr / bins depth = bins / 2 # depth d = torch.ones(1, 1, 2, 2, device=device) * depth # signal r = torch.ones_like(d) * signal # background b = torch.ones_like(d) * bkg_level x = torch.cat([d, r, b], dim=1) # signal of size (B, 3, H, W) y = physics(x) # measurement of size (B, bins, H, W) .. GENERATED FROM PYTHON SOURCE LINES 75-82 Apply matched filtering to recover the signal and plot the results ------------------------------------------------------------------------------- We apply matched filtering to recover the signal and plot the results. The measurements are shown in blue and the depth and intensity of the recovered signals are shown in red. .. GENERATED FROM PYTHON SOURCE LINES 82-102 .. code-block:: Python xhat = physics.A_dagger(y) plt.figure() for i in range(2): for j in range(2): plt.subplot(2, 2, i * 2 + j + 1) plt.plot(y[0, :, i, j].detach().cpu().numpy()) plt.stem( xhat[0, 0, i, j].detach().cpu().numpy(), xhat[0, 1, i, j].detach().cpu().numpy() / 4, linefmt="red", markerfmt="red", ) plt.title(f"pixel ({i}, {j})") plt.tight_layout() plt.show() .. image-sg:: /auto_examples/basics/images/sphx_glr_demo_lidar_001.png :alt: pixel (0, 0), pixel (0, 1), pixel (1, 0), pixel (1, 1) :srcset: /auto_examples/basics/images/sphx_glr_demo_lidar_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/work/deepinv/deepinv/deepinv/physics/lidar.py:79: UserWarning: Using padding='same' with even kernel lengths and odd dilation may require a zero-padded copy of the input be created (Triggered internally at /pytorch/aten/src/ATen/native/Convolution.cpp:1036.) x = torch.nn.functional.conv1d(y, self.irf, padding="same") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.258 seconds) .. _sphx_glr_download_auto_examples_basics_demo_lidar.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo_lidar.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo_lidar.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo_lidar.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_