Calculating difference between two matrices to a scalar

1.1k Views Asked by At

I want to calculate the difference between two n x n matrices to a scaler. That measure should give the idea about the physical location of each values too. For example if I name some operation with '~'

A = 1 0    B = 2 0   C = 0 0   D = 0 0
    0 0        0 0       1 0       2 0

If '~' is to compare each pixel which is A[i, j] with B[i, j] and to get the summation of them, it gives B ~ A = D ~ C = 1

But since the measure should give an idea about the locations B ~ A and D ~ C cannot be equal because in A,B the change is in [0,0] and in C,D the change is in [1,0]

So what are the measures/ ways that I can calculate the difference of two matrices to a scaler reflecting their physical locations?

1

There are 1 best solutions below

4
On

For $A\sim B$ you could calculate a new matrix $N_{ij} = \left\{\begin{array}{l}1 \text{ if } A_{ij}\ne B_{ij}\\0 \text{ if } A_{ij}= B_{ij}\end{array}\right.$, then define $A \sim B = \displaystyle\sum_{i=1}^n\sum_{j=1}^n N_{ij}2^{in+j}$. Then $\sim$ is basically a large binary number, each non-zero bit of which indicates a difference between $A$ and $B$ at a particular location.