2014-03-04 73 views
0

我需要在Matlab中创建一个GUI。它要求我确定两幅图像的斑点,并计算它们之间的距离。矩阵的Matlab GUI GUI

我已经获得了查找和包围单个点的代码。其计算方法如下:

function [meanx,meany] = centroid(pic) 
[x,y,z] = size(pic); 
if(z==1) 
    ; 
else 
    pic = rgb2gray(pic); 
end 

% N=2; 
% image = interp2(double(pic),N,'spline'); 
image = sort(sort(pic,1),2); 
image =reshape(image,1,numel(image)); 
i=0; 
while(i<3) 
     if(image(end)==image(end-1)) 
       image(end)=[]; 
     else 
      image(end)=[]; 
      i=i+1; 
     end 
end 
    threshold = image(end); 
     pic2 =(pic>=threshold); 
pic=(pic-threshold).*uint8(pic2); 
% % image=(pic-threshold+1).*uint8(image);  %minus threshold 


[rows,cols] = size(pic); 
x = ones(rows,1)*[1:cols]; 
y = [1:rows]'*ones(1,cols); 

area = sum(sum(pic)); 
if area ~= 0 
    meanx = sum(sum(double(pic).*x))/area; 
    meany = sum(sum(double(pic).*y))/area; 
else 
    meanx = cols/2; 
    meany = rows/2; 
end 

不过,我需要它为多点工作,如下图所示:

http://imgur.com/oEe0mRV,UAnbH5y#0

http://imgur.com/oEe0mRV,UAnbH5y#1

到目前为止,我想出了这一点,但它只是圈出不同的景点而不是全部。 请帮助 - 我需要包围至少10X10个点并存储它们的值,并为上面显示的两个图像执行此操作,并找到它们之间的距离!

img1 = imread('r0.bmp'); 
centroidmat=zeros(10,10,2); 
for numx=1:2 
    for numy=1:2 
     single_spot=img1((numx*220+780):((numx+1)*220+780),(numy*220+1272):((numy+1)*220+1272),:); 
     figure 
     imshow(single_spot); 
     figure 

     [cx,cy] = centroid(single_spot); 
     centroidmat(numx,numy,1)=cx; 
     centroidmat(numx,numy,2)=cy; 
     imshow(single_spot); 
     hold on; 
     plot(cx,cy,'og') 

    end 
end 

Please HELP GUYS!Please HELP GUYS!任何帮助表示赞赏!

回答

0

这项工作? -

centroidmat=zeros(10,10,2); 
for numx=1:2 
    for numy=1:2 
     single_spot=img1((numx*220+780):((numx+1)*220+780),(numy*220+1272):((numy+1)*220+1272),:); 

     [cx,cy] = centroid(single_spot); 
     centroidmat(numx,numy,1)=cx; 
     centroidmat(numx,numy,2)=cy; 

     figure, 
     imshow(single_spot); 
     hold on; 
     plot(cx,cy,'og') 
    end 
end 

我只被移去的冗余imshow(single_spot);在循环的开始,因为它们稍后再次出现在同一个循环中。