mr2.utils.filters.dct_filters

mr2.utils.filters.dct_filters(kernel_size: tuple[int, ...], dtype: dtype = torch.float32) → Tensor[source]

Create a separable orthonormal cosine basis for an N-dimensional patch.

For spatial shape \((s_1,\ldots,s_d)\), the filter indexed by \((k_1,\ldots,k_d)\) is the product of one-dimensional DCT-II rows:

\[h_{k_1,\ldots,k_d}[m_1,\ldots,m_d] = \prod_{j=1}^d C^{(s_j)}_{k_j,m_j}.\]

Frequency indices are flattened with the last axis varying fastest. The first filter is constant. Flattening each filter gives the rows of an orthonormal patch-transform matrix; its transpose is the inverse.

Parameters:
  • kernel_size (tuple[int, ...]) – Positive spatial sizes, for example (5, 7) or (5, 7, 9).

  • dtype (dtype, default: torch.float32) – Floating dtype of the filters.

Returns:

DCT basis filters of shape (prod(kernel_size), *kernel_size).