gravcenters.m
上传用户:zslfgd
上传日期:2010-04-06
资源大小:115k
文件大小:1k
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- %% %%
- %% Prof. Sclaroff's CS585 Image avd Video Processing %%
- %% Project ONE %%
- %% C H A R A C T E R R E C O G N I T I O N %%
- %% %%
- %% by Stanislav Rost %%
- %% ID: 31764117 %%
- %% %%
- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
- function [ gx, gy ] = gravcenters(matrix, width, height)
- % GRAVCENTERS.M
- %
- % function [ gx, gy ] = gravcenters(matrix, width, height)
- %
- % Returns the centers of gravity for the matrix "matrix"
- % which represents a binary image
- % Calculate the area (0-th moment), and also
- % M_10(S) and M_01(S)
- area = 0;
- m10 = 0;
- m01 = 0;
- for y = 1:height,
- for x = 1:width,
- if matrix(y,x)==1
- area = area + 1;
- m10 = m10 + x;
- m01 = m01 + y;
- end
- end
- end
- % Figure out the center of gravity
- gx = m10/area;
- gy = m01/area;