Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
Cap.cs
1using System;
2
4{
8 public static partial class ArithmeticsOperations
9 {
16 public static void Cap(this Matrix<float> M, float Min, float Max)
17 {
18 if (Max < Min)
19 throw new ArgumentOutOfRangeException(nameof(Max));
20
21 int y, h = M.Height;
22 int x, w = M.Width;
23 int Index = M.Start;
24 int Skip = M.Skip;
25 float[] Data = M.Data;
26 float v;
27
28 for (y = 0; y < h; y++, Index += Skip)
29 {
30 for (x = 0; x < w; x++)
31 {
32 v = Data[Index];
33 if (v < Min)
34 Data[Index] = Min;
35 else if (v > Max)
36 Data[Index] = Max;
37
38 Index++;
39 }
40 }
41 }
42
49 public static void Cap(this Matrix<int> M, int Min, int Max)
50 {
51 if (Max < Min)
52 throw new ArgumentOutOfRangeException(nameof(Max));
53
54 int y, h = M.Height;
55 int x, w = M.Width;
56 int Index = M.Start;
57 int Skip = M.Skip;
58 int[] Data = M.Data;
59 int v;
60
61 for (y = 0; y < h; y++, Index += Skip)
62 {
63 for (x = 0; x < w; x++)
64 {
65 v = Data[Index];
66 if (v < Min)
67 Data[Index] = Min;
68 else if (v > Max)
69 Data[Index] = Max;
70
71 Index++;
72 }
73 }
74 }
75 }
76}
static void Cap(this Matrix< int > M, int Min, int Max)
Caps the smallest and largest values in a matrix.
Definition: Cap.cs:49
static void Cap(this Matrix< float > M, float Min, float Max)
Caps the smallest and largest values in a matrix.
Definition: Cap.cs:16
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