annotate Meerwald/kim_common.c @ 22:d8551fb39a5e default tip

Added tag v0.6 for changeset 1c4ccd635a68
author Peter Meerwald-Stadler <pmeerw@pmeerw.net>
date Sat, 28 Jan 2023 23:57:51 +0100
parents be303a3f5ea8
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1 #include "wm.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2 #include "kim_common.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
3
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
4
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5 // find the largest absolute coefficient of a subband
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6 double find_subband_largest_coeff(Image_tree s, int subband, int verbose) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
7 int i, j;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8 double max;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 max = 0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 for (i = 5; i < s->image->height-5; i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 for (j = 5; j < s->image->width-5; j++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 double coeff;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 coeff = fabs(get_pixel(s->image, i, j));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 if (coeff > max)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 max = coeff;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 if (verbose > 8)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21 fprintf(stderr, " subband %f\n", max);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23 return max;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 // find largest absolute coefficient of the detail subbands (LH, HL, HH) of
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27 // a decomposition level
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 double find_level_largest_coeff(Image_tree p, int verbose) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 double h, v, d;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 h = find_subband_largest_coeff(p->horizontal, HORIZONTAL, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 v = find_subband_largest_coeff(p->vertical, VERTICAL, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 d = find_subband_largest_coeff(p->diagonal, DIAGONAL, verbose);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 return MAX(h, MAX(v, d));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 // calculate the significance threshold given the maximum absolute
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 // coefficient at a decomposition level
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 double calc_level_threshold(double max_coeff, int verbose) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 double threshold;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 threshold = pow(2.0, floor(log(max_coeff) / log(2.0)) - 1.0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 if (verbose > 7)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 fprintf(stderr, " max %f, threshold %f\n", max_coeff, threshold);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 return threshold;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 // calculate an appropriate embedding strength for a given decomposition level
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 // and a base alpha strength
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 double calc_level_alpha_detail(double alpha, int maxlevels, int level, int verbose) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 double level_alpha;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 level_alpha = alpha / pow(2.0, level - 1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 return level_alpha;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60

Repositories maintained by Peter Meerwald, pmeerw@pmeerw.net.