Decolorize#

class deepinv.physics.Decolorize(channels=3, srf='rec601', device='cpu', **kwargs)[source]#

Bases: DecomposablePhysics

Converts n-channel images to grayscale.

The image channels are multiplied by factors determined by the spectral response function (SRF), then summed to produce a grayscale image.

We provide various ways of defining the SRF including the rec601 convention for RGB images.

In the adjoint operation, we multiply the grayscale image by the coefficients in the SRF.

Images must be tensors with C channels, i.e. (B,C,H,W). The measurements are grayscale images.

Parameters:
  • channels (int) – number of channels in the input image.

  • srf (str, tuple, list) –

    spectral response function. Either pass in user-defined SRF (must be of length channels), or rec601 (default) following the rec601 convention, or flat for a flat SRF (i.e. averages channels), or random for random SRF (e.g. to initialise joint learning).

  • device (str, torch.device) – device on which to perform the computations. Default: cpu.


Examples:

Decolorize a 3x3 image:

>>> import torch
>>> from deepinv.physics import Decolorize
>>> x = torch.ones((1, 3, 3, 3), requires_grad=False) # Define constant 3x3 RGB image
>>> physics = Decolorize()
>>> physics(x)
tensor([[[[1.0000, 1.0000, 1.0000],
          [1.0000, 1.0000, 1.0000],
          [1.0000, 1.0000, 1.0000]]]])

Examples using Decolorize:#

Remote sensing with satellite images

Remote sensing with satellite images

A tour of forward sensing operators

A tour of forward sensing operators