fid=fopen("names.txt","r");
folder="jpg-/";
name=fgetl(fid);
num_faces=143;
face_dims=[115 144];
faces=zeros(num_faces, prod(face_dims));
for i=1:num_faces
final=strcat(folder,name);
A=imread(final);
faces(i,:)=A(:);
name=fgetl(fid);
i++;
endfor
n=i

# input has been taken

euclidean = zeros(num_faces, num_faces);
for i=1:num_faces
row1 = faces(i,:);
for j=1:num_faces
if j!=i
row2 = faces(j,:);
diff = row1-row2;
dist = diff*diff';
dist = sqrt(dist);
euclidean(i,j) += dist;
endif
endfor
endfor

#made the euclidean matrix

k=9; #no. of neighbours

graph = zeros(num_faces, num_faces);
[s,i] = sort(euclidean);
i;
for ind=1:num_faces
for p=1:k+1
neigh=i(p,ind);
if neigh !=ind
if (ind==25 || ind==10)
face=faces(neigh,:);
face = reshape(face(:), face_dims);
imwrite(uint8(face), strcat('images/', num2str(ind), 'neighbour', num2str(neigh), '.jpg'));
endif
graph(ind,neigh)=euclidean(ind,neigh);
graph(neigh,ind)=euclidean(ind,neigh);
endif
endfor
endfor
graph;

geodesic=allspath(graph);

M = mbed(geodesic,2);
figure;
fig=gcf;
y=M(:,1);
x=M(:,2);
plot(x,y,'o');
hold on
print(fig,"images/2DManifold.jpeg") -djpeg;
hold off
figure;
fig=gcf;
labels = cellstr(num2str([1:num_faces]'));
plot(x,y,'rx');
hold on;
text(x,y,labels, 'VerticalAlignment', 'bottom', 'HorizontalAlignment', 'right');
hold on;
print(fig,"images/2DManifoldlabel.jpeg") -djpeg;
hold off
#residual=zeros(1,10);
#for m=1:10
#embed = mbed(geodesic,m);
#cor=corrcoef(geodesic);
#size(cor)
#residual(1,i) = 1 - cor*cor';
#endfor
#residual

