# DCT - Coefficients and Basis Function

I am trying to understand how the Discrete Cosine Transformation works but I am not sure if I am at the right road.

Assuming that I have an $$8\times8$$ pixels image and I am applying the DCT to this sample. What I will get as a result is a $$8\times8$$ matrix of the DCT Coefficients.

In order to convert from this to the original image I will need to multiply each DCT Coefficient with its corresponding basis function and sum the result. But how do I calculate the basis function if DCT only returns the coefficients?

## 2 Answers

When DCT is defined by a matrix, then this matrix contains the necessary information to build the basis functions.

Suppose that $$I$$ is your $$8\times8$$ block, and $$D$$ a real $$8\times8$$ matrix for a 1D DCT (with column-wise vectors). Then $$D^TI$$ applies the DCT on columns, and $$ID$$ does it on rows. Thus, a 2D DCT yields a $$8\times8$$ matrix $$C$$ of coefficients defined by:

$$C = D^T I D\,.$$

Consequently, we have $$I = D C D^T \,.$$

If we call $$\Gamma_{m,n}$$ the matrix such that every element is zero, except for $$\Gamma[m,n]=1$$ (the canonical basis), then

$$C = \sum_{m,n} C[m,n]\Gamma_{m,n}$$

hence, by linearity:

$$I = \sum_{m,n} C[m,n] D \Gamma_{m,n} D^T \,.$$

Each matrix $$D \Gamma_{m,n} D^T$$ is an element of the basis you are looking for.

My knowledge of DFT is not very advanced but from I understand it is similar to other frequency domain transforms like Fourier or Radon. The frequencies that you want to check against have already been defined and "standardized". The way that you sum those different frequencies create frequencies that resemble the one you are trying to recreate. So to answer your question more directly, the function that you are using to create the 8x8 matrix is already aplying said functions. For inverting that operation you need the inverse (not completely sure about this but I can see from this answer https://stackoverflow.com/questions/54295413/change-code-from-dct-to-inverse-discrete-cosine-transformation) If you need more information check out Radial basis functions which do a similar decomposition but are more visually clear.