6
static void decimate(LIKELIHOOD ***, struct Region *, int, LIKELIHOOD ***,
8
static void up_ll(LIKELIHOOD *, int, double, LIKELIHOOD *);
11
void make_pyramid(LIKELIHOOD **** ll_pym, /* log likelihood pyramid, ll_pym[scale][i][j][class] */
12
struct Region *region, /* specifies image subregion */
13
int M, /* number of classes */
14
double *alpha /* decimation parameters */
19
struct Region region_buff;
21
/* save region stucture */
22
copy_reg(region, ®ion_buff);
25
reg_to_wdht(region, &wd, &ht);
26
while ((wd > 2) && (ht > 2)) {
27
G_debug(1, "D = %d alpha = %f; 1-alpha = %f", D, alpha[D],
29
decimate(ll_pym[D], region, M, ll_pym[D + 1], alpha[D]);
31
reg_to_wdht(region, &wd, &ht);
35
/* restore region structure */
36
copy_reg(®ion_buff, region);
40
/* decimate statistics ll1 to form ll2 */
41
LIKELIHOOD *** ll1, /* log likelihood ll1[i][j][class], at fine resolution */
42
struct Region *region1, /* specifies image subregion */
43
int M, /* number of classes */
44
LIKELIHOOD *** ll2, /* loglikelihood ll1[i][j][class], at coarse resolution */
45
double alpha /* transition parameter */
48
struct Region *region2, reg_spc; /* coarse resolution region */
49
int wflag, hflag; /* flags indicate odd number of pixels */
51
LIKELIHOOD *node; /* coarse resolution point */
52
LIKELIHOOD *pt1, *pt2, *pt3, *pt4; /* fine resolution neighbors */
56
copy_reg(region1, region2);
59
wflag = region1->xmax & 1;
60
hflag = region1->ymax & 1;
62
for (i = region2->ymin; i < region2->ymax; i++)
63
for (j = region2->xmin; j < region2->xmax; j++) {
64
pt1 = ll1[2 * i][2 * j];
65
pt2 = ll1[2 * i][2 * j + 1];
66
pt3 = ll1[2 * i + 1][2 * j];
67
pt4 = ll1[2 * i + 1][2 * j + 1];
70
for (m = 0; m < M; m++)
73
up_ll(pt1, M, alpha, node);
74
up_ll(pt2, M, alpha, node);
75
up_ll(pt3, M, alpha, node);
76
up_ll(pt4, M, alpha, node);
80
for (i = region2->ymin; i < region2->ymax; i++) {
81
node = ll2[i][region2->xmax - 1];
82
for (m = 0; m < M; m++)
85
pt1 = ll1[2 * i][region1->xmax - 1];
86
pt2 = ll1[2 * i + 1][region1->xmax - 1];
87
up_ll(pt1, M, alpha, node);
88
up_ll(pt2, M, alpha, node);
93
for (j = region2->xmin; j < region2->xmax; j++) {
94
node = ll2[region2->ymax - 1][j];
95
for (m = 0; m < M; m++)
98
pt1 = ll1[region1->ymax - 1][2 * j];
99
pt2 = ll1[region1->ymax - 1][2 * j + 1];
100
up_ll(pt1, M, alpha, node);
101
up_ll(pt2, M, alpha, node);
105
if (hflag && wflag) {
106
node = ll2[region2->ymax - 1][region2->xmax - 1];
107
for (m = 0; m < M; m++)
110
pt1 = ll1[region1->ymax - 1][region1->xmax - 1];
111
up_ll(pt1, M, alpha, node);
116
static void up_ll(LIKELIHOOD * pt1, /* array of log likelihood values, pt1[class] */
117
int M, double alpha, LIKELIHOOD * pt2 /* array of log likelihood values, pt2[class] */
121
static double sum, max, cprob[256];
125
for (m = 1; m < M; m++)
130
for (m = 0; m < M; m++) {
131
cprob[m] = exp(pt1[m] - max);
135
sum = ((1 - alpha) * sum) / M;
137
for (m = 0; m < M; m++)
138
pt2[m] += log(sum + alpha * cprob[m]) + max;
141
for (m = 0; m < M; m++)
146
char ***get_pyramid(int w0, int h0, size_t size)
152
pym = (char ***)G_malloc((D + 1) * sizeof(char *));
157
pym[D] = (char **)get_img(wn, hn, size);
158
while ((wn > 2) && (hn > 2)) {
162
pym[D] = (char **)get_img(wn, hn, size);
169
void free_pyramid(char *pym, int wd, int ht)
174
pt = (unsigned char ***)pym;
176
for (i = 0; i <= D; i++)
181
char ****get_cubic_pyramid(int w0, int h0, int M, size_t size)
187
pym = (char ****)G_malloc((D + 1) * sizeof(char *));
192
pym[D] = (char ***)multialloc(size, 3, hn, wn, M);
193
while ((wn > 2) && (hn > 2)) {
197
pym[D] = (char ***)multialloc(size, 3, hn, wn, M);
204
void free_cubic_pyramid(char *pym, int wd, int ht, int M)
211
for (i = 0; i <= D; i++)
216
int levels(int wd, int ht)
221
while ((wd > 2) && (ht > 2)) {