Consider this simple binary image created with
Code: Select all
convert -size 100x200 xc:black -fill white -draw "rectangle 0,0 79,49" -draw "rectangle 0,50 19,99" foo.png
Code: Select all
convert foo.png -define connected-components:verbose=true -connected-components 4 null:
Objects (id: bounding-box centroid area mean-color):
1: 100x200+0+0 54.8,121.2 15000 gray(0)
0: 80x100+0+0 33.5,34.5 5000 gray(255)
My idea was: consider each white pixel as a vector v_t=(x_t,y_t). So we have N=5000 vectors, ie, t=1...N. Then, compute sum of x_t and divide by N. The same for y_t.
But what are coordinates x_t? I think that we have to split in two rectangles, for example, x_t=0..79 and y_t=0..49. Similar arguments for the other rectangular part.
But I'm no able to obtain the same value for centroid. I got 34,25.
What am I missing?
Also, using OpenCV pca_analysis I got 31,41 and the following image: