annotate Meerwald/wavelet.c @ 5:8191b855cd5e

Added tag v0.5 for changeset 9cf6ec970448
author Peter Meerwald <pmeerw@cosy.sbg.ac.at>
date Tue, 14 Aug 2007 21:13:29 +0200
parents be303a3f5ea8
children f83ef905a63d
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 <stdio.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2 #include <stdlib.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
3 #include <string.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
4 #include <math.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
5 #include "wavelet.h"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
6 #include <ctype.h>
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
7
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
8 static int read_char(FILE *fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
9 static int read_int(FILE *fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
10
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
11 IntImage new_intimage(int width, int height)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
12 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
13 IntImage image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
14
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
15 image = (IntImage) calloc(1,sizeof(struct IntImage_struct));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
16 if (image==NULL) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
17 image->data = (IntPixel*) calloc(width*height,sizeof(IntPixel));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
18 if (image->data==NULL) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
19 image->width = width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
20 image->height = height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
21 image->size = width*height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
22 image->bpp = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
23 image->min_val = (IntPixel) 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
24 image->max_val = (IntPixel) 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
25
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
26 return image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
27
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
28 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
29 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
30 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
31 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
32
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
33 Image new_image(int width, int height)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
34 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
35 Image image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
36
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
37 image = (Image) calloc(1,sizeof(struct Image_struct));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
38 if (image==NULL) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
39 image->data = (Pixel*) calloc(width*height,sizeof(Pixel));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
40 if (image->data==NULL) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
41 image->width = width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
42 image->height = height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
43 image->size = width*height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
44 image->bpp = 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
45 image->min_val = (Pixel) 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
46 image->max_val = (Pixel) 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
47
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
48 return image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
49
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
50 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
51 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
52 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
53 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
54
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
55
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
56 void free_intimage(IntImage img)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
57 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
58 if (img) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
59 if (img->data) free(img->data);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
60 free(img);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
61 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
62 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
63
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
64 void free_image(Image img)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
65 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
66 if (img) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
67 if (img->data) free(img->data);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
68 free(img);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
69 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
70 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
71
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
72 /************************************************************************
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
73 * Functionname: load_intimage
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
74 * --------------------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
75 * PARAMETER:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
76 * file: filename of image
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
77 * max_val: scaling of grey values to [0..max_val]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
78 *
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
79 * RETURN:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
80 * Image that shoud be loaded, if not possible return NULL
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
81 * --------------------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
82 * DESCRIPTION:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
83 * This function loads an IntImage (PGM, ASCII or binary
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
84 * encoded (P5 or P3 format) ) from a file.
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
85 ************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
86
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
87 IntImage load_intimage(char *file, int max_val)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
88 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
89 IntImage img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
90 FILE *fp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
91 IntPixel *data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
92 int width, height, i, max, ch1, ch2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
93
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
94 fp=fopen(file,"rb");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
95 if (fp==NULL) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
96
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
97 ch1=getc(fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
98 ch2=getc(fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
99 if (ch1!='P' || (ch2!='5' && ch2!='2')) goto error1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
100
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
101 width=read_int(fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
102 height=read_int(fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
103 if ((width==0) || (height==0) ) goto error1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
104 max=read_int(fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
105
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
106 img=new_intimage(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
107
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
108 img->bpp=8;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
109
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
110 data=img->data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
111 for (i=0; i<img->size; i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
112 { if (ch2=='5')
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
113 *data=getc(fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
114 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
115 *data=read_int(fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
116 data++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
117 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
118 fclose(fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
119 return img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
120
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
121 error1:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
122 err_SimpleMessage(err_GetErrorMessage(Error_WrongFileFormat));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
123 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
124 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
125 err_SimpleMessage(err_GetErrorMessage(Error_CantOpenFile));
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 /************************************************************************
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
130 * Functionname: load_image
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
131 * --------------------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
132 * PARAMETER:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
133 * file: filename of image
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
134 * max_val: scaling of grey values to [0..max_val]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
135 *
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
136 * RETURN:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
137 * Image that shoud be loaded, if not possible return NULL
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
138 * --------------------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
139 * DESCRIPTION:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
140 * This function loads an IntImage with load_intimage
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
141 * and then converts to Image.
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
142 ************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
143 extern Image load_image(char *file, int max_val)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
144 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
145 Image img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
146 IntImage intimg;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
147
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
148 intimg = load_intimage(file, max_val);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
149 if (!intimg) return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
150 img = intimage_to_image(intimg);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
151 if (!intimg) return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
152
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
153 return img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
154 }
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 /* Functionname: save_image_P5 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
158 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
159 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
160 /* img: Image that shoud be saved */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
161 /* file: filename of image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
162 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
163 /* Description: save an image as PGM (P5 binary decoded) file */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
164 /* */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
165 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
166
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
167 extern int save_image_P5(char *file, Image img)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
168 { FILE *fp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
169 Pixel *data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
170 long i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
171 int p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
172
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
173 fp=fopen(file,"wb");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
174 if (fp==NULL)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
175 goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
176 fprintf(fp,"P5\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
177 fprintf(fp,"%d %d\n%d ",img->width,img->height,255);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
178 data=img->data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
179 for (i=0;i<img->size;i++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
180 p=floor(*data+0.5);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
181 if (p<0) p=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
182 if (p>255) p=255;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
183 /* putc(*data,fp); */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
184 putc(p,fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
185 data++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
186 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
187 fclose(fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
188 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
189
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
190 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
191 err_SimpleMessage(err_GetErrorMessage(Error_CantOpenFile));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
192 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
193 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
194
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
195 void clear_image(Image img)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
196 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
197 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
198
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
199 PreCondition(img!=NULL,"image==NULL");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
200
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
201 for (i=0;i<img->size;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
202 (img->data)[i]=(Pixel) 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
203 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
204
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
205 extern void copy_into_image(Image img1,Image img2,int x,int y)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
206 /* copy img2 into img1 at position (x,y)*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
207 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
208 int start,i,j,aim;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
209 Pixel *temp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
210
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
211 temp=img2->data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
212 start=img1->width*y+x;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
213 for (i=0;i<img2->height;i++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
214 for (j=0;j<img2->width;j++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
215 aim=start+j+img1->width*i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
216 img1->data[aim]=*temp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
217 temp++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
218 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
219 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
220 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
221
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
222 extern void copy_into_intimage(IntImage img1,IntImage img2,int x,int y)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
223 {/* copy img2 into img1 at position (x,y)*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
224
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
225 int start,i,j,aim;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
226 IntPixel *temp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
227
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
228 temp=img2->data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
229 start=img1->width*y+x;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
230 for (i=0;i<img2->height;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
231 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
232 for (j=0;j<img2->width;j++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
233 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
234 aim=start+j+img1->width*i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
235 img1->data[aim]=*temp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
236 temp++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
237 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
238 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
239 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
240
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
241 void copy_part_of_image_into_image(Image dest_img, int dest_x, int dest_y,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
242 Image src_img, int src_x, int src_y,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
243 int width, int height)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
244 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
245 Pixel *sp,*dp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
246 int y,siz;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
247
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
248 sp=get_pixel_adr(src_img,src_x,src_y);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
249 dp=get_pixel_adr(dest_img,dest_x,dest_y);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
250
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
251 siz=width*sizeof(Pixel);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
252
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
253 for (y=0;y<height;y++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
254 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
255 memcpy(dp,sp,siz);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
256 sp+=src_img->width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
257 dp+=dest_img->width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
258 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
259 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
260
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
261 extern void copy_part_of_image(Image img1,Image img2,int x,int y)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
262 /* copy part of img2 begining at position (x,y) into img1 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
263 { int i,j,width,height,start,step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
264 Pixel *data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
265
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
266 width=img1->width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
267 height=img1->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
268 start=img2->width*y+x;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
269 data=img1->data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
270 for (i=0;i<height;i++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
271 step=i*img2->width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
272 for (j=0;j<width;j++){
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
273 *data=img2->data[start+j+step];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
274 data++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
275 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
276 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
277 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
278
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
279
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
280 extern void scale_image(Image img,int maximum)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
281 /* scale image to [0..maximum]*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
282 { int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
283 Pixel max,min,multi;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
284
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
285 for (i=0;i<img->size;i++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
286 if (img->data[i]<min) min=img->data[i];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
287 else if (img->data[i]>max) max=img->data[i];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
288 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
289
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
290 multi=(Pixel)maximum/(max-min);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
291 for (i=0;i<img->size;i++) img->data[i]=multi*(img->data[i]-min);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
292 img->min_val=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
293 img->max_val=maximum;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
294 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
295
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
296 int string_to_pixel(char *str, Pixel *p)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
297 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
298 float ppp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
299 if (sscanf(str,"%f",&ppp)==1)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
300 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
301 *p=(Pixel) ppp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
302 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
303 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
304 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
305 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
306 *p=0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
307 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
308 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
309 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
310
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
311 Image intimage_to_image(IntImage i)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
312 { Image img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
313 int j;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
314
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
315 img=new_image(i->width,i->height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
316 if (img==NULL) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
317 for (j=0;j<i->size;j++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
318 img->data[j]=(Pixel)i->data[j];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
319 img->bpp=i->bpp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
320 return img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
321
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
322 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
323 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
324 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
325 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
326 IntImage image_to_intimage(Image i)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
327 { IntImage img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
328 int j,multi=1,max,min;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
329
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
330 img=(IntImage)calloc(1,sizeof(struct IntImage_struct));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
331 if (img==NULL) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
332 img->data=(IntPixel *)calloc(i->size,sizeof(IntPixel));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
333 if (img->data==NULL) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
334 img->width=i->width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
335 img->height=i->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
336 img->size=i->size;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
337 img->bpp=i->bpp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
338
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
339 max=i->max_val;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
340 min=i->min_val;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
341 if ((max-min)!=0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
342 multi=255.0/(max-min);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
343
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
344 for (j=0;j<img->size;j++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
345 img->data[j]=(int)((i->data[j]-min)*multi+0.5);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
346 return img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
347
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
348 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
349 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
350 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
351
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
352 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
353
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
354 static int read_char(FILE *fp)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
355 /*read a character from file, but skip any comments*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
356 { int ch;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
357
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
358 ch=getc(fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
359 if (ch=='#'){
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
360 do {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
361 ch=getc(fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
362 } while (ch!='\n' && ch!=EOF);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
363 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
364 return ch;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
365 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
366
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
367
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
368 static int read_int(FILE *fp)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
369 /*read an ascii integer from file, and skip leading tabstops,new lines ...*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
370 { int r,ch;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
371
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
372 do {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
373 ch=read_char(fp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
374 } while (ch==' ' || ch=='\n' || ch=='\t');
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
375
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
376 if (ch<'0' || ch>'9')
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
377 goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
378
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
379 r=ch-'0';
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
380 while ( (ch=read_char(fp)) >='0' && (ch <= '9') ) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
381 r*=10;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
382 r+=ch-'0';
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
383 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
384 return r;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
385 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
386 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
387 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
388
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
389 Image_tree new_image_tree()
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
390 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
391 Image_tree t;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
392 t=(Image_tree) calloc(1,sizeof(struct Image_tree_struct));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
393 t->entropy=0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
394 t->image=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
395 t->coarse=t->horizontal=t->vertical=t->diagonal=t->doubletree=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
396 t->level=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
397 t->codec_data=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
398 t->significance_map=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
399 return t;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
400 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
401
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
402 void free_image_tree(Image_tree t)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
403 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
404 if (t->coarse) free_image_tree(t->coarse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
405 if (t->horizontal) free_image_tree(t->horizontal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
406 if (t->vertical) free_image_tree(t->vertical);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
407 if (t->diagonal) free_image_tree(t->diagonal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
408 if (t->doubletree) free_image_tree(t->doubletree);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
409 if (t->image) free_image(t->image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
410 if (t->significance_map) free_intimage(t->significance_map);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
411 if (t->codec_data) free(t->codec_data);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
412 t->image=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
413 free(t);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
414 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
415
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
416 /***********************************************************************
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
417 * Functionname: get_image_infos
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
418 * --------------------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
419 * Parameter:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
420 * Image image: input image
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
421 * Pixel *min,*max,*avg,*var: return minimum, maximum,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
422 * average and variance of current image
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
423 * --------------------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
424 * Description:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
425 * get statistical information of Image
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
426 ************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
427
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
428 void get_image_infos(Image image, Image_info info)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
429 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
430 int x,y;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
431 Pixel p,sp,sp2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
432
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
433 sp=sp2=(Pixel)0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
434
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
435 p=get_pixel(image,0,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
436
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
437 info->min=info->max=p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
438
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
439 for (y=0;y<image->height;y++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
440 for (x=0;x<image->width;x++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
441 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
442 p=get_pixel(image,x,y);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
443 info->max=MAX(info->max,p);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
444 info->min=MIN(info->min,p);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
445 sp+=p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
446 sp2+=p*p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
447 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
448 sp=sp/image->width/image->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
449 sp2=sp2/image->width/image->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
450
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
451 info->mean=sp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
452 info->var=sp2-sp*sp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
453 info->rms=sqrt(sp2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
454 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
455
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
456 /***********************************************************************
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
457 * Functionname: get_difference_image
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
458 * --------------------------------------------------------------------
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
459 * Parameter:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
460 * Image image1, image 2: input images
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
461 *
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
462 * Return:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
463 * Image : difference of image1 and image 2,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
464 * NULL if error occurs
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
465 ************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
466
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
467 Image get_difference_image(Image image1, Image image2)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
468 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
469 Image diff;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
470 int i,max,w,h;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
471 Pixel *d,*i1,*i2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
472
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
473 if ((!image1) || (!image2)) return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
474
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
475 w=image1->width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
476 h=image1->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
477
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
478 if (image2->width != w || image2->height != h) return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
479
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
480 diff=new_image(w,h);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
481 max=w*h;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
482
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
483 d=diff->data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
484 i1=image1->data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
485 i2=image2->data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
486
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
487 for (i=0;i<max;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
488 d[i]=i2[i]-i1[i];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
489
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
490 return diff;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
491 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
492
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
493
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
494 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
495 /* Functionname: get_intimage_infos */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
496 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
497 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
498 /* IntImage image: input image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
499 /* IntPixel *min,*max, return minimum, maximum */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
500 /* Pixel *avg,*var: average and variance of current image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
501 /* average and variance of current image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
502 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
503 /* Description: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
504 /* get statistical information of Image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
505 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
506
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
507 void get_intimage_infos(IntImage image, IntPixel *min, IntPixel *max, Pixel *avg, Pixel *var)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
508 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
509 int x,y;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
510 Pixel p,sp,sp2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
511
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
512 sp=sp2=(Pixel)0.0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
513
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
514 p= (Pixel) get_intpixel(image,0,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
515 *min=*max=p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
516
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
517 for (y=0;y<image->height;y++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
518 for (x=0;x<image->width;x++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
519 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
520 p= (Pixel) get_intpixel(image,x,y);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
521 *max=MAX(*max, (IntPixel) p);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
522 *min=MIN(*min, (IntPixel) p);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
523 sp+=p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
524 sp2+=p*p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
525 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
526 sp=sp/image->width/image->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
527 sp2=sp2/image->width/image->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
528
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
529 *avg=sp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
530 *var=sp2-sp*sp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
531 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
532
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
533 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
534 /* Functionname: init_zigzag */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
535 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
536 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
537 /* Zigzag_data_struct: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
538 /* output: will be initialized, x/y hold coordinates of */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
539 /* the first pixel */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
540 /* int width,height: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
541 /* input: width/height of image: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
542 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
543 /* Description: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
544 /* initializes Zigzag_data structure for use with next_zigzag */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
545 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
546
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
547 void init_zigzag(Zigzag_data zz, int width, int height)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
548 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
549 zz->x=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
550 zz->y=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
551 zz->dir=zigzag_up;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
552 zz->w=width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
553 zz->h=height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
554 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
555
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
556 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
557 /* Functionname: next_zigzag */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
558 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
559 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
560 /* Zigzag_data_struct: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
561 /* int x,y: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
562 /* input: current position of zigzag-scan */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
563 /* output: next position of zigzag-scan */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
564 /* int w,h: width and height of image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
565 /* enum zigzag_direction *dir: i/o: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
566 /* direction moving thru the image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
567 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
568 /* Description: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
569 /* calculates the next point (x',y') of the zigzag-scan */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
570 /* through the image with size (w,h) */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
571 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
572
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
573
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
574 void next_zigzag(Zigzag_data zz)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
575 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
576 switch(zz->dir)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
577 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
578 case zigzag_up:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
579 if (zz->y==0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
580 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
581 if (zz->x==zz->w-1)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
582 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
583 (zz->y)++; zz->dir=zigzag_down;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
584 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
585 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
586 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
587 (zz->x)++; zz->dir=zigzag_down;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
588 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
589 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
590 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
591 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
592 if (zz->x==zz->w-1)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
593 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
594 (zz->y)++; zz->dir=zigzag_down;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
595 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
596 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
597 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
598 (zz->x)++; (zz->y)--;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
599 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
600 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
601 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
602
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
603 case zigzag_down:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
604
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
605 if (zz->x==0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
606 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
607 if (zz->y==zz->h-1)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
608 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
609 (zz->x)++; zz->dir=zigzag_up;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
610 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
611 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
612 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
613 (zz->y)++; zz->dir=zigzag_up;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
614 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
615 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
616 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
617 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
618 if (zz->y==zz->h-1)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
619 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
620 (zz->x)++; zz->dir=zigzag_up;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
621 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
622 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
623 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
624 (zz->x)--;(zz->y)++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
625 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
626 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
627 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
628 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
629 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
630
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
631 Image get_absolute_image_scaled(Image img)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
632 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
633 Image out;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
634
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
635 int x,y;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
636
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
637 struct Image_info_struct info;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
638 Pixel scale,p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
639
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
640 out=new_image(img->width,img->height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
641
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
642 get_image_infos(img, &info);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
643
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
644 scale=255/MAX(fabs(info.min),fabs(info.max));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
645
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
646 for(y=0;y<img->height;y++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
647 for(x=0;x<img->width;x++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
648 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
649 p=get_pixel(img,x,y)*scale;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
650 set_pixel(out,x,y,p);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
651 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
652 return out;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
653 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
654
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
655 #define FLOOR_HALF(x) ((x)&1 ? ((x)-1)/2 : (x)/2)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
656 #define CEILING_HALF(x) ((x)&1 ? ((x)+1)/2 : (x)/2)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
657
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
658 #define MOD(a,b) ( (a)<0 ? ((b)-((-(a))%(b))) : (a)%(b) )
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
659
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
660 Filter new_filter(int size)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
661 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
662 Filter f;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
663
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
664 Entering;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
665 f=(Filter) calloc(1,sizeof(struct FilterStruct));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
666 f->data=(Pixel *)calloc(size,sizeof(Pixel));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
667 f->len=size;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
668 f->hipass=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
669
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
670 Leaving;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
671 return f;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
672 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
673
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
674 Pixel get_filter_center(Filter f)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
675 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
676 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
677 Pixel p, sum, norm;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
678
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
679 if (f==NULL) return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
680
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
681 sum=norm=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
682
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
683 for (i=0;i<f->len;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
684 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
685 p=f->data[i];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
686 p=p*p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
687 norm += p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
688 sum += (i+f->start)*p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
689 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
690 p=sum/norm;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
691
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
692 return p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
693 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
694 int filter_cutoff(Image in, int in_start, int in_len, int in_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
695 Image out, int out_start, int out_len, int out_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
696 Filter f)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
697 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
698 int i,i2,j;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
699 Pixel *out_pix, *in_pix, *f_data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
700 int fstart,fend; /* Source interval */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
701
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
702 Entering;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
703
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
704 PreCondition(out_len == in_len/2,"out_len != in_len/2 !!!");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
705
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
706 /* convolution: out[i]=sum_{j=start}^{end} (in[2*i-j]*f[j])
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
707
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
708 boundaries: image in [in_start ... in_start + in_len-1]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
709 image out [out_start ... out_start + out_len-1]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
710 filter f [0..f->len-1] = [f->start .. f->end]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
711 cutoff at:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
712 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
713
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
714 for (i=0;i<out_len;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
715 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
716 i2=2*i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
717
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
718 fstart=i2-(in_len-1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
719 fstart=MAX(fstart,f->start);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
720 fend=MIN(i2,f->end);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
721
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
722 #ifdef TRACE
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
723 sprintf(dbgstr,"i=%d fstart=%d fend=%d\n",i,fstart,fend);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
724 Trace(dbgstr);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
725 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
726
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
727 out_pix=out->data+out_start+i*out_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
728
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
729 in_pix=in->data+in_start+(i2-fstart)*in_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
730
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
731 f_data=f->data-f->start+fstart;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
732
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
733 for (j=fstart;j<=fend;j++,in_pix-=in_step,f_data++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
734 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
735 *out_pix += (*f_data) * (*in_pix);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
736 #ifdef TRACE
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
737
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
738 sprintf(dbgstr," j=%2d in: %4.2f filter: %4.2f [%4d] [%4d] opt : %4.2f %4.2f\n",
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
739 j,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
740 in->data[in_start+in_step*(i2-j)],
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
741 f->data[j-f->start],
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
742 in_start+in_step*(i2-j),
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
743 j-f->start,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
744 *in_pix, *f_data);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
745 Trace(dbgstr);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
746 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
747 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
748 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
749
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
750 Leaving;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
751 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
752 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
753
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
754
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
755 int filter_inv_cutoff(Image in, int in_start, int in_len, int in_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
756 Image out, int out_start, int out_len, int out_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
757 Filter f)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
758 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
759 int i,j;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
760 Pixel *out_pix, *in_pix, *f_data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
761 int fstart,fend; /* Source interval */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
762 Entering;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
763 PreCondition(out_len == in_len*2,"out_len != in_len*2 !!!");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
764
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
765 /* convolution: out[i]=sum_{j=start}^{end} (f[2*j-i]*in[j])
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
766
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
767 boundaries: image in [in_start ... in_start + in_len-1]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
768 image out [out_start ... out_start + out_len-1]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
769 filter f [0..f->len-1] = [f->start .. f->end]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
770 cutoff at:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
771 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
772
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
773 for (i=0;i<out_len;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
774 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
775 fstart=CEILING_HALF(f->start+i);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
776 fend=FLOOR_HALF(f->end+i);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
777 fstart=MAX(fstart,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
778 fend=MIN(fend,in_len-1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
779
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
780 #ifdef TRACE
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
781 sprintf(dbgstr,"i=%d fstart=%d fend=%d\n",i,fstart,fend);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
782 Trace(dbgstr);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
783 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
784 out_pix=out->data+out_start+i*out_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
785
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
786 in_pix=in->data+in_start+fstart*in_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
787
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
788 f_data=f->data-f->start+2*fstart-i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
789
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
790 for (j=fstart;j<=fend;j++,in_pix+=in_step,f_data+=2)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
791 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
792 *out_pix += (*f_data) * (*in_pix);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
793 #ifdef TRACE
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
794 sprintf(dbgstr," j=%2d in: %4.2f filter: %4.2f [%4d] [%4d] opt : %4.2f %4.2f\n",
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
795 j,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
796 in->data[in_start+j*in_step],
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
797 f->data[2*j-i-f->start],
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
798 in_start+j*in_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
799 2*j-i-f->start,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
800 *in_pix, *f_data);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
801 Trace(dbgstr);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
802 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
803 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
804 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
805
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
806 Leaving;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
807 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
808 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
809
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
810 int filter_periodical(Image in, int in_start, int in_len, int in_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
811 Image out, int out_start, int out_len, int out_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
812 Filter f)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
813 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
814 int i,i2,j;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
815 Pixel *out_pix, *in_pix, *f_data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
816 int fstart,fend;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
817 int istart;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
818 int ipix_len;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
819
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
820 Entering;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
821 PreCondition(out_len == in_len/2,"out_len != in_len/2 !!!");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
822
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
823 /* convolution: out[i]=sum_{j=start}^{end} (in[2*i-j]*f[j])
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
824
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
825 boundaries: image in [in_start ... in_start + in_len-1]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
826 image out [out_start ... out_start + out_len-1]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
827 filter f [0..f->len-1] = [f->start .. f->end]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
828 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
829
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
830 ipix_len=in_len*in_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
831
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
832 for (i=0;i<out_len;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
833 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
834 i2=2*i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
835
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
836 fstart=f->start;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
837 fend=f->end;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
838
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
839 istart=(i2-fstart);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
840 istart=MOD(istart,in_len);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
841
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
842 #ifdef TRACE
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
843 sprintf(dbgstr,"i=%d istart=%d\n",i,istart);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
844 Trace(dbgstr);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
845 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
846
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
847 out_pix=out->data+out_start+i*out_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
848
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
849 in_pix=in->data+in_start+istart*in_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
850
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
851 f_data=f->data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
852
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
853 for (j=fstart;j<=fend;j++,f_data++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
854 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
855 *out_pix += (*f_data) * (*in_pix);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
856 #ifdef TRACE
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
857
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
858 sprintf(dbgstr," j=%2d in: %4.2f filter: %4.2f [%4d] [%4d] opt : %4.2f %4.2f\n",
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
859 j,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
860 in->data[in_start+in_step*((i2-j+in_len)%in_len)],
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
861 f->data[j-f->start],
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
862 in_start+in_step*((i2-j+in_len)%in_len),
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
863 j-f->start,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
864 *in_pix, *f_data);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
865 Trace(dbgstr);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
866 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
867 in_pix-=in_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
868 istart--;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
869 if (istart<0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
870 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
871 istart+=in_len;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
872 in_pix+=ipix_len;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
873 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
874 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
875 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
876
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
877 Leaving;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
878 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
879 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
880
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
881 int filter_inv_periodical(Image in, int in_start, int in_len, int in_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
882 Image out, int out_start, int out_len, int out_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
883 Filter f)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
884 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
885 int i,j;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
886 Pixel *out_pix, *in_pix, *f_data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
887 int fstart,fend; /* Source interval */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
888 int istart;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
889 int ipix_len;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
890 Entering;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
891 PreCondition(out_len == in_len*2,"out_len != in_len*2 !!!");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
892
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
893 /* convolution: out[i]=sum_{j=start}^{end} (f[2*j-i]*in[j])
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
894
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
895 boundaries: image in [in_start ... in_start + in_len-1]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
896 image out [out_start ... out_start + out_len-1]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
897 filter f [0..f->len-1] = [f->start .. f->end]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
898 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
899
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
900 ipix_len=in_len*in_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
901
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
902 for (i=0;i<out_len;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
903 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
904 fstart=CEILING_HALF(f->start+i);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
905 fend=FLOOR_HALF(f->end+i);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
906
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
907 istart=MOD(fstart,in_len);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
908 #ifdef TRACE
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
909 sprintf(dbgstr,"i=%d fstart=%d fend=%d istart=%d\n",i,fstart,fend,istart);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
910 Trace(dbgstr);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
911 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
912 out_pix=out->data+out_start+i*out_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
913
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
914 in_pix=in->data+in_start+istart*in_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
915
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
916 f_data=f->data-f->start+2*fstart-i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
917
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
918 for (j=fstart;j<=fend;j++,f_data+=2)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
919 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
920 *out_pix += (*f_data) * (*in_pix);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
921 #ifdef TRACE
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
922 sprintf(dbgstr," j=%2d in: %4.2f filter: %4.2f [%4d] [%4d] opt : %4.2f %4.2f\n",
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
923 j,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
924 in->data[in_start+(j % in_len)*in_step],
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
925 f->data[2*j-i-f->start],
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
926 in_start+(j%in_len)*in_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
927 2*j-i-f->start,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
928 *in_pix, *f_data);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
929 Trace(dbgstr);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
930 #endif
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
931 in_pix+=in_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
932 istart++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
933 if (istart>=in_len)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
934 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
935 istart-=in_len;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
936 in_pix-=ipix_len;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
937 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
938 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
939 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
940
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
941 Leaving;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
942 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
943 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
944
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
945 int filter_mirror(Image in, int in_start, int in_len, int in_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
946 Image out, int out_start, int out_len, int out_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
947 Filter f)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
948 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
949 int i,i2,j;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
950 Pixel *out_pix, *in_pix, *f_data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
951 int fstart,fend;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
952 int in_pos;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
953
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
954 int in_dir,in_div,in_mod;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
955
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
956 Entering;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
957 PreCondition(out_len == in_len/2,"out_len != in_len/2 !!!");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
958
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
959 /* convolution: out[i]=sum_{j=start}^{end} (in[2*i-j]*f[j])
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
960
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
961 boundaries: image in [in_start ... in_start + in_len-1]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
962 image out [out_start ... out_start + out_len-1]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
963 filter f [0..f->len-1] = [f->start .. f->end]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
964 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
965
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
966 in_pix=in->data+in_start;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
967
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
968 for (i=0;i<out_len;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
969 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
970 i2=2*i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
971
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
972 fstart=f->start;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
973 fend=f->end;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
974
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
975 out_pix=out->data+out_start+i*out_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
976
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
977 f_data=f->data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
978
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
979 for (j=fstart;j<=fend;j++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
980 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
981 in_pos=(i2-j);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
982 if (in_pos<0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
983 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
984 in_pos=-in_pos;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
985 if (in_pos>=in_len) continue;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
986 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
987 if (in_pos>=in_len)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
988 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
989 in_pos=2*in_len-2-in_pos;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
990 if (in_pos<0) continue;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
991 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
992 *out_pix += (f_data[j-fstart]) * (in_pix[in_pos*in_step]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
993 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
994 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
995
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
996 Leaving;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
997 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
998 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
999
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1000 int filter_inv_mirror(Image in, int in_start, int in_len, int in_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1001 Image out, int out_start, int out_len, int out_step,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1002 Filter f)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1003 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1004 int i,j;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1005 Pixel *out_pix, *in_pix, *f_data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1006 int fstart,fend; /* Source interval */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1007 int in_pos,in_dir,in_div,in_mod;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1008
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1009 Entering;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1010 PreCondition(out_len == in_len*2,"out_len != in_len*2 !!!");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1011
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1012 /* convolution: out[i]=sum_{j=start}^{end} (f[2*j-i]*in[j])
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1013
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1014 boundaries: image in [in_start ... in_start + in_len-1]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1015 image out [out_start ... out_start + out_len-1]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1016 filter f [0..f->len-1] = [f->start .. f->end]
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1017 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1018
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1019 /*fprintf(stderr,"inv started\n");*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1020 for (i=0;i<out_len;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1021 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1022 fstart=CEILING_HALF(f->start+i);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1023 fend=FLOOR_HALF(f->end+i);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1024
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1025 out_pix=out->data+out_start+i*out_step;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1026
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1027 in_pix=in->data+in_start;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1028
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1029 /*
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1030 printf("in: %4d - %4d flt: %4d - %4d [%s]\n",fstart,fend,2*fstart-i,2*fend-i,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1031 (2*fstart-i<f->start || 2*fend-i>f->end) ? "error":"ok");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1032 */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1033 /*fprintf(stderr,"inv[%d]\n",i);*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1034 for (j=fstart;j<=fend;j++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1035 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1036 in_pos=j;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1037 if (in_pos<0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1038 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1039 if (f->hipass)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1040 in_pos=-in_pos-1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1041 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1042 in_pos=-in_pos;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1043 if (in_pos>=in_len) continue;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1044 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1045 if (in_pos>=in_len)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1046 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1047 if (f->hipass)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1048 in_pos=2*in_len-2-in_pos;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1049 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1050 in_pos=2*in_len-1-in_pos;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1051 if (in_pos<0) continue;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1052 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1053 /*fprintf(stderr,"out+= %7.2f * %7.2f = %7.2f\n",f->data[2*j-i-f->start],in_pix[in_pos*in_step],f->data[2*j-i-f->start]*in_pix[in_pos*in_step]);*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1054 *out_pix += f->data[2*j-i-f->start] * (in_pix[in_pos*in_step]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1055 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1056 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1057
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1058 Leaving;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1059 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1060 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1061
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1062 #define MAX_LINE 256
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1063
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1064 #define skip_blank(str) { while(isspace(*(str))) (str)++; }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1065
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1066 static int get_next_line(FILE *f, char *c)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1067 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1068 char *str,string[200];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1069 int len;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1070 do
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1071 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1072 str=string;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1073 if (!fgets(str,200,f))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1074 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1075 Trace("get_next_line: eof\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1076 goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1077 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1078 len=strlen(str);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1079 while (len>=1 && isspace(str[len-1])) str[--len]=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1080 while (isspace(*str)) str++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1081 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1082 while (strlen(str)==0 || *str=='#');
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1083 strcpy(c,str);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1084 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1085 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1086 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1087 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1088
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1089 static int next_line_str(FILE *f, char *tag, char *out)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1090 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1091 char str[MAX_LINE],*t_str;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1092
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1093 if (!get_next_line(f,str)) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1094 t_str=strtok(str," ");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1095 if (!t_str || strcmp(t_str,tag)) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1096 t_str=strtok(NULL,"\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1097 if (!t_str) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1098 skip_blank(t_str);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1099
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1100 strcpy(out,t_str);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1101 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1102 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1103 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1104 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1105
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1106 static int next_line_str_alloc(FILE *f, char *tag, char **out)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1107 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1108 char str[MAX_LINE];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1109 if (!next_line_str(f,tag,str)) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1110
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1111 *out=malloc(strlen(str)+1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1112 strcpy(*out,str);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1113
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1114 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1115 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1116 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1117 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1118
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1119 static int next_line_int(FILE *f, char *tag, int *out)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1120 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1121 char str[MAX_LINE];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1122 if (next_line_str(f,tag,str) && sscanf(str,"%d",out)==1)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1123 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1124 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1125 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1126 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1127
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1128
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1129 static Filter read_filter(FILE *f)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1130 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1131 char str[MAX_LINE];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1132 Filter filter;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1133 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1134
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1135 Entering;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1136
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1137 filter=calloc(1,sizeof(struct FilterStruct));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1138
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1139 if (!next_line_str(f,"Type",str)) goto error1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1140
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1141 if (!strcmp(str,"nosymm"))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1142 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1143 filter->type=FTNoSymm;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1144 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1145 else if (!strcmp(str,"symm"))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1146 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1147 filter->type=FTSymm;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1148 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1149 else if (!strcmp(str,"antisymm"))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1150 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1151 filter->type=FTAntiSymm;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1152 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1153 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1154 goto error1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1155
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1156 if (!next_line_int(f,"Length",&(filter->len))) goto error1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1157 if (!next_line_int(f,"Start",&(filter->start))) goto error1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1158 if (!next_line_int(f,"End",&(filter->end))) goto error1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1159
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1160 if ((filter->end-filter->start+1!=filter->len))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1161 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1162 Trace("error: len != end-start+1\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1163 goto error1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1164 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1165
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1166 filter->data=calloc(filter->len,sizeof(Pixel));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1167
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1168 for (i=0;i<filter->len;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1169 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1170 if (!get_next_line(f,str)) goto error2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1171 if (!string_to_pixel(str,filter->data+i))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1172 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1173 Trace("error: invalid filter-value\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1174 goto error2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1175 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1176 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1177 if (!get_next_line(f,str)) goto error2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1178 if (*str!='}')
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1179 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1180 Trace("error: '}' not found\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1181 goto error2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1182 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1183
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1184 Leaving;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1185 return filter;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1186
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1187 error2:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1188 free(filter->data);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1189
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1190 error1:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1191 free(filter);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1192
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1193 LeavingErr;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1194 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1195
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1196 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1197
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1198 static FilterGH read_filter_gh(FILE *f)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1199 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1200 char str[MAX_LINE];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1201 FilterGH fgh;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1202 Filter filter;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1203 int i,max;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1204
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1205 Entering;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1206
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1207 fgh=calloc(1,sizeof(struct FilterGHStruct));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1208
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1209 if (!next_line_str_alloc(f,"Name",&(fgh->name)))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1210 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1211 Trace("error: 'Name' tag not found\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1212 goto error1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1213 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1214
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1215 if (!next_line_str(f,"Type",str))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1216 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1217 Trace("error: 'Type' tag not found\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1218 goto error1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1219 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1220
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1221 if (!strcmp(str,"orthogonal"))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1222 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1223 fgh->type=FTOrtho;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1224 max=2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1225 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1226 else if (!strcmp(str,"biorthogonal"))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1227 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1228 fgh->type=FTBiOrtho;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1229 max=4;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1230 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1231 else if (!strcmp(str,"other"))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1232 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1233 fgh->type=FTOther;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1234 max=4;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1235 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1236 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1237 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1238 Trace("error: expecting 'orthogonal', 'biorthogonal' or 'other' type-tag\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1239 goto error1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1240 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1241
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1242 for (i=0;i<max;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1243 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1244 if (!get_next_line(f,str)) goto error2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1245 if (*str!='{')
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1246 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1247 Trace("error: '{' not found\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1248 goto error2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1249 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1250 if (!(filter=read_filter(f)))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1251 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1252 Trace("error: read_filter failed\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1253 goto error2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1254 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1255 filter->hipass = !(i&1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1256 switch(i)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1257 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1258 case 0: fgh->g=filter; break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1259 case 1: fgh->h=filter; break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1260 case 2: fgh->gi=filter; break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1261 case 3: fgh->hi=filter; break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1262 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1263 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1264 if (!get_next_line(f,str)) goto error2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1265 if (*str!='}')
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1266 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1267 Trace("error: '}' not found\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1268 goto error2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1269 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1270
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1271 Leaving;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1272 return fgh;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1273
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1274 error2:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1275 if (fgh->g) free(fgh->g);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1276 if (fgh->h) free(fgh->h);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1277 if (fgh->gi) free(fgh->gi);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1278 if (fgh->hi) free(fgh->hi);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1279
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1280 error1:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1281 free(fgh);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1282
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1283 LeavingErr;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1284 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1285 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1286
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1287
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1288 AllFilters load_filters(char *name)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1289 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1290 FILE *f;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1291 char str[MAX_LINE];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1292 AllFilters a;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1293 FilterGH fgh;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1294
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1295 Entering;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1296
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1297 PreCondition(name!=NULL,"name=NULL!");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1298
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1299 f=fopen(name,"rt");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1300 if (!f)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1301 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1302 Trace("error: fopen failed\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1303 goto error1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1304 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1305
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1306 a=calloc(1,sizeof(struct AllFilterStruct));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1307 a->count=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1308
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1309 while (get_next_line(f,str))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1310 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1311 if (*str=='{')
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1312 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1313 fgh=read_filter_gh(f);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1314 if (!fgh)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1315 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1316 Trace("error: read_filter returned NULL\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1317 goto error2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1318 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1319 if (a->count)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1320 a->filter=realloc(a->filter,(a->count+1)*sizeof(FilterGH));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1321 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1322 a->filter=malloc(sizeof(FilterGH));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1323 (a->filter)[a->count]=fgh;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1324 a->count++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1325 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1326 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1327 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1328 Trace("error: '{' not found\n");
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1329 goto error2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1330 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1331 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1332
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1333 fclose(f);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1334
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1335 Leaving;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1336 return a;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1337
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1338 error2:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1339 fclose(f);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1340 error1:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1341
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1342 LeavingErr;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1343 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1344 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1345
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1346 #define doubletree_min 32
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1347 #define best_basis_min 8
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1348
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1349 static int convolute_lines(Image output,Image input,Filter flt,enum FilterMethod method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1350 static int convolute_rows(Image output,Image input,Filter flt,enum FilterMethod method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1351 static int decomposition(Image t_img,Image coarse,Image horizontal,Image vertical,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1352 Image diagonal,Filter g,Filter h,enum FilterMethod method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1353 static int compute_best(Image_tree tree,int level,int max_level,FilterGH *flt,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1354 enum FilterMethod method,enum Information_Cost cost,double epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1355 static double compute_entropy(Image img,enum Information_Cost cost,double epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1356 static compute_levels(Image_tree tree,double *entropies,enum Information_Cost cost,double epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1357 static free_levels(Image_tree tree,int best);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1358
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1359 static Pixel sumationq(Image img);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1360 static Pixel normq(Image_tree tree);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1361 static Pixel sumation_down(Image_tree tree, Pixel normq);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1362 static Pixel compute_non_additive(Image_tree tree,int size,enum Information_Cost cost,double
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1363 epsilon,int down);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1364
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1365 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1366 /* Functionname: wavelettransform */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1367 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1368 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1369 /* original: Image that should be transformed */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1370 /* level: transform down to level */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1371 /* flt: transform with filters flt[0..level] */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1372 /* method: method of filtering */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1373 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1374 /* Description: Carries out the wavelettransform */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1375 /* */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1376 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1377 extern Image_tree wavelettransform(Image original,int level,FilterGH *flt,enum FilterMethod method)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1378 { int i,width,height,min,max_level,e;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1379 Image coarsei,horizontali,verticali,diagonali,tempi;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1380 Image_tree ret_tree,temp_tree;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1381
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1382 width=original->width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1383 height=original->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1384
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1385 tempi=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1386 if(!tempi) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1387
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1388 copy_into_image(tempi,original,0,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1389
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1390 ret_tree=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1391 if(!ret_tree) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1392
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1393 temp_tree=ret_tree;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1394 ret_tree->level=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1395
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1396 min=original->width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1397 if (original->height<min) min=original->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1398 max_level=log(min)/log(2)-2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1399 if (max_level<level) level=max_level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1400
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1401 if (level<1) /* do not transform */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1402 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1403 ret_tree->image=tempi;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1404 return ret_tree;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1405 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1406
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1407 /* decomposition */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1408
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1409 for (i=0;i<level;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1410 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1411
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1412 width=(width+1)/2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1413 height=(height+1)/2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1414
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1415 coarsei=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1416 horizontali=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1417 verticali=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1418 diagonali=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1419 if(!coarsei||!horizontali||!verticali||!diagonali) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1420
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1421 e=decomposition(tempi,coarsei,horizontali,verticali,diagonali,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1422 flt[i]->g,flt[i]->h,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1423 if (!e) return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1424
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1425 temp_tree->coarse=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1426 temp_tree->horizontal=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1427 temp_tree->vertical=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1428 temp_tree->diagonal=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1429
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1430 temp_tree->coarse->level=i+1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1431 temp_tree->horizontal->level=i+1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1432 temp_tree->vertical->level=i+1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1433 temp_tree->diagonal->level=i+1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1434
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1435 temp_tree->horizontal->image=horizontali;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1436 temp_tree->vertical->image=verticali;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1437 temp_tree->diagonal->image=diagonali;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1438 free_image(tempi);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1439
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1440 if (i!=(level-1))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1441 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1442 tempi=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1443 copy_into_image(tempi,coarsei,0,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1444 free_image(coarsei);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1445 /*if i=level coarsei is inserted into the image tree
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1446 so we should not free coarsei on level-1*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1447 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1448
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1449 temp_tree=temp_tree->coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1450
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1451 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1452
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1453 temp_tree->image=coarsei;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1454 return ret_tree;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1455
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1456 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1457 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1458 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1459 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1460
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1461 static Image_tree wavelettransform__wp(Image original, int current_level, int level, FilterGH *flt, enum FilterMethod method)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1462 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1463 int i, width, height, min, max_level, e;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1464 Image coarse_image,horizontal_image,vertical_image,diagonal_image,temp_image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1465 Image_tree return_tree, temp_tree;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1466
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1467 width = original->width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1468 height = original->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1469
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1470 temp_image = new_image(width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1471 if (!temp_image) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1472
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1473 copy_into_image(temp_image, original, 0, 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1474
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1475 temp_tree = return_tree = new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1476 if (!return_tree) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1477
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1478 temp_tree->level = current_level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1479
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1480 min = original->width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1481 if (original->height < min) min = original->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1482 max_level = log(min) / log(2) - 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1483 if (max_level < level) level = max_level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1484
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1485 if (current_level >= level) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1486 return_tree->image = temp_image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1487 return return_tree;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1488 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1489
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1490 for (i = current_level; i < level; i++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1491 width = (width + 1) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1492 height = (height + 1) / 2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1493
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1494 coarse_image = new_image(width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1495 horizontal_image = new_image(width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1496 vertical_image = new_image(width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1497 diagonal_image = new_image(width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1498
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1499 if (!coarse_image || !horizontal_image ||
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1500 !vertical_image || !diagonal_image) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1501
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1502 e = decomposition(temp_image, coarse_image, horizontal_image,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1503 vertical_image, diagonal_image,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1504 flt[i]->g, flt[i]->h, method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1505 if (!e) return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1506
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1507 temp_tree->coarse = new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1508 temp_tree->coarse->level = i+1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1509 temp_tree->horizontal = wavelettransform__wp(horizontal_image, i+1, level, flt, method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1510 temp_tree->vertical = wavelettransform__wp(vertical_image, i+1, level, flt, method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1511 temp_tree->diagonal = wavelettransform__wp(diagonal_image, i+1, level, flt, method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1512
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1513 free_image(horizontal_image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1514 free_image(vertical_image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1515 free_image(diagonal_image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1516 free_image(temp_image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1517
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1518 if (i != (level - 1)) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1519 temp_image = new_image(width, height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1520 copy_into_image(temp_image, coarse_image, 0, 0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1521 free_image(coarse_image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1522 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1523
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1524 temp_tree = temp_tree->coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1525 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1526
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1527 temp_tree->image = coarse_image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1528 return return_tree;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1529
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1530 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1531 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1532 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1533 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1534
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1535 extern Image_tree wavelettransform_wp(Image original, int level, FilterGH *flt, enum FilterMethod method) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1536 wavelettransform__wp(original, 0, level, flt, method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1537 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1538
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1539
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1540 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1541 /* Functionname: best_basis */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1542 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1543 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1544 /* original: Image to be transformed */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1545 /* level: best basis selection down to this level */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1546 /* flt: transform with filters flt[0..level] */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1547 /* method: transform with filter method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1548 /* cost: carry best basis selection out with this costfunc */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1549 /* epsilon: limit for threshold method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1550 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1551 /* Description: carries best basis and near best basis selection */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1552 /* out */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1553 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1554 extern Image_tree best_basis(Image original,int level,FilterGH *flt,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1555 enum FilterMethod method,enum Information_Cost cost,double epsilon)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1556
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1557 { Image_tree tree;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1558 Image img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1559 int min,max_level,e;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1560
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1561 tree=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1562 if(!tree) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1563
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1564 img=new_image(original->width,original->height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1565 if(!img) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1566
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1567 copy_into_image(img,original,0,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1568
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1569 tree->image=img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1570
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1571 min=original->width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1572 if (original->height<min) min=original->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1573 max_level=log10((float) min/best_basis_min)/log10(2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1574 if (max_level>level) max_level=level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1575
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1576 e=compute_best(tree,0,max_level,flt,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1577
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1578 if (!tree->image) free(img);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1579
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1580 return tree;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1581
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1582 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1583 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1584 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1585
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1586 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1587 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1588 /* Functionname: best_level_selection */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1589 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1590 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1591 /* original: Image that should be transformed */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1592 /* maxlevel: transform down to level */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1593 /* flt: transform with filters flt[0..level] */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1594 /* method: transform with filter method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1595 /* cost: carry best basis selection out with this costfunc */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1596 /* epsilon: limit for threshold method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1597 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1598 /* Description: Carries out the best level selection */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1599 /* */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1600 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1601 extern Image_tree best_level(Image original,int maxlevel,int *bestlevel,FilterGH *flt,enum FilterMethod method,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1602 enum Information_Cost cost,double epsilon)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1603 { Image_tree tree;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1604 Image img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1605 double *entropies,min;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1606 int best=0,i,e;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1607
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1608 img=new_image(original->width,original->height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1609 copy_into_image(img,original,0,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1610
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1611 tree=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1612 tree->image=img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1613
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1614 entropies=(double *)calloc(maxlevel+1,sizeof(double));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1615 if(!entropies) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1616
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1617 /* decompose down to maxlevel */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1618 e=decompose_all(tree,maxlevel,flt,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1619 if (!e) return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1620
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1621 /* compute costs of each level and store it in entropies array*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1622 compute_levels(tree,entropies,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1623
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1624 min=entropies[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1625 for (i=1;i<=maxlevel;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1626 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1627 if (entropies[i]<min)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1628 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1629 min=entropies[i];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1630 best=i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1631 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1632 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1633
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1634 /* free all other levels */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1635 free_levels(tree,best);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1636
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1637 *bestlevel=best;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1638
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1639 return tree;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1640
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1641 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1642 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1643 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1644 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1645
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1646 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1647 /* Functionname: compute_best */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1648 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1649 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1650 /* img: Image that should be transformed */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1651 /* level: transform level */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1652 /* max_level: transform to maximum level */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1653 /* flt: transform with filters flt[0..level] */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1654 /* method: transform with filter method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1655 /* cost: carry best basis selection out with this costfunc */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1656 /* epsilon: limit for threshold method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1657 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1658 /* Description: Carries out the best basis selection (recursivly) */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1659 /* (is needed by the waveletpacket procedure) */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1660 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1661 static int compute_best(Image_tree tree,int level,int max_level,FilterGH *flt,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1662 enum FilterMethod method,enum Information_Cost cost,double epsilon)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1663
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1664 { Image coarse,horizontal,vertical,diagonal;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1665 int e,width,height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1666 double sum;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1667
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1668 tree->level=level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1669
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1670 /* non additive cost function*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1671 if (cost>=shanon)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1672 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1673 tree->entropy=compute_non_additive(tree,tree->image->size,cost,epsilon,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1674 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1675 /*additive cost function*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1676 else tree->entropy=compute_entropy(tree->image,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1677
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1678 if (level<max_level) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1679 width=(tree->image->width+1)/2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1680 height=(tree->image->height+1)/2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1681
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1682 tree->coarse=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1683 tree->horizontal=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1684 tree->vertical=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1685 tree->diagonal=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1686
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1687 coarse=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1688 horizontal=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1689 vertical=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1690 diagonal=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1691 if(!coarse||!vertical||!horizontal||!diagonal) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1692
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1693 e=decomposition(tree->image,coarse,horizontal,vertical,diagonal,flt[0]->g,flt[0]->h,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1694 if (!e) return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1695
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1696 tree->coarse->image=coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1697 tree->horizontal->image=horizontal;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1698 tree->vertical->image=vertical;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1699 tree->diagonal->image=diagonal;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1700
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1701 e=compute_best(tree->coarse,level+1,max_level,flt+1,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1702 e=compute_best(tree->horizontal,level+1,max_level,flt+1,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1703 e=compute_best(tree->vertical,level+1,max_level,flt+1,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1704 e=compute_best(tree->diagonal,level+1,max_level,flt+1,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1705 if (!e) return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1706
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1707 /*going back in recursion*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1708
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1709 if (cost>=shanon) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1710 sum=compute_non_additive(tree,tree->image->size,cost,epsilon,1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1711 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1712 else sum=(tree->coarse->entropy)+(tree->horizontal->entropy)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1713 +(tree->vertical->entropy)+(tree->diagonal->entropy);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1714
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1715 if (tree->entropy>sum)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1716 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1717 tree->entropy=sum;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1718 free_image(tree->image); /* take down tree */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1719 tree->image=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1720
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1721 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1722 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1723 { /* delete the tree downwards */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1724 free_image_tree(tree->coarse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1725 free_image_tree(tree->horizontal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1726 free_image_tree(tree->vertical);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1727 free_image_tree(tree->diagonal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1728
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1729 tree->coarse=tree->vertical=tree->horizontal=tree->diagonal=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1730 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1731 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1732
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1733 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1734
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1735 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1736 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1737 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1738
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1739 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1740
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1741 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1742 /* Functionname: decompose_all */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1743 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1744 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1745 /* tree: Image tree to be decomposed */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1746 /* maxlevel: decompose down to level */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1747 /* flt: transform with filters flt[0..maxlevel] */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1748 /* method: transform with filter method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1749 /* cost: cost function for entropy computing */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1750 /* epsilon: limit for threshold method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1751 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1752 /* Description: whole decompositing down to maxlevel */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1753 /* The original image must be in tree->image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1754 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1755 extern int decompose_all(Image_tree tree,int maxlevel,FilterGH *flt,enum FilterMethod method,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1756 enum Information_Cost cost,double epsilon)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1757 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1758 Image original,coarse,horizontal,vertical,diagonal;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1759 int e,width,height,level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1760
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1761 if (tree->level<maxlevel)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1762 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1763 tree->coarse=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1764 tree->horizontal=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1765 tree->vertical=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1766 tree->diagonal=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1767
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1768 original=tree->image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1769 width=(original->width+1)/2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1770 height=(original->height+1)/2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1771 level=tree->level;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1772
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1773 coarse=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1774 horizontal=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1775 vertical=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1776 diagonal=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1777 if(!coarse||!vertical||!horizontal||!diagonal) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1778
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1779
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1780 e=decomposition(tree->image,coarse,horizontal,vertical,diagonal,flt[0]->g,flt[0]->h,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1781 if (!e) return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1782
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1783 tree->coarse->image=coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1784 tree->horizontal->image=horizontal;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1785 tree->vertical->image=vertical;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1786 tree->diagonal->image=diagonal;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1787
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1788 tree->coarse->entropy=compute_entropy(coarse,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1789 tree->horizontal->entropy=compute_entropy(horizontal,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1790 tree->vertical->entropy=compute_entropy(vertical,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1791 tree->diagonal->entropy=compute_entropy(diagonal,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1792
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1793 tree->coarse->level=tree->horizontal->level=
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1794 tree->vertical->level=tree->diagonal->level=level+1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1795
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1796 e=decompose_all(tree->coarse,maxlevel,flt+1,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1797 e=decompose_all(tree->horizontal,maxlevel,flt+1,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1798 e=decompose_all(tree->vertical,maxlevel,flt+1,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1799 e=decompose_all(tree->diagonal,maxlevel,flt+1,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1800 if (!e) return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1801
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1802 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1803
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1804 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1805
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1806 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1807 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1808 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1809 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1810
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1811 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1812 /* Functionname: compute_levels */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1813 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1814 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1815 /* tree: Image tree where the entropy should be computed */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1816 /* entropies : array for entropy */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1817 /* cost: carry best basis selection out with this costfunc */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1818 /* epsilon: limit for threshold method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1819 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1820 /* Description: Compute the entropies of all decomposition levels */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1821 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1822 static compute_levels(Image_tree tree,double *entropies,enum Information_Cost cost,double epsilon)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1823 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1824 if (tree->image){
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1825 entropies[tree->level]+=compute_entropy(tree->image,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1826 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1827 if (tree->coarse) compute_levels(tree->coarse,entropies,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1828 if (tree->horizontal) compute_levels(tree->horizontal,entropies,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1829 if (tree->vertical) compute_levels(tree->vertical,entropies,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1830 if (tree->diagonal) compute_levels(tree->diagonal,entropies,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1831
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1832 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1833
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1834 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1835 /* Functionname: free_levels */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1836 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1837 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1838 /* tree: Image tree which should be cleaned */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1839 /* best: best level */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1840 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1841 /* Description: clean the image tree except the best level */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1842 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1843 static free_levels(Image_tree tree,int best)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1844 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1845 if (tree->level<best)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1846 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1847 free_image(tree->image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1848 tree->image=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1849 free_levels(tree->coarse,best);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1850 free_levels(tree->horizontal,best);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1851 free_levels(tree->vertical,best);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1852 free_levels(tree->diagonal,best);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1853 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1854 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1855 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1856 if (tree->coarse)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1857 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1858 free_image_tree(tree->coarse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1859 free_image_tree(tree->horizontal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1860 free_image_tree(tree->vertical);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1861 free_image_tree(tree->diagonal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1862 tree->coarse=tree->horizontal=tree->vertical=tree->diagonal=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1863 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1864 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1865 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1866
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1867 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1868 /* Functionname: decompose_to_level */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1869 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1870 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1871 /* original: original image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1872 /* level: decompose to level */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1873 /* flt: decompos with filters[0..level] */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1874 /* method: transform with filter method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1875 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1876 /* Description: Decomposes an image to an certain level and stores */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1877 /* only this level in the returned quadtree */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1878 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1879 extern Image_tree decompose_to_level(Image original,int level,FilterGH *flt,enum FilterMethod method)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1880 { Image_tree tree;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1881 int e;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1882
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1883 tree=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1884 tree->image=original;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1885
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1886 e=decompose_all(tree,level,flt,method,entropy,1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1887 if (!e) return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1888
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1889 free_levels(tree,level);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1890
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1891 return tree;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1892
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1893 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1894
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1895 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1896 /* Functionname: decomposition */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1897 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1898 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1899 /* t_img: Image which should be decomposed */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1900 /* coarse,horizontal,vertical,diagonal: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1901 /* decomposed images */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1902 /* method: transform with filter method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1903 /* g,h: the transformation is carried out with these filters*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1904 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1905 /* Description: This carries out one wavelettransformation */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1906 /* using waveletfilters. */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1907 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1908
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1909 static int decomposition(Image t_img,Image coarse,Image horizontal,Image vertical,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1910 Image diagonal,Filter g,Filter h,enum FilterMethod method)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1911 { Image temp1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1912
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1913 /*coarse*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1914 temp1=new_image(coarse->width,t_img->height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1915 if(!temp1) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1916 convolute_lines(temp1,t_img,h,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1917 convolute_rows(coarse,temp1,h,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1918
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1919 /*horizontal*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1920 convolute_rows(horizontal,temp1,g,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1921 free_image(temp1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1922
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1923 /*vertical*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1924 temp1=new_image(vertical->width,t_img->height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1925 if(!temp1) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1926 convolute_lines(temp1,t_img,g,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1927 convolute_rows(vertical,temp1,h,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1928
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1929 /*diagonal*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1930 convolute_rows(diagonal,temp1,g,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1931 free_image(temp1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1932
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1933 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1934
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1935 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1936 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1937 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1938
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1939 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1940
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1941 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1942 /* Functionname: inv_decomposition */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1943 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1944 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1945 /* sum: reconstructed image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1946 /* coarse,horizontal,vertical,diagonal: images to carry out*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1947 /* the inverse transformation */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1948 /* flt_gh: transform with filters g and h */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1949 /* method: transform with filter method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1950 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1951 /* Description: Carries out the wavelettransform */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1952 /* */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1953 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1954 static int inv_decomposition(Image sum,Image coarse,Image horizontal,Image vertical,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1955 Image diagonal,FilterGH flt_gh,enum FilterMethod method)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1956 { Image temp1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1957 Filter g,h;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1958
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1959 if (flt_gh->type==FTOrtho) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1960 g=flt_gh->g;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1961 h=flt_gh->h;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1962 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1963 else {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1964 g=flt_gh->gi;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1965 h=flt_gh->hi;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1966 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1967
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1968 /*coarse*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1969 temp1=new_image(coarse->width,sum->height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1970 if(!temp1) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1971 convolute_rows(temp1,coarse,h,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1972
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1973 /*horizontal*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1974 convolute_rows(temp1,horizontal,g,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1975 convolute_lines(sum,temp1,h,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1976 free_image(temp1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1977
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1978 /*vertical*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1979 temp1=new_image(vertical->width,sum->height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1980 if(!temp1) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1981 convolute_rows(temp1,vertical,h,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1982
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1983 /*diagonal*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1984 convolute_rows(temp1,diagonal,g,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1985 convolute_lines(sum,temp1,g,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1986
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1987 free_image(temp1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1988
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1989 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1990
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1991 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1992 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1993 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1994 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1995
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1996 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1997 /* Functionname: build_image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1998 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
1999 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2000 /* quadtree: quadtree with decomposition information */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2001 /* width,height: image width and height */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2002 /* RETURN: returns the build up image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2003 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2004 /* Description: builds up an image out of an Image_tree */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2005 /* */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2006 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2007 extern Image build_image(Image_tree quadtree,int width,int height)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2008 { Image ret_img,coarse,horizontal,vertical,diagonal;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2009
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2010
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2011 ret_img=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2012 if(!ret_img) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2013
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2014 width=(width+1)/2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2015 height=(height+1)/2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2016
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2017 if (!(quadtree->image)) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2018 coarse=build_image(quadtree->coarse,width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2019 horizontal=build_image(quadtree->horizontal,width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2020 vertical=build_image(quadtree->vertical,width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2021 diagonal=build_image(quadtree->diagonal,width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2022 if (!coarse||!horizontal||!vertical||!diagonal) return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2023
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2024 copy_into_image(ret_img,coarse,0,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2025 copy_into_image(ret_img,horizontal,width,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2026 copy_into_image(ret_img,vertical,0,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2027 copy_into_image(ret_img,diagonal,width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2028
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2029 if (!quadtree->coarse->image) free_image(coarse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2030 if (!quadtree->horizontal->image) free_image(horizontal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2031 if (!quadtree->vertical->image) free_image(vertical);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2032 if (!quadtree->diagonal->image) free_image(diagonal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2033
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2034 return ret_img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2035 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2036 else return quadtree->image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2037
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2038 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2039 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2040 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2041 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2042
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2043 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2044 /* Functionname: inv_transform */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2045 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2046 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2047 /* tree: tree with decomposition information */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2048 /* flt_gh: transform with filters g and h */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2049 /* method: transform with filter method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2050 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2051 /* Description: Inverts the wavelettransform,best_basis,best_level */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2052 /* */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2053 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2054 extern Image inv_transform(Image_tree tree,FilterGH *flt,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2055 enum FilterMethod method)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2056
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2057 { int er,width,height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2058 Image ret_img,coarse,vertical,horizontal,diagonal;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2059
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2060 if (!tree->image) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2061
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2062 coarse=inv_transform(tree->coarse,flt,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2063 horizontal=inv_transform(tree->horizontal,flt,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2064 vertical=inv_transform(tree->vertical,flt,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2065 diagonal=inv_transform(tree->diagonal,flt,method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2066 if (!coarse||!horizontal||!vertical||!diagonal) return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2067
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2068 width=coarse->width+horizontal->width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2069 height=coarse->height+vertical->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2070
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2071 ret_img=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2072 if(!ret_img) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2073
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2074
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2075 if (tree->flag==0) /*if flag is set it is a doubletree tiling*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2076 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2077 // er=inv_decomposition(ret_img,coarse,horizontal,vertical,diagonal,flt[1],method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2078 er=inv_decomposition(ret_img,coarse,horizontal,vertical,diagonal,flt[tree->level],method);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2079 if (!er) return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2080 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2081 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2082 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2083 copy_into_image(ret_img,coarse,0,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2084 copy_into_image(ret_img,horizontal,coarse->width,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2085 copy_into_image(ret_img,vertical,0,coarse->height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2086 copy_into_image(ret_img,diagonal,coarse->width,coarse->height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2087 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2088
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2089 if (!tree->coarse->image) free_image(coarse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2090 if (!tree->horizontal->image) free_image(horizontal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2091 if (!tree->vertical->image) free_image(vertical);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2092 if (!tree->diagonal->image) free_image(diagonal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2093
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2094 return ret_img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2095 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2096
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2097 else return tree->image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2098
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2099 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2100 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2101 return NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2102 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2103
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2104 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2105 /* Functionname: find_deepest_level */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2106 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2107 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2108 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2109 /* Description: Finds the deepest possible level where width and */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2110 /* height can divided by two exactly. */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2111 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2112 extern int find_deepest_level(int width,int height)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2113 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2114 int level=0,w=width,h=height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2115
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2116 while ( !((w%2)||(h%2)))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2117 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2118 w=w/2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2119 h=h/2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2120 level++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2121 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2122
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2123 return level-1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2124
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2125 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2126
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2127 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2128 /* Functionname: convolute_lines */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2129 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2130 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2131 /* output: output image of wavelettransformation */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2132 /* input: input image for decomposition */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2133 /* flt: transform with filter flt */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2134 /* method: transform with filter method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2135 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2136 /* Description: Carries out the wavelettransform for all lines of */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2137 /* the input image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2138 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2139 static int convolute_lines(Image output,Image input,Filter flt,enum FilterMethod method)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2140 /*Convolute the lines with filter*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2141 { int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2142
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2143 for (i=0;i<input->height;i++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2144 switch(method) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2145 case cutoff:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2146 filter_cutoff(input,input->width*i,input->width,1,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2147 output,output->width*i,output->width,1,flt);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2148 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2149 case inv_cutoff:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2150 filter_inv_cutoff(input,input->width*i,input->width,1,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2151 output,output->width*i,output->width,1,flt);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2152 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2153 case periodical:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2154 filter_periodical(input,input->width*i,input->width,1,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2155 output,output->width*i,output->width,1,flt);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2156 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2157 case inv_periodical:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2158 filter_inv_periodical(input,input->width*i,input->width,1,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2159 output,output->width*i,output->width,1,flt);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2160 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2161 case mirror:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2162 filter_mirror(input,input->width*i,input->width,1,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2163 output,output->width*i,output->width,1,flt);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2164 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2165 case inv_mirror:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2166 filter_inv_mirror(input,input->width*i,input->width,1,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2167 output,output->width*i,output->width,1,flt);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2168 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2169
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2170
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2171 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2172 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2173
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2174 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2175 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2176
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2177 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2178 /* Functionname: convolute_rows */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2179 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2180 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2181 /* output: output image of wavelettransformation */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2182 /* input: input image for decomposition */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2183 /* flt: transform with filter flt */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2184 /* method: transform with filter method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2185 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2186 /* Description: Carries out the wavelettransform for all rows of */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2187 /* the input image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2188 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2189 static int convolute_rows(Image output,Image input,Filter flt,enum FilterMethod method)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2190 /*Convolute the rows with filter*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2191 { int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2192
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2193 for (i=0;i<input->width;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2194 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2195 switch (method)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2196 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2197 case cutoff:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2198 filter_cutoff(input,i,input->height,input->width,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2199 output,i,output->height,output->width,flt);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2200 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2201 case inv_cutoff:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2202 filter_inv_cutoff(input,i,input->height,input->width,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2203 output,i,output->height,output->width,flt);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2204 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2205 case periodical:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2206 filter_periodical(input,i,input->height,input->width,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2207 output,i,output->height,output->width,flt);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2208 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2209 case inv_periodical:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2210 filter_inv_periodical(input,i,input->height,input->width,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2211 output,i,output->height,output->width,flt);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2212 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2213 case mirror:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2214 filter_mirror(input,i,input->height,input->width,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2215 output,i,output->height,output->width,flt);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2216 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2217 case inv_mirror:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2218 filter_inv_mirror(input,i,input->height,input->width,
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2219 output,i,output->height,output->width,flt);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2220 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2221
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2222 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2223 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2224 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2225 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2226
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2227 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2228 /* Functionname: sumationq */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2229 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2230 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2231 /* img: image to compute */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2232 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2233 /* Description: compute the sum of quadrats of all elements of */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2234 /* the input image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2235 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2236 static Pixel sumationq(Image img)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2237 { Pixel sum=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2238 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2239
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2240 for (i=0;i<img->size;i++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2241 sum+=(*img->data+i)*(*img->data+i);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2242 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2243 return sum;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2244 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2245
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2246 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2247 /* Functionname: normq */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2248 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2249 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2250 /* tree: tree to compute */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2251 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2252 /* Description: computes the quadratic norm over all images in */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2253 /* the input tree */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2254 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2255 static Pixel normq(Image_tree tree)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2256 { Pixel sum=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2257
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2258 if (tree->image)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2259 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2260 sum=sumationq(tree->image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2261 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2262 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2263 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2264 if (tree->coarse) sum+=normq(tree->coarse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2265 if (tree->horizontal) sum+=normq(tree->horizontal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2266 if (tree->vertical) sum+=normq(tree->vertical);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2267 if (tree->diagonal) sum+=normq(tree->diagonal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2268 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2269
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2270 return sum;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2271 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2272
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2273 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2274 /* Functionname: sumation_down */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2275 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2276 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2277 /* tree: tree to compute */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2278 /* normq: norm of the images in the tree */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2279 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2280 /* Description: computes the Entropy over all (string aded) images */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2281 /* in the input tree */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2282 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2283 static Pixel sumation_down(Image_tree tree, Pixel normq)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2284 { Pixel sum=0,p;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2285 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2286 Image img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2287 Pixel *data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2288
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2289 if (tree->image)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2290 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2291 img=tree->image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2292 data=img->data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2293 for (i=0;i<img->size;i++,data++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2294 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2295 if (*data!=0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2296 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2297 p=(*data)*(*data)/normq;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2298 sum+=p*log(1/p);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2299 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2300 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2301 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2302 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2303 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2304 if (tree->coarse) sum+=sumation_down(tree->coarse,normq);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2305 if (tree->horizontal) sum+=sumation_down(tree->horizontal,normq);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2306 if (tree->vertical) sum+=sumation_down(tree->vertical,normq);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2307 if (tree->diagonal) sum+=sumation_down(tree->diagonal,normq);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2308 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2309
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2310 return sum;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2311 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2312
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2313 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2314 /* Functionname: comp */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2315 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2316 /* Description: used for quicksort for decreasing order */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2317 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2318 int comp(const Pixel *x,const Pixel *y)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2319 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2320 if (*x<*y) return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2321 else if (*x==*y) return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2322 else return -1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2323 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2324
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2325 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2326 /* Functionname: recarea */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2327 /* tree: Image tree to compute */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2328 /* list: target list */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2329 /* list_size: actual size of the list */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2330 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2331 /* Description: copies all elements within the tree into an list */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2332 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2333 static void recarea(Image_tree tree,Pixel *list,int *list_size)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2334 { Image img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2335
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2336 if (tree->image)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2337 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2338 img=tree->image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2339 memcpy(list+(*list_size),img->data,img->size*sizeof(Pixel));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2340 *list_size+=img->size;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2341 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2342 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2343 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2344 if (tree->coarse) recarea(tree->coarse,list,list_size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2345 if (tree->horizontal) recarea(tree->horizontal,list,list_size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2346 if (tree->vertical) recarea(tree->vertical,list,list_size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2347 if (tree->diagonal) recarea(tree->diagonal,list,list_size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2348 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2349
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2350 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2351
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2352 static void abs_list(Pixel *list,int list_size)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2353 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2354 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2355
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2356 for (i=0;i<list_size;i++) list[i]=fabs(list[i]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2357 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2358
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2359 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2360 /* Functionname: sum_list */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2361 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2362 /* Description: computes the sum of all poweres list elements */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2363 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2364 static Pixel sum_list(Pixel *list,int p,int size)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2365 { Pixel sum=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2366 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2367
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2368 for (i=0;i<size;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2369 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2370 if (p!=1) sum+=pow(list[i],p);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2371 else sum+=list[i];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2372 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2373 return sum;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2374 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2375
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2376 static Pixel weak_lp(Image_tree tree,int size,int p,double epsilon)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2377 { Pixel wlp,*list,max=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2378 int *list_size,k;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2379
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2380 list_size=(int *)malloc(sizeof(int));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2381 if (!list_size) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2382
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2383 *list_size=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2384
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2385 list=(Pixel *)calloc(size,sizeof(Pixel));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2386 if (!list) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2387
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2388 recarea(tree,list,list_size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2389 abs_list(list,*list_size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2390
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2391 qsort(list,*list_size, sizeof(Pixel), &comp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2392
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2393 for (k=0;k<size;k++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2394 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2395 if (k!=0) wlp=pow(k,1/p)*list[k];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2396 else wlp=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2397 if (wlp>max) max=wlp;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2398 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2399
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2400 free(list);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2401
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2402 return max;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2403
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2404 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2405 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2406 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2407 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2408
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2409 static Pixel comp_number(Image_tree tree,int size,int p,double f)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2410 { Pixel sum=0,*list,min,norm,npf,normf;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2411 int *list_size=0,k;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2412
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2413 list_size=(int *)malloc(sizeof(int));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2414 if (!list_size) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2415 *list_size=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2416
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2417 list=(Pixel *)calloc(size,sizeof(Pixel));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2418 if (!list) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2419 recarea(tree,list,list_size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2420 abs_list(list,*list_size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2421
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2422 qsort(list,*list_size, sizeof(Pixel), &comp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2423
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2424 norm=sum_list(list,p,size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2425 normf=norm*f;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2426
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2427 for (k=0;k<size;k++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2428 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2429 if (list[k]!=0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2430 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2431 sum+=pow(list[k],p);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2432 npf=fabs(sum-normf);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2433 if (npf<min) min=npf;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2434 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2435 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2436 min=min/norm;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2437
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2438 free(list);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2439
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2440 return min;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2441
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2442 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2443 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2444 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2445 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2446
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2447 static Pixel comp_area(Image_tree tree,int size,int p,double f)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2448 { Pixel sum=0,*list,norm,vk=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2449 int *list_size=0,k;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2450
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2451 list_size=(int *)malloc(sizeof(int));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2452 if (!list_size) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2453 *list_size=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2454
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2455 list=(Pixel *)calloc(size,sizeof(Pixel));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2456 if (!list) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2457
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2458 recarea(tree,list,list_size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2459 abs_list(list,*list_size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2460
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2461 qsort(list,*list_size, sizeof(Pixel), &comp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2462
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2463 norm=sum_list(list,p,size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2464
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2465 for (k=0;k<size;k++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2466 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2467 if (list[k]!=0)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2468 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2469 vk+=pow(list[k],p);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2470 sum+=vk;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2471
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2472 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2473 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2474
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2475 free(list);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2476
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2477 return (size-sum/norm);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2478
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2479 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2480 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2481 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2482 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2483
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2484 static Pixel compute_sdiscrepancy(Image_tree tree,int size)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2485 { Pixel *list,min,max,factor,maximum=0,x;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2486 int *list_size=0,k;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2487
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2488 list_size=(int *)malloc(sizeof(int));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2489 if (!list_size) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2490 *list_size=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2491
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2492 list=(Pixel *)calloc(size,sizeof(Pixel));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2493 if (!list) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2494
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2495 recarea(tree,list,list_size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2496
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2497 qsort(list,*list_size, sizeof(Pixel), &comp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2498
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2499 min=list[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2500 max=list[size-1];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2501 factor=1/(max-min);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2502
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2503 /*scaling to [0,1]*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2504 for (k=0;k<size;k++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2505 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2506 list[k]=factor*(list[k]-min);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2507 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2508
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2509 for (k=0;k<size;k++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2510 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2511 x=fabs(list[k]-(2*k-1)/(2*size));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2512 if (x>maximum) maximum=x;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2513 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2514
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2515 free(list);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2516
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2517 return (1/(2*size)+maximum);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2518
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2519 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2520 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2521 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2522 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2523
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2524 static Pixel compute_discrepancy(Image_tree tree,int size)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2525 { Pixel *list,min,max,factor,maximum=0,minimum=0,x;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2526 int *list_size=0,k;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2527
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2528 list_size=(int *)malloc(sizeof(int));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2529 if (!list_size) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2530 *list_size=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2531
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2532 list=(Pixel *)calloc(size,sizeof(Pixel));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2533 if (!list) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2534
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2535 recarea(tree,list,list_size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2536
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2537 qsort(list,*list_size, sizeof(Pixel), &comp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2538
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2539 min=list[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2540 max=list[size-1];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2541 factor=1/(max-min);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2542
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2543 /*scaling to [0,1]*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2544 for (k=0;k<size;k++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2545 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2546 list[k]=factor*(list[k]-min);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2547 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2548
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2549 for (k=0;k<size;k++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2550 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2551 x=((Pixel)k/size-list[k]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2552 if (x>maximum) maximum=x;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2553 else if (x<minimum) minimum=x;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2554
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2555 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2556
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2557 free(list);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2558
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2559 return (1/size+maximum-minimum);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2560
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2561 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2562 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2563 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2564 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2565
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2566 static Pixel compute_concentration(Image_tree tree,int size)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2567 { Pixel *list,min,max,factor,lkm=0,length,sum=0,value,norm;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2568 int *list_size=0,k,next=0,last=0,i=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2569
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2570 list_size=(int *)malloc(sizeof(int));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2571 if (!list_size) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2572 *list_size=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2573
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2574 list=(Pixel *)calloc(size+1,sizeof(Pixel));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2575 if (!list) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2576
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2577 recarea(tree,list,list_size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2578
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2579 qsort(list,*list_size, sizeof(Pixel), &comp);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2580
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2581 min=list[0];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2582 max=list[size-1];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2583 length=(max-min)/100;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2584
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2585 factor=1/(max-min);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2586 for (k=0;k<size;k++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2587 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2588 list[k]=factor*(list[k]-min);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2589 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2590
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2591 norm=size*sum_list(list,1,size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2592 length=0.01;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2593 value=length;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2594
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2595 list[size]=max+value;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2596
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2597 for (k=0;k<100;k++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2598 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2599 while ((list[i]<value)&(i<size))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2600 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2601 sum+=list[i];
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2602 next++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2603 i++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2604 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2605 lkm+=(next-last)*sum/norm;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2606 value+=length;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2607 last=next;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2608 sum=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2609 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2610
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2611 return -lkm;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2612
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2613 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2614 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2615 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2616 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2617 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2618 /* Functionname: compute_entropy */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2619 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2620 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2621 /* img: Image from which the entropy should be computed */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2622 /* cost: choosen costfunction */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2623 /* epsilon: limit for threshold method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2624 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2625 /* Description: computes entropy of an image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2626 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2627 static double compute_entropy(Image img,enum Information_Cost cost,double epsilon)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2628 { double sum=0,x=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2629 int i;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2630 Pixel *data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2631
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2632 data=img->data;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2633
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2634 switch(cost) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2635
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2636 case threshold:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2637 for(i=0;i<img->size;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2638 if (fabs(img->data[i])>epsilon) sum++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2639 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2640
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2641 case log_energy:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2642 for(i=0;i<img->size;i++,data++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2643 x=(*data) * (*data);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2644 if (x!=0) sum+=(x*log(1/x));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2645 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2646 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2647
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2648 case norml:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2649 for(i=0;i<img->size;i++,data++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2650 x=fabs(*data);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2651 sum+=x;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2652 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2653 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2654
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2655 case norml2:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2656 for(i=0;i<img->size;i++,data++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2657 x=(*data) * (*data);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2658 sum+=x;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2659 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2660 sum=pow(sum,0.5);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2661 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2662
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2663 case entropy:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2664 for(i=0;i<img->size;i++,data++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2665 x=(*data)*(*data);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2666 if (x!=0) sum-=(x*log(x));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2667 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2668 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2669
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2670 case gauss_markov:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2671 for(i=0;i<img->size;i++) {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2672 x=(img->data[i])*(img->data[i]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2673 if (x!=0) sum+=log(x*x);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2674 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2675 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2676
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2677 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2678
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2679 return sum;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2680 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2681
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2682 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2683 /* Functionname: compute_non_additive */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2684 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2685 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2686 /* tree: Image tree from which the entropy should be */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2687 /* computed */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2688 /* size : size of the image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2689 /* cost: choosen costfunction */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2690 /* epsilon: limit for threshold method */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2691 /* down: decides if only the first image should be computed*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2692 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2693 /* Description: computes entropy of an image */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2694 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2695 static Pixel compute_non_additive(Image_tree tree,int size,enum Information_Cost cost,double epsilon,int down)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2696 { Pixel sum=0,normx;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2697 Image img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2698
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2699 if (down)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2700 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2701 img=tree->image;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2702 tree->image=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2703 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2704 switch (cost)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2705 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2706 case shanon:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2707 normx=normq(tree);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2708 sum=-sumation_down(tree,normx);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2709
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2710 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2711 case weak_l:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2712 sum=weak_lp(tree,size,1,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2713 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2714 case weak_lq:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2715 sum=weak_lp(tree,size,2,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2716 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2717 case compression_number:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2718 sum=comp_number(tree,size,1,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2719 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2720 case compression_numberq:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2721 sum=comp_number(tree,size,2,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2722 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2723 case compression_area:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2724 sum=comp_area(tree,size,1,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2725 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2726 case compression_areaq:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2727 sum=comp_area(tree,size,2,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2728 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2729 case discrepancy:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2730 sum=compute_discrepancy(tree,size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2731 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2732 case sdiscrepancy:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2733 sum=compute_sdiscrepancy(tree,size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2734 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2735 case concentration:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2736 sum=compute_concentration(tree,size);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2737 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2738
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2739
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2740 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2741
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2742 if (down) tree->image=img;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2743
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2744 return sum;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2745 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2746
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2747 extern int rec_double(Image_tree dtree,int level,FilterGH *flt,enum FilterMethod method,enum Information_Cost cost,double epsilon)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2748
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2749 { int min,width,height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2750 double sum=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2751 Image c,h,v,d;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2752
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2753 dtree->level=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2754
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2755 if (cost>=shanon)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2756 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2757 dtree->entropy=compute_non_additive(dtree,dtree->image->size,cost,epsilon,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2758 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2759 else dtree->entropy=compute_entropy(dtree->image,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2760
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2761 dtree->doubletree=best_basis(dtree->image,level,flt,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2762
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2763 min=dtree->image->width;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2764 if (dtree->image->height<min) min=dtree->image->height;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2765
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2766 if (doubletree_min<min)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2767 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2768 width=(dtree->image->width+1)/2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2769 height=(dtree->image->height+1)/2;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2770
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2771 dtree->coarse=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2772 dtree->horizontal=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2773 dtree->vertical=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2774 dtree->diagonal=new_image_tree();
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2775
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2776 c=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2777 h=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2778 v=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2779 d=new_image(width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2780 if(!c||!h||!v||!d) goto error;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2781
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2782
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2783 copy_part_of_image(c,dtree->image,0,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2784 copy_part_of_image(h,dtree->image,width,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2785 copy_part_of_image(v,dtree->image,0,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2786 copy_part_of_image(d,dtree->image,width,height);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2787
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2788 dtree->coarse->image=c;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2789 dtree->horizontal->image=h;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2790 dtree->vertical->image=v;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2791 dtree->diagonal->image=d;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2792
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2793 rec_double(dtree->coarse,level,flt,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2794 rec_double(dtree->horizontal,level,flt,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2795 rec_double(dtree->vertical,level,flt,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2796 rec_double(dtree->diagonal,level,flt,method,cost,epsilon);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2797
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2798 /* going back in recursion*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2799
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2800 sum=dtree->coarse->entropy+dtree->horizontal->entropy+
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2801 dtree->vertical->entropy+dtree->diagonal->entropy;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2802
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2803 if (sum>dtree->entropy)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2804 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2805 /*take image*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2806
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2807 free_image_tree(dtree->coarse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2808 free_image_tree(dtree->horizontal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2809 free_image_tree(dtree->vertical);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2810 free_image_tree(dtree->diagonal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2811 dtree->coarse=dtree->horizontal=dtree->vertical=dtree->diagonal=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2812 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2813 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2814 { /*take tiling*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2815 dtree->entropy=sum;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2816 free_image(dtree->image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2817 dtree->image=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2818 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2819
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2820 if (dtree->entropy>dtree->doubletree->entropy)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2821 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2822 /*take best basis tree*/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2823
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2824 dtree->entropy=dtree->doubletree->entropy;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2825
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2826 if(dtree->coarse) free_image_tree(dtree->coarse);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2827 if(dtree->horizontal) free_image_tree(dtree->horizontal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2828 if(dtree->vertical) free_image_tree(dtree->vertical);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2829 if(dtree->diagonal) free_image_tree(dtree->diagonal);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2830
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2831 dtree->coarse=dtree->doubletree->coarse;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2832 dtree->horizontal=dtree->doubletree->horizontal;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2833 dtree->vertical=dtree->doubletree->vertical;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2834 dtree->diagonal=dtree->doubletree->diagonal;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2835
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2836 free_image(dtree->image);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2837 dtree->image=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2838 free(dtree->doubletree);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2839 dtree->doubletree=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2840
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2841 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2842 else
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2843 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2844 dtree->flag=1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2845 if(dtree->doubletree) free_image_tree(dtree->doubletree);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2846 dtree->doubletree=NULL;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2847 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2848 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2849
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2850 return 1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2851
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2852 error:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2853 err_SimpleMessage(err_GetErrorMessage(Error_NotEnoughMemory));
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2854 return 0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2855 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2856
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2857 static save_structur(Image_tree tree,FILE *fp,int pos)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2858 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2859 int shift,next_pos,max;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2860
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2861 if (tree->flag)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2862 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2863 fprintf(fp,"%d ",pos);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2864
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2865 shift=pos-(pow(4,tree->level-1)-1)*4/3-1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2866 max=(int) ((pow(4,tree->level)-1)*4/3);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2867 next_pos=max+4*shift+1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2868 if (tree->coarse) save_structur(tree->coarse,fp,next_pos);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2869 if (tree->horizontal) save_structur(tree->horizontal,fp,next_pos+1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2870 if (tree->vertical) save_structur(tree->vertical,fp,next_pos+2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2871 if (tree->diagonal) save_structur(tree->diagonal,fp,next_pos+3);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2872 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2873
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2874 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2875
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2876 static int is_in_list(int *list,int len, int x)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2877 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2878 int i,found=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2879
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2880 for (i=0;i<len;i++)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2881 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2882 if (list[i]==x)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2883 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2884 found=1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2885 i=len;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2886 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2887 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2888
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2889 return found;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2890 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2891
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2892 static write_flags(Image_tree tree,int *list,int len,int pos)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2893 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2894 int shift,next_pos,max;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2895
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2896 if (is_in_list(list,len,pos))
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2897 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2898 tree->flag=1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2899
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2900 shift=pos-(pow(4,tree->level-1)-1)*4/3-1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2901 max=(int) ((pow(4,tree->level)-1)*4/3);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2902 next_pos=max+4*shift+1;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2903
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2904 write_flags(tree->coarse,list,len,next_pos);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2905 write_flags(tree->horizontal,list,len,next_pos+1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2906 write_flags(tree->vertical,list,len,next_pos+2);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2907 write_flags(tree->diagonal,list,len,next_pos+3);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2908 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2909 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2910
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2911 static read_structur(Image_tree tree,FILE *fp)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2912 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2913 int e, flags[1000],len=0,i=0;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2914
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2915 do
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2916 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2917 e=fscanf(fp,"%d ",&flags[i++]);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2918 if (e!=-1) len++;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2919 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2920 while (e!=-1);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2921
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2922 write_flags(tree,flags,len,0);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2923
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2924 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2925
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2926 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2927 /* Functionname: err_simple_message */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2928 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2929 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2930 /* char *: string that contains information about an */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2931 /* error the user should know. */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2932 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2933 /* Description: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2934 /* Prints error messages for the user. */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2935 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2936
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2937 void err_SimpleMessage(char *message)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2938 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2939 fprintf(stderr,"%s\n",message);
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2940 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2941
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2942 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2943 /* Functionname: err_get_message */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2944 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2945 /* Return value: Errormessage for this specific error. */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2946 /* Parameter: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2947 /* Error err: Error whose errormessage should be returned */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2948 /* -------------------------------------------------------------------- */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2949 /* Description: */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2950 /************************************************************************/
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2951 char * err_GetErrorMessage(Error err)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2952 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2953
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2954 switch (err)
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2955 {
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2956 case Error_NotImplemented:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2957 return "Sorry, this is not implemented yet. ";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2958 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2959
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2960 case Error_AssertionFailed:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2961 return "Sorry, an internal assertion was violated.\n"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2962 "This action can not be completed. :-(";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2963 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2964
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2965 case Error_NotEnoughMemory:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2966 return "Sorry, there is not enough memory";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2967 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2968
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2969 case Error_Limitation:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2970 return "Some limitation of the program exceeded";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2971 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2972
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2973 /* - FILES - */
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2974
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2975 case Error_CantOpenFile:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2976 return "Could not open file";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2977 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2978
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2979 case Error_CantCreateFile:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2980 return "Could not create file";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2981 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2982
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2983 case Error_CantCloseFile:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2984 return "Could not close file";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2985 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2986
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2987 case Error_InternalError:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2988 return "Sorry, an internal error occured.\n"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2989 "This action can not be completed. :-(";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2990 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2991
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2992 default:
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2993 return "Sorry, but an unknown error ocurred.\n"
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2994 "This action can not be completed. :-(";
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2995 break;
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2996
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2997
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2998 }
Peter Meerwald <pmeerw@cosy.sbg.ac.at>
parents:
diff changeset
2999 }

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