Matrix element betweenness

asked 2014-08-21 15:20:31 -0600

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.

edit retag flag offensive close merge delete

Comments

if we're talking c++, or python here, -

if you can formulate it as an equation, you might be pretty close to the actual solution..

berak gravatar imageberak ( 2014-08-21 15:33:48 -0600 )edit

yes, I can write a function to do this element wise, but looking for anything inbuilt I can use. My matrix tends to be large: 960 x 1280 or so. Need lightest CPU algorithm to get this done.

DotFrammie gravatar imageDotFrammie ( 2014-08-21 15:59:52 -0600 )edit