Ask Your Question

Revision history [back]

Matrix element betweenness

Background: I have three matrices of the same size. A, B and C. Most elements in these matrices are the same except a few.

Ask: I want to deduce a 4th matrix D (the same size) that gives element "1" whenever corresponding element of B is between that of A and C. Otherwise 0 for that element.

Clarification: I don't care too much if it isn't "1" and it is an actual subtraction between element A and C. I just need a 0 if B's element is not between that of A and C.

Example If A, B and C are as follows: A(3x3)= 12 24 18 34 45 35 08 12 34

B(3x3)= 13 26 18 45 01 38 80 10 34

C(3x3)= 10 34 18 45 45 35 90 09 34

I want to calculate a D using openCV or matrices manipulations so that it can be D(3x3)= 0 1 1 1 0 0 1 0 1

Basically 1 when B's element is between A's and C's element inclusive.

Thanks in advance!

Preferably I want a matlab/ opencv way to do this.