简体   繁体   中英

Given two equally sized binary matrices, compute a pattern similarity score

Say I have a two 4*4 matrices (representing binary images) and I want to compute a similarity score (from 0 to 1) of the pattern displayed on the two matrices. The number of 'on' pixels is always the same between the two matrices eg:

M1
0 1 1 1
0 0 0 1
0 0 0 0
0 0 0 0

M2
0 0 0 0
0 0 0 0
1 1 1 0
0 0 1 0

M3
1 0 0 1
0 0 0 0
0 0 0 0
1 0 0 1

M4
0 0 0 0
1 1 1 0
0 0 0 1
0 0 0 0

In this case, I want M1:M2 to give a perfect score (1) because positioning of the pattern is irrelevant. M1:M3 should give a very poor score, and M1:M4 would get a good, but imperfect, score. For now, I'm only interested in patterns in the same orientation, so checking pattern orientation is not needed.

Any help or recommendations for relevant algorithms would be much appreciated!

The final implementation of this will be written in Matlab, but I'm writing up an initial test implementation in Python, so libraries in either are fine :)

seems like an operation on conv2 will be related , but that was just suggested. Here's a different approach, since M1 and M2 are identical they have the same principal components, so svd can be helpful as a measure of similarity, for example:

abs(sum(svd(M1)-svd(M2)))
ans =
   1.1102e-16

abs(sum(svd(M1)-svd(M4)))
ans =
   0.1189

abs(sum(svd(M3)-svd(M4)))
ans =
    0.7321

This is straight computer vision, but here is a naive starter: Convole the two matrices over each other for each possible arrangement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM