A binary image is an image made up of 0, 1. We can get a series of information about images through some simple calculations.
Area:
Sum of all 1
Location:
The position of the image is generally expressed by centroid, and we can calculate the centroid of the x-axis and y-axis direction directly according to the definition of centroid, then get the center (XM,YM)
Orientation:
The definition of orientation given in the book "Machine Vision":
Here, we need to ask for the smallest second moment corresponding to the axis.
We use a point and the angle of the line and the x-axis to define the position of the axis, first we are deduced to obtain: the smallest second moment corresponding to the axis through the centroid.
Next, we only need an angle.
which
Projection:
In simple terms, the projection is the sum of 1 in one direction.
In concrete implementations, we can use incremental thinking to speed up operations. We know that when the image is loaded, we load the image one line at a time, so we can calculate the first and second moments in this process, and then calculate some of the eigenvalues of the binary image.
Matlab code:
function twovalueimg (f)
[m,n] = size (f);
s = 0; % area
x1 = 0;% First order moment x direction
y1 = 0;% First order moment y direction
a = 0;% Second moment
b = 0; second moment
c = 0;% second moment for
i = 1:m
for j = 1:n
if (f (i,j) ==1)% increment thought
s = s + 1;
X1 = x1 + i;
Y1 = y1 + j;
A = a + I*i;
B = b + i*j;
c = C + j*j;
End End End