annotate Meerwald/wavelet.c @ 15:ad1d224896c5

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

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