Your input is a matrix (2d array) of positive integers. For example:
\begin{matrix} 1 & 1 & 4 & 7\\ 1 & 3 & 5 & 6\\ 2 & 1 & 4 & 5 \\ \end{matrix}
A semi-continuous transformation of this matrix is a rearranging of elements that preserves immediate neighbors. For example, we can swap the \$2\$ in the bottom left, and the \$1\$ in the top left corner.
\begin{matrix} 2 & 1 & 4 & 7\\ 1 & 3 & 5 & 6\\ 1 & 1 & 4 & 5 \\ \end{matrix}
This is fine, because every number has the same neighborhood counts. That is, we can make a sorted list of numbers and their neighbors, and verify the they are the same:
\begin{matrix} \text{Number} & \text{Neighbors} \\ 1 & 1,1 \\ 1 & 1,2,3 \\ 1 & 1,3,4 \\ 1 & 2,3,4 \\ 2 & 1,1 \\ 3 & 1,1,1,5 \\ 4 & 1,5,7 \\ 4 & 1,5,5 \\ 5 & 3,4,4,6 \\ 6 & 5,5,7 \\ 7 & 4,6 \end{matrix}
Here is another example.
\begin{matrix} 2 & 1 & 1\\ 1 & 3 & 1\\ 1 & 1 & 4\\ \end{matrix}
Let's make a neighbor list. Note that we are gonna have duplicate entries (which is fine)
\begin{matrix} \text{Number} & \text{Neighbors} \\ 1 & 1,1 \\ 1 & 1,1 \\ 1 & 1,2,3 \\ 1 & 1,2,3 \\ 1 & 1,3,4 \\ 1 & 1,3,4 \\ 2 & 1,1 \\ 3 & 1,1,1,1 \\ 4 & 1,1 \\ \end{matrix}
Now, can we swap the top left \$2\$ and the bottom left \$1\$? It may look fine at first glance, but we must be careful! By swapping those two elements we would create a \$1\$ which has neighbors \$2,3,4\$, which didn't exist in the first input.
Just to demonstrate, here is the matrix after this non-semi-continuous transformation:
\begin{matrix} 1 & 1 & 1\\ 1 & 3 & 1\\ 2 & 1 & 4\\ \end{matrix}
And here is the neighbor list:
\begin{matrix} \text{Number} & \text{Neighbors} \\ 1 & 1,1 \\ 1 & 1,1 \\ 1 & 1,1,3 \\ 1 & 1,2,3 \\ 1 & 1,3,4 \\ 1 & 2,3,4 \\ 2 & 1,1 \\ 3 & 1,1,1,1 \\ 4 & 1,1 \\ \end{matrix}
Which is has changed after the transformation, ergo the transformation is non-semi-continuous (on this input).
To clarify, semi-continuity is a property of a transformation on some specific matrix.
Your code will take a matrix as input and output the number of (unique) semi-continuous transformations. Two transformations are different if the output is different. So for example swapping two identical numbers is the same as the identity transform (doing nothing).
Or in other words: Your code will take a matrix and return the number of matrices with those dimensions that have the same neighbor-list.
You can assume that the matrix has positive width and height, and also that if m is the maximum number in the matrix, then the matrix contains all numbers 1 to m inclusive. Or alternatively you can assume that if m is the maximum number, then the matrix contains all numbers from 0 to m inclusive.
Examples
[[1]] -> 1
[[1, 1], [1, 1]] -> 1
[[2, 1], [1, 2]] -> 2
[[2, 2], [1, 2]] -> 4
[[2, 1, 1], [1, 2, 1], [1, 1, 2]] -> 2
[[1, 1, 2, 1, 1, 1, 1]] -> 3
[[1, 2, 3], [4, 5, 6], [7, 8, 9]] -> 8
[[1, 1, 4, 7], [1, 3, 5, 6], [2, 1, 4, 5]] -> 8
[[2, 1, 1], [1, 3, 1], [1, 1, 4]] -> 4