Neuron®
The Neuron® is the basis for the creation of open and secure federated networks for smart societies.
Loading...
Searching...
No Matches
AbsoluteDifference.cs
1using System;
2
4{
8 public static partial class ArithmeticsOperations
9 {
16 {
17 int y, h = M.Height;
18 if (h != Matrix.Height)
19 throw new ArgumentOutOfRangeException(nameof(Matrix), "Heights to do not match.");
20
21 int x, w = M.Width;
22 if (w != Matrix.Width)
23 throw new ArgumentOutOfRangeException(nameof(Matrix), "Widths to do not match.");
24
25 int DestOffset = M.Start;
26 int SrcOffset = Matrix.Start;
27 int DestSkip = M.Skip;
28 int SrcSkip = Matrix.Skip;
29 float[] Dest = M.Data;
30 float[] Src = Matrix.Data;
31 float v;
32
33 for (y = 0; y < h; y++, DestOffset += DestSkip, SrcOffset += SrcSkip)
34 {
35 for (x = 0; x < w; x++)
36 {
37 v = Dest[DestOffset] - Src[SrcOffset++];
38 Dest[DestOffset++] = v < 0 ? -v : v;
39 }
40 }
41 }
42
49 {
50 int y, h = M.Height;
51 if (h != Matrix.Height)
52 throw new ArgumentOutOfRangeException(nameof(Matrix), "Heights to do not match.");
53
54 int x, w = M.Width;
55 if (w != Matrix.Width)
56 throw new ArgumentOutOfRangeException(nameof(Matrix), "Widths to do not match.");
57
58 int DestOffset = M.Start;
59 int SrcOffset = Matrix.Start;
60 int DestSkip = M.Skip;
61 int SrcSkip = Matrix.Skip;
62 int[] Dest = M.Data;
63 int[] Src = Matrix.Data;
64 int v;
65
66 for (y = 0; y < h; y++, DestOffset += DestSkip, SrcOffset += SrcSkip)
67 {
68 for (x = 0; x < w; x++)
69 {
70 v = Dest[DestOffset] - Src[SrcOffset++];
71 Dest[DestOffset++] = v < 0 ? -v : v;
72 }
73 }
74 }
75 }
76}
static void AbsoluteDifference(this Matrix< int > M, Matrix< int > Matrix)
Computes the absolute difference of two matrices.
static void AbsoluteDifference(this Matrix< float > M, Matrix< float > Matrix)
Computes the absolute difference of two matrices.
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