comparison Meerwald-dir/cmp_dugad_sig.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/cmp_dugad_sig.c@f83ef905a63d
children
comparison
equal deleted inserted replaced
23:71dd4b96221b 24:9f20bce6184e
1 #include "wm.h"
2
3 char *progname;
4
5 void usage(void) {
6 fprintf(stderr, "usage: %s [-h] [-s file] [-C] [-o file] [-v] file\n\n", progname);
7 fprintf(stderr, "\t-C\t\toutput correlation only\n");
8 fprintf(stderr, "\t-h\t\tprint usage\n");
9 fprintf(stderr, "\t-o file\t\toutput file\n");
10 fprintf(stderr, "\t-s file\t\tignored\n");
11 exit(0);
12 }
13
14 int main(int argc, char *argv[]) {
15
16 FILE *in = stdin;
17 FILE *out = stdout;
18
19 char output_name[MAXPATHLEN] = "(stdout)";
20 char input_name[MAXPATHLEN] = "(stdin)";
21
22 int c, i, n, ok;
23 int levels;
24 double alpha;
25 double diff;
26 char line[32];
27
28 int correlation_only = 0;
29 int verbose = 0;
30
31 progname = argv[0];
32
33 while ((c = getopt(argc, argv, "h?Co:v:s:")) != EOF) {
34 switch (c) {
35 case 'h':
36 case '?':
37 usage();
38 break;
39 case 'C':
40 correlation_only = 1;
41 break;
42 case 's':
43 break;
44 case 'o':
45 if ((out = fopen(optarg, "w")) == NULL) {
46 fprintf(stderr, "%s: unable to open output file %s\n", progname, optarg);
47 exit(1);
48 }
49 strcpy(output_name, optarg);
50 break;
51 case 'v':
52 verbose = atoi(optarg);
53 if (verbose < 0) {
54 fprintf(stderr, "%s: verbosity level %d out of range\n", progname, verbose);
55 exit(1);
56 }
57 break;
58 }
59 }
60
61 argc -= optind;
62 argv += optind;
63
64 if (argc > 1) {
65 usage();
66 exit(1);
67 }
68
69 if (argc == 1 && *argv[0] != '-') {
70 if ((in = fopen(argv[0], "r")) == NULL) {
71 fprintf(stderr, "%s: unable to open input file %s\n", progname, argv[0]);
72 exit(1);
73 }
74 else
75 strcpy(input_name, argv[0]);
76 }
77
78 fgets(line, sizeof(line), in);
79 if (strspn(line, "DGWM") < 4) {
80 fprintf(stderr, "%s: watermark file %s invalid\n", progname, input_name);
81 exit(1);
82 }
83
84 fscanf(in, "%d\n", &levels);
85 fscanf(in, "%lf\n", &alpha);
86
87 n = 3 * levels;
88 ok = 0;
89 diff = 0.0;
90 for (i = 0; i < levels; i++) {
91 int m;
92 double z, v;
93
94 // HL subband
95 fscanf(in, "%d %lf %lf\n", &m, &z, &v);
96 if (verbose && !correlation_only) {
97 if (m)
98 fprintf(out, "%f %f\n", z / (double) m, (v * alpha) / (double) (1.0 * m));
99 else
100 fprintf(out, "0.0 0.0\n");
101 }
102 if (m) {
103 ok += (z > v * alpha / (double) 1.0) ? 1 : 0;
104 diff += ((z - v * alpha) / (double) (1.0 * m));
105 }
106 else
107 n--;
108
109 // LH subband
110 fscanf(in, "%d %lf %lf\n", &m, &z, &v);
111 if (verbose && !correlation_only) {
112 if (m)
113 fprintf(out, "%f %f\n", z / (double) m, (v * alpha) / (double) (1.0 * m));
114 else
115 fprintf(out, "0.0 0.0\n");
116 }
117 if (m) {
118 ok += (z > v * alpha / (double) 1.0) ? 1 : 0;
119 diff += ((z - v * alpha) / (double) (1.0 * m));
120 }
121 else
122 n--;
123
124 // HH subband
125 fscanf(in, "%d %lf %lf\n", &m, &z, &v);
126 if (verbose && !correlation_only) {
127 if (m)
128 fprintf(out, "%f %f\n", z / (double) m, (v * alpha) / (double) (1.0 * m));
129 else
130 fprintf(out, "0.0 0.0\n");
131 }
132
133 if (m) {
134 ok += (z > v * alpha / (double) 1.0) ? 1 : 0;
135 diff += ((z - v * alpha) / (double) (1.0 * m));
136 }
137 else
138 n--;
139 }
140
141 if (!correlation_only)
142 fprintf(out, "%d/%d, diff %f\n", ok, n, diff);
143 fprintf(out, "%f\n", (double) ok / (double) n);
144
145 fclose(out);
146 fclose(in);
147
148 exit(0);
149 }

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