comparison Meerwald-dir/kim_common.c @ 24:9f20bce6184e v0.7

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

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