sname='3';
[img,map] = imread(strcat('project/',sname,'.gif'),'gif');
%img = ind2gray(img,map);
%colormap(gray);
%[edgeimg,t] = edge(img,'canny',0.5);
%imview(img);
%size(img)
global tetamap;
global edgemap;
img = ind2gray(img,map);
[edgemap,tetamap] = prewitt(img,30);
[height,width] = size(img);
%edgemap=edgeimg;
edgemap = padarray(edgemap,[3,3]);
tetamap = padarray(tetamap,[3,3]);
tracemap = zeros(size(edgemap));
colormap(gray);
imview(edgemap);
%imview(tetamap);
rowindex = 0;
count=0;
traced=false;
rowindex = 3;
index =3;
features = 0;
for rowindex =3:size(edgemap,1)-2
    row = edgemap(rowindex,:)';
    for index=20:size(row,1)-2
        if(row(index)==1 && ~traced)            
                %fprintf('tracing: line %d row %d\n',rowindex,index);
                   
                   
                     [xend,yend,shape,arclength,shapesize,allpoints,trace] = mtrace(index,rowindex);
                   
                   %resample to reflect changes made by mtrace to prevent
                   %backtracing
                   %tracemap = tracemap|trace;
                   row = edgemap(rowindex,:)';                 
                 if(shapesize>height*2 && ~traced)
                     count=count+1;
                     imview(trace);
                    traced=true;         
                    
                    shapeSpline = spline(linspace(0,1,size(allpoints,1)),allpoints(:,2));
                    features = round(ppval(shapeSpline,linspace(0,1,100)));
                    %dbfile = fopen(strcat(sname,'.shp'),'w+');
                    %fwrite(dbfile,features,'int32');
                    %fclose(dbfile);
                    
                    
                    
                end
        end            
            
    end
        
end

%imwrite(trace,'3btraced.jpg','jpg');





        
        

        
