Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
ScalarLinearTransform.cs
2{
6 public static partial class ArithmeticsOperations
7 {
14 public static void ScalarLinearTransform(this Matrix<float> M, float Scale, float Offset)
15 {
16 int y, h = M.Height;
17 int x, w = M.Width;
18 int Index = M.Start;
19 int Skip = M.Skip;
20 float[] Data = M.Data;
21 float v;
22
23 for (y = 0; y < h; y++, Index += Skip)
24 {
25 for (x = 0; x < w; x++)
26 {
27 v = Data[Index];
28 Data[Index++] = v * Scale + Offset;
29 }
30 }
31 }
32
40 public static void ScalarLinearTransform(this Matrix<float> M, float PreOffset, float Scale, float PostOffset)
41 {
42 M.ScalarLinearTransform(Scale, PreOffset * Scale + PostOffset);
43 }
44
52 public static void ScalarLinearTransform(this Matrix<int> M, int ScaleNumerator,
53 int ScaleDenominator, int Offset)
54 {
55 int y, h = M.Height;
56 int x, w = M.Width;
57 int Index = M.Start;
58 int Skip = M.Skip;
59 int[] Data = M.Data;
60 int sd2 = ScaleDenominator >> 1;
61 int v;
62
63 for (y = 0; y < h; y++, Index += Skip)
64 {
65 for (x = 0; x < w; x++)
66 {
67 v = Data[Index];
68 Data[Index++] = (int)((((long)v) * ScaleNumerator + sd2) / ScaleDenominator) + Offset;
69 }
70 }
71 }
72
81 public static void ScalarLinearTransform(this Matrix<int> M, int PreOffset,
82 int ScaleNumerator, int ScaleDenominator, int PostOffset)
83 {
84 PostOffset = (int)((((long)PreOffset) * ScaleNumerator + (PostOffset >> 1)) / ScaleDenominator) + PostOffset;
85 M.ScalarLinearTransform(ScaleNumerator, ScaleDenominator, PostOffset);
86 }
87 }
88}
static void ScalarLinearTransform(this Matrix< float > M, float Scale, float Offset)
Performs a scalar linear transform (x*Scale+Offset) on each element in the matrix.
static void ScalarLinearTransform(this Matrix< int > M, int ScaleNumerator, int ScaleDenominator, int Offset)
Performs a scalar linear transform (x*Scale+Offset) on each element in the matrix.
static void ScalarLinearTransform(this Matrix< float > M, float PreOffset, float Scale, float PostOffset)
Performs a scalar linear transform ((x+PreOffset)*Scale+PostOffset) on each element in the matrix.
static void ScalarLinearTransform(this Matrix< int > M, int PreOffset, int ScaleNumerator, int ScaleDenominator, int PostOffset)
Performs a scalar linear transform ((x+PreOffset)*Scale+PostOffset) on each element in the matrix.
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