What other constraints are there on these images?
For this image, "-connected-components" can be used to find the bounding boxes and centroids.
Code: Select all
magick small.png -threshold 50% -define connected-components:verbose=true -define connected-components:area-threshold=10 -connected-components 4 NULL:
Objects (id: bounding-box centroid area mean-color):
0: 30x30+0+0 14.6,15.1 509 srgb(0,0,0)
12: 10x9+3+14 7.5,18.0 90 srgb(0,0,0)
13: 10x9+17+14 21.5,18.0 90 srgb(0,0,0)
1: 12x5+2+2 7.5,4.0 57 srgb(255,255,255)
2: 11x5+16+2 21.0,4.0 49 srgb(255,255,255)
10: 12x14+2+10 7.5,17.1 48 srgb(255,255,255)
11: 12x14+16+10 21.5,17.1 48 srgb(255,255,255)
4: 1x2+19+3 19.0,3.5 2 srgb(0,0,0)
6: 2x1+8+4 8.5,4.0 2 srgb(0,0,0)
9: 1x1+23+5 23.0,5.0 1 srgb(0,0,0)
8: 1x1+20+5 20.0,5.0 1 srgb(0,0,0)
5: 1x1+22+3 22.0,3.0 1 srgb(0,0,0)
3: 1x1+7+3 7.0,3.0 1 srgb(0,0,0)
7: 1x1+21+4 21.0,4.0 1 srgb(0,0,0)
srgb(0,0,0) is black and srgb(255,255,255) is white.
The two black entries size 90 pixels, and the two largest white entries, are the ones you want.