annotate Meerwald/dwt_util.c @ 1:647ab0f05aae v0.4

drop, not needed
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Tue, 14 Aug 2007 19:58:25 +0200
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 "dwt_util.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
3 #include <ctype.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
4
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5 void copy_coeffs_from_dwt(double ** block_coeffs, double ** dwt_coeffs,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6 int level, int band, int width, int height) {
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 int size = width >> level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9 int h = (band > 2) ? size : 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10 int w = (band & 1) ? 0 : size;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 for (i = 0; i < size; i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 for (j = 0; j < size; j++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14 block_coeffs[i][j] = dwt_coeffs[h + i][w + j];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 void copy_coeffs_to_dwt(double ** dwt_coeffs, double ** block_coeffs,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 int level, int band, int width, int height) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 int i, j;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 int size = width >> level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21 int h = (band > 2) ? size : 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 int w = (band & 1) ? 0 : size;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 for (i = 0; i < size; i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25 for (j = 0; j < size; j++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 dwt_coeffs[h + i][w + j] = block_coeffs[i][j];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 char *subband_name(int type) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 switch (type) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 case LL: return "LL";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32 case HL: return "HL";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 case LH: return "LH";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 case HH: return "HH";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 default: return "XX";
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
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 int subband_in_list(char *list, int type, int level) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 int subband_wp_in_list(char *list, char *name) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47 int calc_subband_wp_level(char *name){
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 return strlen(name);
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 void calc_subband_location(int cols, int rows, int type, int level, int *col, int *row) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 *col = *row = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54 if (level <= 0 || level > find_deepest_level(cols, rows) - 1) return;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 switch (type) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 case LL:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 case HL:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 *col = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 *row = rows >> level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63 case LH:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 *col = cols >> level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 *row = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 case HH:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 *col = cols >> level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 *row = rows >> level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71 default:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 void calc_subband_wp_location(int cols, int rows, char *name, int *col, int *row) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 char *p = name;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 int level = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 *col = *row = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 while (*p) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 level++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 switch (toupper(*p)) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 case 'A':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86 case 'H':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 *col += (cols >> level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 case 'V':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 *row += (rows >> level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 case 'D':
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93 *col += (cols >> level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 *row += (rows >> level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96 default:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 p++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 Pixel *get_dwt_data(Image_tree dwt, int level, int type) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 return get_dwt_image(dwt, level, type)->data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107 Image get_dwt_image(Image_tree dwt, int level, int type) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 return get_dwt_subband(dwt, level, type)->image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 Image_tree get_dwt_subband(Image_tree dwt, int level, int type) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 while (--level)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 dwt = dwt->coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 switch (type) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 case LL:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 return dwt->coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 case HL:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 return dwt->vertical;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120 case LH:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 return dwt->horizontal;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 case HH:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 return dwt->diagonal;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
126 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
127 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
128
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
129 Pixel get_dwt_coeff(Image_tree dwt, int level, int type, int coeff) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 return get_dwt_data(dwt, level, type)[coeff];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 Pixel get_dwt_location(Image_tree dwt, int level, int type, int col, int row) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 return get_pixel(get_dwt_image(dwt, level, type), col, row);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 static void calc__subband(Image_tree p, Image_tree q, double *min, double *max, double *error) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140 if (!p || !q) return;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 *error = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 *min = *max = fabs(p->image->data[0] - q->image->data[0]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 for (i = 0; i < p->image->size; i++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 double diff = fabs(p->image->data[i] - q->image->data[i]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147 *error += sqr(diff);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 if (diff < *min) *min = diff;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 if (diff > *max) *max = diff;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 void calc_subband(Image_tree p, Image_tree q, int type, double *min, double *max, double *error) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 calc__subband(p, q, min, max, error);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
155 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
156
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
157 void calc_subband_wp(Image_tree p, Image_tree q, char *name, double *min, double *max, double *error) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158 calc__subband(p, q, min, max, error);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159 }

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