SinglePixelCamera#

class deepinv.physics.SinglePixelCamera(m, img_shape, fast=True, ordering='sequency', device='cpu', dtype=torch.float32, rng=None, **kwargs)[source]#

Bases: DecomposablePhysics

Single pixel imaging camera.

Linear imaging operator with binary entries.

If fast=True, the operator uses a 2D subsampled Hadamard transform, which keeps the first \(m\) modes according to the ordering parameter, set by default to sequency ordering. In this case, the images should have a size which is a power of 2.

If fast=False, the operator is a random iid binary matrix with equal probability of \(1/\sqrt{m}\) or \(-1/\sqrt{m}\).

Both options allow for an efficient singular value decomposition (see deepinv.physics.DecomposablePhysics) The operator is always applied independently across channels.

It is recommended to use fast=True for image sizes bigger than 32 x 32, since the forward computation with fast=False has an \(O(mn)\) complexity, whereas with fast=True it has an \(O(n \log n)\) complexity.

An existing operator can be loaded from a saved .pth file via self.load_state_dict(save_path), in a similar fashion to torch.nn.Module.

Warning

Since version 0.3.1, a small bug in the sequency ordering has been fixed. However, it is possible to use the old sequency ordering by setting ordering='old_sequency'.

Parameters:
  • m (int) – number of single pixel measurements per acquisition (m).

  • img_shape (tuple) – shape (C, H, W) of images.

  • fast (bool) – The operator is iid binary if false, otherwise A is a 2D subsampled hadamard transform.

  • ordering (str) – The ordering of selecting the first m measurements, available options are: 'sequency', 'cake_cutting', 'zig_zag', 'xy', 'old_sequency'.

  • rng (torch.Generator) – (optional) a pseudorandom random number generator for the parameter generation. If None, the default Generator of PyTorch will be used.


Examples:

SinglePixelCamera operators with 16 binary patterns for 32x32 image:

>>> from deepinv.physics import SinglePixelCamera
>>> seed = torch.manual_seed(0) # Random seed for reproducibility
>>> x = torch.randn((1, 1, 32, 32)) # Define random 32x32 image
>>> physics = SinglePixelCamera(m=16, img_shape=(1, 32, 32), fast=True)
>>> torch.sum(physics.mask).item() # Number of measurements
16.0
>>> torch.round(physics(x)[:, :, :3, :3]).abs() # Compute measurements
tensor([[[[1., 0., 1.],
          [0., 0., 0.],
          [0., 0., 0.]]]])

Examples using SinglePixelCamera:#

A tour of forward sensing operators

A tour of forward sensing operators

Pattern Ordering in a Compressive Single Pixel Camera

Pattern Ordering in a Compressive Single Pixel Camera

PnP with custom optimization algorithm (Condat-Vu Primal-Dual)

PnP with custom optimization algorithm (Condat-Vu Primal-Dual)