I have an image that is stored in a DenseMatrix
, using MathNet Numerics
.
For rotating the image by 90 degrees counter-clockwise I want to get the transpose and then flip the result vertically by multiplying by the anti-diagonal identity matrix.
Is there a quick way to initialize that identity matrix?
For a 2x2 matrix that would look like:
0 1
1 0
Update:
I ended up doing pretty much what @Joseph suggested. Turns out to be sufficiently fast.
public static Matrix<double> CreateAntiIdentityMatrix(int n)
{
var output = Matrix<double>.Build.Dense(n, n, 0);
for (int i = 0; i <= n - 1; i++)
{
output[i, n - i - 1] = 1;
}
return output;
}