2014-04-01 11:48:10 -0600 commented answer PCA Update Implementation - Discussion Removing zeroes just alters the number of columns, while the rows are kept the same. Think of the dimensions as the rows being the dimensions of the features and the columns being just the number of vectors! The matrix form is there just to perform vector multiplications more easily. In fact, to project a vector v (Px1) on a basis of N vectors with size (Px1) you should do the scalar product N times, but if you pack the N vectors in a matrix Q (PxN) you can do that easily by just computing transpose(Q)*v, and you get an Nx1 vector with the projection scores. Moreover, given Q as a PxN matrix, since you always compute Q*trasponse(Q), the inner dimension N does not count, you always get a PxP matrix. 2014-04-01 06:39:32 -0600 commented answer PCA Update Implementation - Discussion As for the orthonormalization, http://en.wikipedia.org/wiki/Gram%E2%80%93Schmidt_process is a standard procedure for doing it! Did I get what the problem was? 2014-04-01 06:38:28 -0600 commented answer PCA Update Implementation - Discussion So, U (PxN) and V (PxM) are obtained by the PCA procedure. The vectors are the columns of these matrices. G (NxM) represents the projection of the vectors of V on U. H (PxM) holds the M vectors orthogonal to U (which then provide new information to the model). Since some of them could be described the U vectors, it's possibile that some of the columns of H are full of zeros. These have to be removed. Then you compute the new matrix Q = [U,H'], where H' is H without the zero columns, with size [P,N+M-#zeroVectors]. As for the means, I'm not sure of the step described in the paper, but I would proceed similarly to what e have done for V. h = (meanX-meanY); (Px1) g = transpose(Q)h; j = h - Qg; j is the component of h orthogonal to q, and if ... 2014-04-01 06:09:17 -0600 commented answer Implementation Run Length Smoothing Algorithm in C++ Sorry for the huge delay :P I'm not sure that you can avoid these loops! In any case, you could use pointers to access the Mat elements instead of the at<>() function! uchar* p = Mat.data; int pos = j*Img.Cols + i; if(p[pos]==0) [...] 2014-02-10 08:30:33 -0600 answered a question Implementation Run Length Smoothing Algorithm in C++ Well, regarding the index start problem, you just have to shift everything in order to make it work I think. As for the setting to 0 the matrix, I think you could use the Rect class: tmpText(Rect(i,j-zero_count,zero_count-1,1)).setTo(0);  or something like this, where you specify starting position, width and height. In any case, in what way the result is not as expected?