MatLab找图像重心(1)

%图像要求:256*256

 

img = imread('lena256.bmp');
imgray =rgb2gray(img);
imgray = 255 - imgray;
imgray = double(imgray);
imgrayx = zeros(256);
imgrayy = zeros(256);
for i=1:256
    imgrayy(i,:)=i.*imgray(i,:);
end
for j=1:256
imgrayx(:,j)=j.*imgray(:,j);
end
m=sum(sum(imgray));
meanx=sum(sum(imgrayx))/m;
meany=sum(sum(imgrayy))/m;
imshow(img)
hold on
plot(round(meanx),round(meany))
hold off


(meanx ,meany) 即为重心坐标

你可能感兴趣的:(MatLab找图像重心(1))