Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Threshold.cs
2{
6 public static partial class TransformationOperations
7 {
16 public static void Threshold(this Matrix<float> M, float Threshold)
17 {
18 if (Threshold < 0)
19 M.Threshold(float.MinValue, -Threshold);
20 else
21 M.Threshold(Threshold, float.MaxValue);
22 }
23
34 public static void Threshold(this Matrix<float> M, float Min, float Max)
35 {
36 int y, h = M.Height;
37 int x, w = M.Width;
38 int Index = M.Start;
39 int Skip = M.Skip;
40 float[] Data = M.Data;
41 float v;
42
43 if (Min <= Max)
44 {
45 for (y = 0; y < h; y++, Index += Skip)
46 {
47 for (x = 0; x < w; x++)
48 {
49 v = Data[Index];
50 Data[Index++] = v >= Min && v <= Max ? 1 : 0;
51 }
52 }
53 }
54 else
55 {
56 for (y = 0; y < h; y++, Index += Skip)
57 {
58 for (x = 0; x < w; x++)
59 {
60 v = Data[Index];
61 Data[Index++] = v >= Min || v <= Max ? 1 : 0;
62 }
63 }
64 }
65 }
66
75 public static void Threshold(this Matrix<int> M, int Threshold)
76 {
77 if (Threshold < 0)
78 M.Threshold(int.MinValue, -Threshold);
79 else
80 M.Threshold(Threshold, int.MaxValue);
81 }
82
93 public static void Threshold(this Matrix<int> M, int Min, int Max)
94 {
95 int y, h = M.Height;
96 int x, w = M.Width;
97 int Index = M.Start;
98 int Skip = M.Skip;
99 int[] Data = M.Data;
100 int v;
101
102 if (Min <= Max)
103 {
104 for (y = 0; y < h; y++, Index += Skip)
105 {
106 for (x = 0; x < w; x++)
107 {
108 v = Data[Index];
109 Data[Index++] = v >= Min && v <= Max ? 0x01000000 : 0;
110 }
111 }
112 }
113 else
114 {
115 for (y = 0; y < h; y++, Index += Skip)
116 {
117 for (x = 0; x < w; x++)
118 {
119 v = Data[Index];
120 Data[Index++] = v >= Min || v <= Max ? 0x01000000 : 0;
121 }
122 }
123 }
124 }
125
126 }
127}
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
static void Threshold(this Matrix< int > M, int Threshold)
Creates a black and white image based on the threshold level provided in Threshold ....
Definition: Threshold.cs:75
static void Threshold(this Matrix< float > M, float Threshold)
Creates a black and white image based on the threshold level provided in Threshold ....
Definition: Threshold.cs:16
static void Threshold(this Matrix< int > M, int Min, int Max)
Creates a black and white image based on the threshold levels provided in Min and Max ....
Definition: Threshold.cs:93
static void Threshold(this Matrix< float > M, float Min, float Max)
Creates a black and white image based on the threshold levels provided in Min and Max ....
Definition: Threshold.cs:34