m-adjacency

Two pixels p and q with values from V are m-adjacent if :
 
1. q is in the set N4(p), or
2. q is in the set ND(p) and the set N4(p)∩N4(q) has no pixels whose values are from V

Example

In the following image set V = {1,2} (image contains only two values)

m-adjacent values are represented with red lines