Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Rotate180.cs
1using System;
2
4{
8 public static partial class LinearTransformationOperations
9 {
15 public static Matrix<T> Rotate180<T>(this Matrix<T> M)
16 where T : struct
17 {
18 int w = M.Width;
19 int h = M.Height;
20 Matrix<T> Result = new(w, h);
21 T[] Src = M.Data;
22 int SrcIndex;
23 T[] Dest = Result.Data;
24 int DestIndex = 0;
25 int x, y;
26
27 for (y = 0; y < h; y++)
28 {
29 SrcIndex = M.StartIndex(w - 1, h - y - 1);
30 for (x = 0; x < w; x++)
31 Dest[DestIndex++] = Src[SrcIndex--];
32 }
33
34 return Result;
35 }
36
42 public static IMatrix Rotate180(this IMatrix M)
43 {
44 if (M is Matrix<float> M2)
45 return M2.Rotate180();
46 else if (M is Matrix<int> M3)
47 return M3.Rotate180();
48 else if (M is Matrix<uint> M4)
49 return M4.Rotate180();
50 else if (M is Matrix<byte> M5)
51 return M5.Rotate180();
52 else
53 throw new ArgumentException("Unsupported type: " + M.GetType().FullName, nameof(M));
54 }
55
56 }
57}
Implements a Matrix, basic component for computations in Image Processing and Computer Vision.
Definition: Matrix.cs:12
T[] Data
Underlying data on which the matrix is defined.
Definition: Matrix.cs:114
static IMatrix Rotate180(this IMatrix M)
Rotates the image 180 degrees to the right.
Definition: Rotate180.cs:42
static Matrix< T > Rotate180< T >(this Matrix< T > M)
Rotates the image 180 degrees to the right.
Definition: Rotate180.cs:15
Interface for matrices.
Definition: IMatrix.cs:9