A knight's graph on an N-by-N board In chess, a knight can only move to the positions marked with X relative to its current position, marked with ♞:





A Knight's Graph is a graph that represents all legal moves of the knight chess piece on a chessboard. Each vertex of this graph represents a square of the chessboard, and each edge connects two squares that are a knight's move apart from each other.

The graph looks like this for a standard 8-by-8 board.





Challenge:

Given an integer N, where 3 ≤ N ≤ 8, output an N-by-N matrix representing a board, where the number of possible moves from each position is shown. For N = 8, the output will be a matrix showing the values of each vertex in the graph above.

The output format is flexible. List of lists or even a flattened list etc. are accepted formats.



Complete set of test cases:

--- N = 3 ---
2 2 2
2 0 2
2 2 2
--- N = 4 ---
2 3 3 2
3 4 4 3
3 4 4 3
2 3 3 2
--- N = 5 ---
2 3 4 3 2
3 4 6 4 3
4 6 8 6 4
3 4 6 4 3
2 3 4 3 2
--- N = 6 ---
2 3 4 4 3 2
3 4 6 6 4 3
4 6 8 8 6 4
4 6 8 8 6 4
3 4 6 6 4 3
2 3 4 4 3 2
--- N = 7 ---
2 3 4 4 4 3 2
3 4 6 6 6 4 3
4 6 8 8 8 6 4
4 6 8 8 8 6 4
4 6 8 8 8 6 4
3 4 6 6 6 4 3
2 3 4 4 4 3 2
--- N = 8 ---
2 3 4 4 4 4 3 2
3 4 6 6 6 6 4 3
4 6 8 8 8 8 6 4
4 6 8 8 8 8 6 4
4 6 8 8 8 8 6 4
4 6 8 8 8 8 6 4
3 4 6 6 6 6 4 3
2 3 4 4 4 4 3 2




This is code-golf so the shortest solution in each language wins. Explanations are encouraged!
MATL, 17 16 bytes

t&amp;l[2K0]B2:&amp;ZvZ+


Try it online!

(-1 byte thanks to @Luis Mendo.)

The main part of the code is creating a matrix \$ K \$ for convolution:

$$ \mathbf{K} = \begin{pmatrix}0&amp;1&amp;0&amp;1&amp;0\\1&amp;0&amp;0&amp;0&amp;1\\0&amp;0&amp;0&amp;0&amp;0\\1&amp;0&amp;0&amp;0&amp;1\\0&amp;1&amp;0&amp;1&amp;0\end{pmatrix} $$

(Relative to the centre of the matrix, each 1 is a valid knight's move.)

t&amp;l - Form a nxn matrix of all 1s (where n is the input). Let this be M.

[2K0] - Push an array containing [2, 4, 0] on stack

B  - Convert all to binary, padding with 0s as needed

0 1 0
1 0 0
0 0 0


2:&amp;Zv - Mirror that on both dimensions, without repeating the final row/column ("symmetric range indexing").
This gives us the required matrix K. 

0 1 0 1 0
1 0 0 0 1
0 0 0 0 0
1 0 0 0 1
0 1 0 1 0


Z+ - Perform 2D convolution of K over the earlier matrix M (conv2(M, K, 'same')),
summing up the 1s at legal knight move targets for each position  

Result matrix is displayed implicitly.