Yi Ma’s Robust Face Recognition using Sparse Representation; matlab code

June 29, 2012 3 comments

Following is a matlab version of simple Face Recognition algorithm given by Yi Ma.

</pre>
%build the dictionary from training
imgTrain = double(Tr_dataMatrix);
imgTest  = double(Tt_dataMatrix);

mx = mean(imgTrain,2);
D = imgTrain - repmat(mx, 1, size(imgTrain,2));

imgTest = imgTest - repmat(mx, 1, size(imgTest,2));

totalTest = size(imgTest,2);
lambda2 = 3;
addpath D:\mohsen\matlabCode\sparseCoding\elad\;
[U S V] = svd(D);
[egVal ind] = sort(diag(S), 'descend');
egV = U;
egV = egV(:, ind);

D = egV(:,1:200)'*D;
D = D./repmat(sqrt(sum(D.^2)),size(D,1),1);
imgTest = egV(:,1:200)'*imgTest;
 ci = zeros(size(D,2), size(imgTest,2));
ci = GetSparseFast(D,imgTest,0*zeros(size(D,2), size(imgTest,2)),500,1, 40);
testImgId = [];
rejectedI = [];
for i=1:totalTest
 recEr = 0;
 recMinid = -1;
 for p=1:totalPeople
   recErt = norm(imgTest(:,i)-D*(ci(:,i).*(imgTrainLabel'==p)));
   if recErt < recEr || p == 1
        recMinid = p; recEr = recErt;
   end
 end
 testImgId(i) = recMinid;
end

Matlab and Object orientation

March 3, 2012 Leave a comment

It’s high time to start implementing the object orientation in the matlab. If you are good in C/C++ you know how to develop classes and why to develop them.
Few caveats however, changes inside the method of any class member does not mean that object has been updated. Remember to return the object itself and re-assign it to iself. Unless you define it as subclass of ‘handle’. http://www.mathworks.com/help/techdoc/matlab_oop/brfylzt-1.html#brfylzt-2

 

When Pre-Allocating (i.e. array of classes )use the “empty”
have a look at http://www.mathworks.com/help/techdoc/matlab_oop/brd4btr.html#brd4nrh

srun and matlab

November 19, 2011 Leave a comment

ok Mr. Cluster, here I come, I have unlocked the power to issue commands to your nodes for my maltab function ha ha ha ha!

so if you are in slurm
srun -n1 -o t.txt matlab -nodesktop -nosplash -nodisplay -r “temp4(29)” &

t.txt <— will get all the output

after -r you can give all the commands as the form of script i.e. ” ”

in above case temp4 was matlab file function, and 29 was input

& so that it can run in background

-n1 only one measly node 😦

But then you can run multiple of such commands and each one gets node 🙂

Don’t forget to open the matlabpool in the file you are running if you are using the parallel commands.

Categories: basic, code, matlab Tags: , , , , ,

getPatch; matlab function to get a patch from a matrix

April 1, 2011 Leave a comment
function mat = getPatch(srcMat, rect)
%function getPatch(srcMat, rect)
%rect is [x y width height]

stX = max(rect(1),1);stY = max(rect(2),1);
endX = min(rect(1)+rect(3)-1, size(srcMat,1));endY = min(rect(2)+rect(4)-1, size(srcMat,2));
mat = srcMat(stY:endY, stX:endX);
Categories: code, matlab, matlab Code Tags: ,

cygwin/x cannot establish any listening sockets

March 10, 2011 Leave a comment

Running cygwin/x I was facing following error
Cannot establish any listening sockets  Make sure an X server isn’t already running

poked around to find what’s happening, firewall was fine and I was on the administrator account, but it appears one has to set the application it-self as “run as administrator”

i.e. go to the XWin file, right click, get the properties, go to advanced and check  “Run as administrator”.

fixing MSVCR100.DLL not found

December 23, 2010 Leave a comment

Just download Microsoft Visual C++ Redistributable Package. It will install the MSVCR100.DLL in folder windows\system32.
However I was not able to get MSVCR100D.DLL for the debugging

Categories: Uncategorized

Dynamic Multi-dimensional memory allocation C/C++

October 15, 2010 Leave a comment

An excellent library for the multi dimensional memory allocation.

http://www8.cs.umu.se/~isak/snippets/mdalloc.c

some other code snippets are http://www8.cs.umu.se/~isak/snippets/