-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefaultWeightFunc.java
More file actions
68 lines (58 loc) · 1.76 KB
/
defaultWeightFunc.java
File metadata and controls
68 lines (58 loc) · 1.76 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
/**
* This class represent a default weight function, which calculate the weight between two pixels
*/
public class defaultWeightFunc extends weightFunction
{
private float z;
private float epsilon;
/**
* Constructor
* @param z - power Coefficient of the euclidean distance between two pixels.
* @param eps - epsilon
*/
public defaultWeightFunc(float z, float eps) throws weightException {
if (z <= 0 || eps <= 0)
throw new weightException();
this.epsilon = eps;
this.z = z;
}
/**
* Calculate the weight between two pixels according to this formula (1/ ||u-v||^z + epsilon)
* @param pixel1 - the first pixel
* @param pixel2 - the second pixel
* @return the weight between two pixels
*/
public double calcWeight(Pixel pixel1, Pixel pixel2)
{
double dist = calcDistance(pixel1, pixel2);
double denominator = Math.pow(dist, this.z) + this.epsilon;
return (1/(denominator));
}
/**
* Getter for z
* @return z
*/
public float getZ() {
return this.z;
}
/**
* Getter for epsilon
* @return epsilon
*/
public float getEpsilon() {
return this.epsilon;
}
/**
* Calculate the euclidean distance between two pixels (||u-v||)
* @param pixel1 - the first pixel
* @param pixel2 - the second pixel
* @return the distance
*/
private double calcDistance(Pixel pixel1, Pixel pixel2)
{
// Substract the cooridnates of the pixels
double y_coor = Math.abs (pixel1.getCor_y() - pixel2.getCor_y());
double x_coor = Math.abs (pixel1.getCor_x() - pixel2.getCor_x());
return Math.sqrt(Math.pow(y_coor,2) + Math.pow(x_coor,2));
}
}