-
Notifications
You must be signed in to change notification settings - Fork 0
/
pmed.cpp
64 lines (63 loc) · 1.2 KB
/
pmed.cpp
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
#include <math.h>
#include "pmed.h"
#include "logging.h"
#define PMED_PROB 2
int PMed::predict(int x, int y, PDistrib *pd, double priority, int rad)
{
Image *img = yuvimage->getPlane(plane);
if (!img || x<0 || x>=img->getWidth() || y<0 || y>=img->getHeight())
return -1;
int v;
float val = 0;
float n = 0;
int min = 255, max = 0;
if (x > 0) {
v = img->get(x-1, y);
val += v;
n++;
if (v < min)
min = v;
if (v > max)
max = v;
}
if (x > 0 && y > 0) {
v = img->get(x-1, y-1);
val += v/sqrt(2);
n += 1/sqrt(2);
if (v < min)
min = v;
if (v > max)
max = v;
}
if (y > 0) {
v = img->get(x, y-1);
val += v;
n++;
if (v < min)
min = v;
if (v > max)
max = v;
}
if (x < img->getWidth()-1 && y > 0) {
v = img->get(x+1, y-1);
n += 1/sqrt(2);
val += v/sqrt(2);
if (v < min)
min = v;
if (v > max)
max = v;
}
if (n < 0.1)
return -1;
val /= n;
int radius = rad;
/* if (max >= min)
radius += (max - min)/2;
*/ if (2*radius > val)
radius = val/2;
if (2*radius > img->getMaxValue() - val)
radius = (img->getMaxValue() - val)/2;
// if (n>0)
pd->addSpikeEllipse(val, 2*radius, PMED_PROB*priority);
return val;
}