Pixel Adjacency

Now that we've learned about neighbors, let's talk about adjacency. Adjacency involves not only position (like neighborhood does), but also pixel value.

For the sake of simplicity, let's only consider binary images, that have values of 0 and 1. These mutated-crossword looking things are our images: pixels with values of 1 are represented by white squares, while pixels with values of 0 are black.

An image, believe it or not.

Adjacency in an image depends on the position and value of the pixels we're interogating. We need them to be in the correct neighborhood, and we need those pixels within that neighborhood to have the correct values. What is a 'correct' value? That's up to you. For the case of binary images, usually the value of '1' is used, though for your standard black and white images (which often have 256 shades of gray), it could be ranges of intensities.

Like with our neighbors, we have three common definitions of adjacency. The first two - 4-adjacency and 8-adjacency - you could probably intuit based off our discussion of 4-neighbors and 8-neighbors. The only difference is that both the pixel you're pointing at and the neighbors have to be 'correct' (in this case, the value has to be 1).

4-adjacency

8-adjacency

The third definition of adjacency - known as mixed-adjacency - is a bit more complex. You can think of it like an 'augmented 4-adjacency'. It will always contain all 4-adjacent pixels, and it will contain 8-adjacent pixels only if that pixel (q) does not share a 4-adjacent pixel with the pixel we're pointing at (p).

Mixed-adjacency

Before explaining it in more detail, try playing around with an interactive example first to see if you can come up with your own rules. In particular, put your cursor where diagonals are white but the 4-neighbors are black.

To explain in more detail, let's consider if a specific pixel (p) is adjacent with another specific pixel (q)

Are these pixels adjacent (by mixed adjacency)? Think for a moment from the rules you generated previously. Then, try to find an example in the interactive grid above. Finally, check the answer below.

Answer

No - p and q are not adjacent by mixed adjacency, because they share an N4 pixel they are adjacent with

What about these pixels?

Answer

Yes, they are adjacent by mixed adjacency! They don't share any adjacent N4 pixels.

Finally, what about these?

Answer

Yes - if they are adjacent in N4-adjacency, they are adjacent in mixed-adjacency.