Solved – Whitening and unwhitening for sparse coding

MATLABnormalizationstandardization

Is this procedure for whitening and unwhitening correct?

Given an image $i$:

decompose the image in patches:

patch=im2col(i,[8 8],'sliding');

Whitening step:

1) subtract the mean from each patch (i.e., from each column):

meanP=mean(patch);
patch_m=patch-repmat(mean(patch),[size(patch,1) 1]);

2) divide by the standard deviation:

devP=sqrt(sum(patch.^2));
devpatch_m=sqrt(sum(patch_m.^2));
patch_m_s=patch_m./repmat(sqrt(sum(patch_m.^2)),[size(patch_m,1) 1]);

Unwhitening step:

1) multiply by the standard deviation:

rec_patch= rec_patch .* repmat(devpatch_m, [size(rec_patch,1) 1]);

2) add the mean:

rec_patch=rec_patch+repmat(meanP,[size(rec_patch,1) 1]);

I have also read that before starting the unwhitening step, it is possible to subtract the mean from the "new patches" obtained from the sparse coding step. Which is the correct procedure?

Best Answer

To whiten a $n$ by $d$ matrix $M$ it is not enough to center and scale: you also have to remove the correlation structure. So, denoting $M'$ your whitened matrix, we have:

$$M'=(M-t_M)'S_M^{-1/2}$$

where $t_M$ is the $d$ vector of columnwize means of $M$ and $S_M$ is $M$'s covariance matrix:

$$S_M=\frac{1}{n-1}(M-t_M)'(M-t_M)$$