<< Combinatorica`;
i = Binarize@Import["https://i.sstatic.net/gFZ3F.png"];
mc = MorphologicalComponents[i];
l = Flatten[Thread /@ ComponentMeasurements[MaxFilter[mc, 3], "Neighbors"] /.
Rule -> List, 1];
am = ToAdjacencyMatrix@FromOrderedPairs[l];
f[n_] := f[n] = Rasterize@ ImageAdd[
Image[Unitize[mc - n] /. {1 -> {0, 0, 0}, 0 -> RandomReal[{0, 1}, 3]},
ImageSize -> IntegerPart@(ImageDimensions@i/10)],
ColorNegate@i]
k[i_, j_] := k[i, j] = k[j, i] = ImageAdd[f[i], f[j]]
mi = MapIndexed[Tooltip[#1 /.
{0 -> Graphics[{FaceForm[White], EdgeForm[Black], Rectangle[]}],
1 -> Graphics[{Orange, Rectangle[]}]}, k @@ #2] &, am, {2}];
GraphicsGrid@mi
Or the simpler:
<< Combinatorica`;
i = Binarize@Import["https://i.sstatic.net/gFZ3F.png"];
mc = MorphologicalComponents[i];
l = Flatten[ Thread /@ ComponentMeasurements[MaxFilter[mc, 3], "Neighbors"] /.
Rule -> List, 1];
ToAdjacencyMatrix@FromOrderedPairs[l] // MatrixPlot
Edit:
Without using Combinatorica
i = Binarize@Import["https://i.sstatic.net/gFZ3F.png"];
mc = MorphologicalComponents[i];
l = Flatten[ Thread /@ ComponentMeasurements[MaxFilter[mc, 3], "Neighbors"] /.
Rule -> List, 1];
UndirectedEdge @@@ DeleteDuplicates[Sort /@ l] // System`Graph //
AdjacencyMatrix // MatrixPlot