Adjacency of connected components?

Hi folks, I’m looking to build a list of which pairs of connected components are adjacent, i.e. list of pairs of labels denoting adjacency. Feels like it should be a standard procedure, but can’t locate a solution within opencv. Any tips/pointers?

To give a simple example, say I have an image of 3x3 tiles of different colors. getConnectedComponents will give me a mask like this

111...222...333
...
111
444
...
777...888...999

I’m looking for a function that’ll give me the following output, indicating adjacency of different colors:

[(1, 2), (2, 3), (1, 4), (4, 5), (5, 2), (5, 6), (6, 3), (7, 4), (7, 8), (8, 5), (8, 9), (9, 6)]

Is there something that can achieve this?