Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
GrayScaleFixed.cs
1using System;
2
4{
8 public static partial class ColorModelOperations
9 {
17 {
18 int y, h = M.Height;
19 int x, w = M.Width;
20 int SrcOffset = M.Start;
21 int DestOffset = 0;
22 int SrcSkip = M.Skip;
23 uint[] Src = M.Data;
24 int[] Dest = new int[w * h];
25 uint ui;
26 int f;
27
28 for (y = 0; y < h; y++, SrcOffset += SrcSkip)
29 {
30 for (x = 0; x < w; x++)
31 {
32 ui = Src[SrcOffset++];
33
34 f = 19672 * (int)(ui & 255);
35 ui >>= 8;
36 f += 38620 * (int)(ui & 255);
37 ui >>= 8;
38 f += 7500 * (int)(ui & 255);
39
40 Dest[DestOffset++] = f;
41 }
42 }
43
44 return new Matrix<int>(w, h, Dest);
45 }
46
54 {
55 int y, h = M.Height;
56 int x, w = M.Width;
57 int SrcOffset = M.Start;
58 int DestOffset = 0;
59 int SrcSkip = M.Skip;
60 byte[] Src = M.Data;
61 int[] Dest = new int[w * h];
62
63 for (y = 0; y < h; y++, SrcOffset += SrcSkip)
64 {
65 for (x = 0; x < w; x++)
66 Dest[DestOffset++] = 65793 * Src[SrcOffset++];
67 }
68
69 return new Matrix<int>(w, h, Dest);
70 }
71
79 {
80 int y, h = M.Height;
81 int x, w = M.Width;
82 int SrcOffset = M.Start;
83 int DestOffset = 0;
84 int SrcSkip = M.Skip;
85 float[] Src = M.Data;
86 int[] Dest = new int[w * h];
87
88 for (y = 0; y < h; y++, SrcOffset += SrcSkip)
89 {
90 for (x = 0; x < w; x++)
91 Dest[DestOffset++] = (int)(0x01000000 * Src[SrcOffset++] + 0.5);
92 }
93
94 return new Matrix<int>(w, h, Dest);
95 }
96
104 {
105 return M;
106 }
107
114 public static IMatrix GrayScaleFixed(this IMatrix M)
115 {
116 if (M is Matrix<uint> M2)
117 return GrayScaleFixed(M2);
118 else if (M is Matrix<byte> M3)
119 return GrayScaleFixed(M3);
120 else if (M is Matrix<float> M4)
121 return GrayScaleFixed(M4);
122 else if (M is Matrix<int> M5)
123 return GrayScaleFixed(M5);
124 else
125 throw new ArgumentException("Unsupported type: " + M.GetType().FullName, nameof(M));
126 }
127 }
128}
static Matrix< int > GrayScaleFixed(this Matrix< byte > M)
Creates a matrix of grayscale values. Floating point scales are used to avoid round-off errors and lo...
static Matrix< int > GrayScaleFixed(this Matrix< float > M)
Creates a matrix of grayscale values. Floating point scales are used to avoid round-off errors and lo...
static Matrix< int > GrayScaleFixed(this Matrix< int > M)
Creates a matrix of grayscale values. Floating point scales are used to avoid round-off errors and lo...
static Matrix< int > GrayScaleFixed(this Matrix< uint > M)
Creates a matrix of grayscale values. Floating point scales are used to avoid round-off errors and lo...
static IMatrix GrayScaleFixed(this IMatrix M)
Creates a matrix of grayscale values. Floating point scales are used to avoid round-off errors and lo...
Implements a Matrix, basic component for computations in Image Processing and Computer Vision.
Definition: Matrix.cs:12
int Height
Height of matrix (number of rows)
Definition: Matrix.cs:136
T[] Data
Underlying data on which the matrix is defined.
Definition: Matrix.cs:114
int Width
Width of matrix (number of columns)
Definition: Matrix.cs:120
int Skip
Number of elements to skip from the right edge in the underlying data to the left edge of the new row...
Definition: Matrix.cs:233
int Start
Start offset of matrix in underlying data.
Definition: Matrix.cs:228
Interface for matrices.
Definition: IMatrix.cs:9