m=100; n=100;
fin=fopen('ter.raw','r');
X=fread(fin,m*n,'uint8=>uint8'); fclose(fin);
Y=reshape(X,m,n);
Raw = Y ;
Raw=rot90(Raw,3);
Raw=fliplr(Raw);

figure;
subplot(2,2,1);
imshow( Raw ) ;
title('ter.raw');

%р堵跑Θフ η跑Θ堵
for i=1:100
    for j=1:100
        if Raw(i,j)>0
            Raw(i,j)=0;
        elseif Raw(i,j)==0
             Raw(i,j)=256;
        end
        
    end
end


I = bwmorph(Raw, 'thin',100);
subplot(2,2,2);
imshow( I ) ;
title('after thinning');

dim = size(I)
col = round(dim(2)/2);
row = min(find(I(:,col)))
boundary = bwtraceboundary(I,[row, col],'N');
subplot(2,2,3);
imshow(I)
hold on;
plot(boundary(:,2),boundary(:,1),'g','LineWidth',3);
title('shape boundary');

BW1 = edge(Raw,'sobel');
subplot(2,2,4);
imshow(BW1)
title('after edge detection');
