This notebook explain the use of the NS module to compute the analytical covariance matrix for DCT coefficients from a bloc (or 3) of photo-sites samples.
<form action="javascript:code_toggle()"><input type="submit" value="Click here to toggle on/off the raw code."></form>''')
```
%% Output
<IPython.core.display.HTML object>
%% Cell type:markdown id: tags:
## Computation pipeline :
<ol>
<li>Photo-sites selection</li>
<li>Demosaicking</li>
<li>Selection</li>
<li>Permutation</li>
<li>DCT transform</li>
<li>Transposition</li>
</ol>
%% Cell type:markdown id: tags:
### 1. Photo-sites selection
The samples comes from $n_{b}\times n_{b}$ neighboring blocks, each composed of $8\times8$ photo-sites with the surrounding border included since interpolated values inside a $8\times8$ block need photo-site values surrounding this block (see Figure below). The result of flattening according to the columns this matrix is a contiguous flattened array which is therefore the the vector of the photo-sites samples denoted $\mathbf{y}\in\mathbb{N}^{(8n_{b}+2)^{2}}$.
In our case, this means that to perform color reconstruction and luminance averaging, we can define the demosaicking and averaging matrix $\mathbf{M_{L}}$ as:
With $\mathbf{y_{L}}\in\mathbb{R}^{(8n_{b}+2)^{2}}.$
%% Cell type:code id: tags:
``` python
```
%%Celltype:markdownid:tags:
### 3. Selection
Asstatedabove,thesurroundingedgesof$n_{b}\timesn_{b}$blocksofsampleshavebeenincludedinordertotakeintoaccounttheconvolutionwindowduringdemosaicking.Oncethedemosaickingoperationshavebeencarriedout,theycannowbediscarded.Let's denote $\mathbf{L}$ the $(8n_{b}+2)\times(8n_{b}+2)$ photo-sites matrix with its outer border, and $\mathbf{L_{S}}$ without as depicted in Figure below. The matrix $\mathbf{M_{S}}\in\mathbb{R}^{(8n_{b})^{2}\times(8n_{b}+2)^{2}}$ can the be defined as :$\mathbf{y_{S}=\mathbf{\mathbf{M_{S}}}\cdot}\mathbf{y_{L}}\Leftrightarrow\mathrm{vec_{R}}(\mathbf{L_{S}})=\mathbf{\mathbf{M_{S}}}\cdot\mathrm{vec_{R}}(\mathbf{L})$With $\mathbf{y_{S}}\in\mathbb{R}^{(8n_{b})^{2}}$.
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
### 4. Permutation
%% Cell type:code id: tags:
``` python
```
%% Cell type:markdown id: tags:
### 5. DCT transform
%% Cell type:markdown id: tags:
For a $8\times8$ block in the spatial domain, $\mathbf{X_{s}}$, its 2D-DCT block version written here as $\mathbf{X_{DCT}}$ can be expressed by the following matrix multiplication :
It should be observed that the multiplication by $\mathbf{A}$ and $\mathbf{A}^{t}$ is due to the fact that the DCT transform is separable and processes the columns and rows independently. In order to compute the covariance matrix of the spatial signal $\mathbf{X_{S}}$, we use vector notation by transforming the matrix $\mathbf{X_{S}}\in\mathbb{R}^{8\times8}$ into a vector $\mathbf{x_{S}}\in\mathbb{R}^{64}$ by concatenating the columns. As a result, the $8\times8$ matrix $\mathbf{A}$ is transformed into a $64\times64$ matrix $\mathbf{A_{v}}$ given by :$$\mathbf{A_{v}}=\left[\begin{array}{cccc}
We also define a transpose operator $\mathbf{T}\in\mathbb{R}^{64\times64}$ such as $\mathrm{vec_{c}}(\mathbf{X_{S}^{t}})=\mathbf{T}\cdot\mathrm{vec_{c}}(\mathbf{X_{S}})=\mathbf{T}\cdot\mathbf{x_{S}}$, with :