function norFromPS

ln=input('Enter the path of the folder containing PS images and lightDirection.txt:\n','s');
fname=input('Enter the name of images without suffix and order number:\n','s');
fsuffix=input('Enter image suffix whithout dot:\n','s');

L=dlmread(strcat(ln,'\lightDirection.txt'));
N=size(L,1);
sampleImg=imread(strcat(ln,'\',fname,'1.',fsuffix));
imHeight=size(sampleImg,1);
imWidth=size(sampleImg,2);

I=zeros(imHeight,imWidth,N);
for i=1:N
    fn=strcat(ln,'\',fname,num2str(i),'.',fsuffix);
    temp=imread(fn);
    I(:,:,i)=double(rgb2gray(temp));
end

nor=zeros(imHeight*imWidth,3);
for i=1:imHeight
    for j=1:imWidth
        i1=imHeight-i+1;
        id=(i-1)*imWidth+j;
        Ik = reshape(I(i1,j,:),N,1);
        if sum(Ik)<eps*1e8
            nor(id,:) = [0 0 0];
        else
            tempN = pinv(L)*Ik;
            if norm(tempN)~=0
                tempN = tempN./norm(tempN);
                tempN(2)=-1*tempN(2);
            else
                tempN=[0 0 0];
            end
            nor(id,:) = tempN;
        end
    end
end

sizeV=[imWidth imHeight];
fn=strcat(ln,'\normal.txt');
dlmwrite(fn,sizeV,'precision', '%.8f');
dlmwrite(fn,nor,'-append','precision', '%.8f');
display('Done! Output normal file is saved in:');
display(strcat(ln));