-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMath Functions.cs
More file actions
102 lines (88 loc) · 2.68 KB
/
Math Functions.cs
File metadata and controls
102 lines (88 loc) · 2.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Drawing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ImageProcessingWF
{
class MathF
{
public static int LinearInterpolation(Point a, Point b, int x)
{
int y = (a.Y + (x - a.X) * (b.Y - a.Y) / (b.X - a.X));
return y;
}
public static int NewSize(int length, double factor)
{
int lengthout = (int)factor * length;
return lengthout;
}
public static int CheckRange(int value) // check if value falls within intensity range
{
if (value < 0)
value = 0;
if (value > 255)
value = 255;
return value;
}
public static int Distance(int n1, int n2)
{
int result = (int)Math.Sqrt((n1 * n1) + (n2 * n2));
return result;
}
public static int GetMax(Bitmap bmp)
{
int max = bmp.GetPixel(0, 0).R;
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
max = bmp.GetPixel(x, y).R > max ? bmp.GetPixel(x, y).R : max;
}
}
return max;
}
public static int GetMin(Bitmap bmp)
{
int min = bmp.GetPixel(0, 0).R;
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
min = bmp.GetPixel(x, y).R < min ? bmp.GetPixel(x, y).R : min;
}
}
return min;
}
public static double GetAvg(Bitmap bmp)
{
double avg;
double value = 0.0;
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
value += bmp.GetPixel(x, y).R;
}
}
avg = value / (bmp.Height * bmp.Width);
return avg;
}
public static double GetSdv(Bitmap bmp)
{
double avg = GetAvg(bmp);
double value = 0.0;
double sdv;
for (int x = 0; x < bmp.Width; x++)
{
for (int y = 0; y < bmp.Height; y++)
{
value += Math.Sqrt(Math.Pow((bmp.GetPixel(x, y).R - avg), 2));
}
}
sdv = Math.Sqrt(value / (bmp.Height * bmp.Width));
return sdv;
}
}
}