# Per-Pixel Manifold-Based Color Calibration Technique
## 3 Derivation of the Solution
\begin{split}\frac{\partial A}{\partial a_{ij}}&=\frac{ \left[\begin{array}{cccccc}a_{11}&a_{12}&\cdots&a_{1j}&\cdots&a_{1n}\\ a_{21}&a_{22}&\cdots&a_{2j}&\cdots&a_{2n}\\ \vdots&\vdots&\vdots&\vdots&\vdots&\vdots\\ a_{i1}&a_{i2}&\cdots&a_{ij}&\cdots&a_{in}\\ \vdots&\vdots&\vdots&\vdots&\vdots&\vdots\\ a_{n1}&a_{n2}&\cdots&a_{nj}&\cdots&a_{nm}\end{array}\right]\\ &=\left[\begin{array}{cccccc}\frac{\partial a_{11}}{\partial a_{ij}}&\frac{ \partial a_{12}}{\partial a_{ij}}&\frac{\cdots}{\partial a_{ij}}&\frac{ \partial a_{1i}}{\partial a_{ij}}&\cdots&\frac{\partial a_{1n}}{\partial a_{ ij}}\\ \frac{\partial a_{21}}{\partial a_{ij}}&\frac{\partial a_{22}}{\partial a_{ij}}& \cdots&\frac{\partial a_{2j}}{\partial a_{ij}}&\cdots&\frac{\partial a_{2n}}{ \partial a_{ij}}\\ \vdots&\vdots&\vdots&\vdots&\vdots&\vdots\\ \frac{\partial a_{31}}{\partial a_{ij}}&\frac{\partial a_{22}}{\partial a_{ij}}& \cdots&\frac{\partial a_{ij}}{\partial a_{ij}}&\cdots&\frac{\partial a_{nn}}{ \partial a_{ij}}\\ \vdots&\vdots&\vdots&\vdots&\vdots&\vdots\\ \frac{\partial a_{n1}}{\partial a_{ij}}&\frac{\partial a_{n2}}{\partial a_{ij}}& \cdots&\frac{\partial a_{nj}}{\partial a_{ij}}&\cdots&\frac{\partial a_{nn}}{ \partial a_{ij}}\end{array}\right]\end{split}  \tag{10a}\] \[=\left[ \begin{array}{cccccc}\frac{\partial a_{11}}{\partial a_{ij}}&\frac{ \partial a_{12}}{\partial a_{ij}}&\cdots&\frac{\partial a_{1j}}{\partial a_{ ij}}&\cdots&\frac{\partial a_{1n}}{\partial a_{ij}}\\ \frac{\partial a_{21}}{\partial a_{ij}}&\frac{\partial a_{22}}{\partial a_{ij}}& \cdots&\frac{\partial a_{2j}}{\partial a_{ij}}&\cdots&\frac{\partial a_{2n}}{ \partial a_{ij}}\\ \vdots&\vdots&\vdots&\vdots&\vdots&\vdots\\ \vdots&\vdots&\vdots&\vdots&\vdots&\vdots\\ \vdots&\vdots&\vdots&\vdots&\vdots&\vdots\\ 0&\cdots&0&\cdots&0\end{array} \right]\] (10b) \[=\left[ \begin{array}{c}0\\ 0\\ \vdots\\ 1\\ \vdots\\ 0\end{array} \right]\cdot\left[ \begin{array}{c}0\\ 0\\ \vdots\\ 1\\ \vdots\\ 0\end{array} \right]^{T}=M_{i}\cdot M_{j}^{T}\]So, using Lemma 2 in (9), we have  
\[ \begin{split}\frac{\partial S_{1}}{\partial a_{ij}^{p}}& =2\cdot(A^{P}\cdot L^{P}-R^{P})^{T}\cdot\frac{\partial A^{P}}{ \partial a_{ij}^{p}}\cdot L^{p}\\ &=2\cdot(A^{P}\cdot L^{P}-R^{P})^{T}\cdot M_{i}\cdot M_{j}^{T} \cdot L^{p}\\ &=2\cdot M_{i}^{T}\cdot(A^{P}\cdot L^{p}-R^{P})\cdot M_{j}^{T} \cdot L^{p}\\ &=2\cdot\big{(}M_{i}^{T}\cdot A^{P}\cdot L^{p}-M_{i}^{T}\cdot R^ {p}\big{)}\cdot M_{j}^{T}\cdot L^{p}\end{split}  \tag{11}\]  
**Lemma 3**. : _Let us define a vector \(M_{i}= \begin{bmatrix}0&0&\cdots&1&\cdots&0\end{bmatrix} ^{T}\) in which all components are 0 except for i-th, which is 1. Now, we can define the selection of i-th component as:_  
\[M_{i}^{T}\cdot L= \begin{bmatrix}0&0&\cdots&1&\cdots&0\end{bmatrix} \cdot \begin{bmatrix}I_{1}&I_{2}&\cdots&I_{i}&\cdots&I_{n}\end{bmatrix} ^{T}=I_{i} \tag{12}\]  
_where L is an n component vector._  
\[M_{i}^{T}\cdot A= \begin{bmatrix}0&0&\cdots&1&\cdots&0\end{bmatrix} \cdot \begin{bmatrix}a_{11}&a_{12}&\cdots&a_{1j}&\cdots&a_{1n}\\ a_{21}&a_{22}&\cdots&a_{2j}&\cdots&a_{2n}\\ \vdots&\vdots&\vdots&\vdots&\vdots&\vdots\\ a_{i1}&a_{i2}&\cdots&a_{ij}&\cdots&a_{in}\\ \vdots&\vdots&\vdots&\vdots&\vdots&\vdots\\ a_{n1}&a_{n2}&\cdots&a_{nj}&\cdots&a_{nn}\end{bmatrix} =a_{i:} \tag{13}\]  
_where A is n by n matrix and \(a_{i:}\) mean i-th row of a matrix A._  
Using Lemma 3 on (11), we have  
\[ \begin{split}\frac{\partial S_{1}}{\partial a_{ij}^{p}}& =2\cdot\big{(}M_{i}^{T}\cdot A^{P}\cdot L^{p}-M_{i}^{T}\cdot R^{p} \big{)}\cdot M_{j}^{T}\cdot L^{p}=2\cdot\Big{(}a_{i:}^{p}\cdot L^{p}-r_{i}^{p} \Big{)}\cdot l_{j}^{p}\\ &=2\cdot\bigg{(}\sum\limits_{k}a_{ik}^{p}\cdot l_{k}^{p}-r_{i}^{p} \bigg{)}\cdot l_{j}^{p}=2\cdot\sum\limits_{k}a_{ik}^{p}\cdot l_{k}^{p}\cdot l _{j}^{p}-2\cdot r_{i}^{p}\cdot l_{j}^{p}\end{split}  \tag{14}\]  
Similarly, we would like to minimize (4).