plenoptic.process.polar_to_rectangular#

plenoptic.process.polar_to_rectangular(amplitude, phase)[source]#

Polar to rectangular coordinate transform.

Parameters:
  • amplitude (Tensor) – Tensor containing the amplitude (aka. complex modulus). Must be >= 0.

  • phase (Tensor) – Tensor containing the phase.

Return type:

Tensor

Returns:

image – Complex tensor.

Raises:

ValueError – If amplitude is not non-negative.

See also

polar_to_rectangular_dict

Same operation on dictionaries.

rectangular_to_polar

The inverse operation.

local_gain_release

The analogous function for real-valued signals.

Examples

>>> import plenoptic as po
>>> import torch
>>> amplitude = torch.tensor([1.4142, 1.4142])
>>> phase = torch.tensor([0.7854, -0.7854])
>>> po.process.polar_to_rectangular(amplitude, phase)
tensor([1.+1.j, 1.-1.j])

In plenoptic, this function is typically used for working with steerable pyramid coefficients:

>>> import plenoptic as po
>>> import torch
>>> # starting from an image
>>> img = po.data.einstein()
>>> img.shape
torch.Size([1, 1, 256, 256])
>>> spyr = po.process.SteerablePyramidFreq(img.shape[-2:], is_complex=True)
>>> # let's only look at 1 scale and 1 orientation
>>> coeff = spyr(img)[0][:, :, 0]
>>> # the coefficients returned by spyr (forward) are in rectangular coordinates
>>> # so, we can manually compute polar coordinates
>>> amplitude, phase = torch.abs(coeff), torch.angle(coeff)
>>> amplitude.shape
torch.Size([1, 1, 256, 256])
>>> phase.shape
torch.Size([1, 1, 256, 256])
>>> # from those, we can use this function to recover the rectangular coordinates
>>> rectangular_coeff = po.process.polar_to_rectangular(amplitude, phase)
>>> rectangular_coeff.shape
torch.Size([1, 1, 256, 256])
>>> # we can verify that they match the original
>>> torch.allclose(coeff, rectangular_coeff)
True