www.pudn.com > regionprops.rar > regionprops-centroid.m, change:2011-05-06,size:727b


%用regionprops中的Centroid属性来求得两幅图之间各个质点质心位移 
clear; 
A=imread('5before.JPG'); 
B=rgb2gray(A);  
X=im2bw(B,graythresh(B)); 
X=~X; 
[L1,num1] = bwlabel(X,8); 
stats1 = regionprops(L1, 'Centroid');  
figure; imshow(X); hold on;  
for i =1:length(stats1)  
temp1 = stats1(i).Centroid; ;  
plot(temp1(1), temp1(2), 'r+'); 
end 
C=imread('5after.JPG'); 
D=rgb2gray(C);  
Y=im2bw(D,graythresh(D)); 
Y=~Y; 
[L2,num2] = bwlabel(Y,8); 
stats2 = regionprops(L2, 'Centroid');  
figure; imshow(Y); hold on;  
for k =1:length(stats2)  
temp2= stats2(k).Centroid;  
plot(temp2(1), temp2(2), 'r+'); 
end 
x=temp2(1)-temp1(1) 
y=temp2(2)-temp1(2) 
xlswrite('d:\2.csv',[x y],'A1:B1');%将x,y存入CSV中,打开时选择用EXCEL打开即可