1 | // -------------------- // |
---|
2 | // --- ecc_features --- // |
---|
3 | // -------------------- // |
---|
4 | |
---|
5 | |
---|
6 | /* |
---|
7 | * Copyright (c) 2012 - 2014, Lionel Lacassagne, All rights reserved |
---|
8 | * University of Paris Sud, Laboratoire de Recherche en Informatique |
---|
9 | */ |
---|
10 | |
---|
11 | // |
---|
12 | // Caracteristiques d'une region / label |
---|
13 | // |
---|
14 | |
---|
15 | #ifndef __ECC_FEATURES_H__ |
---|
16 | #define __ECC_FEATURES_H__ |
---|
17 | |
---|
18 | #ifdef __cplusplus |
---|
19 | extern "C" { |
---|
20 | #endif |
---|
21 | |
---|
22 | #ifdef VERBOSE_PRAGMA |
---|
23 | //#pragma message("- include ecc_features.h") |
---|
24 | #endif |
---|
25 | |
---|
26 | #define REGION_STATS1 |
---|
27 | |
---|
28 | //#define REGION_STATS2 |
---|
29 | //#define REGION_STATS3 |
---|
30 | //#define REGION_STATS4 |
---|
31 | |
---|
32 | #define Warning |
---|
33 | #define Error |
---|
34 | |
---|
35 | // ------------------------------------------------------------------------ |
---|
36 | // --- RegionStats -------------------------------------------------------- |
---|
37 | // ------------------------------------------------------------------------ |
---|
38 | |
---|
39 | typedef struct { |
---|
40 | |
---|
41 | uint16 xmin; |
---|
42 | uint16 xmax; |
---|
43 | uint16 ymin; |
---|
44 | uint16 ymax; |
---|
45 | |
---|
46 | uint32 S; |
---|
47 | |
---|
48 | uint16 x; // abscisse du centre d'inertie x = Sx / S |
---|
49 | uint16 y; // ordonnee du centre d'inertie y = Sy / S |
---|
50 | |
---|
51 | uint32 Sx; |
---|
52 | uint32 Sy; |
---|
53 | |
---|
54 | #ifdef REGION_STATS2 |
---|
55 | //uint64 Sx2; |
---|
56 | //uint64 Sxy; |
---|
57 | //uint64 Sy2; |
---|
58 | |
---|
59 | //uint32 Mx2; |
---|
60 | //uint32 Mxy; |
---|
61 | //uint32 My2; |
---|
62 | |
---|
63 | double teta; // direction principale |
---|
64 | #endif |
---|
65 | |
---|
66 | #ifdef REGION_STATS3 |
---|
67 | //uint64 Sx3; |
---|
68 | //uint64 Sx2y; |
---|
69 | //uint64 Sxy2; |
---|
70 | //uint64 Sy3; |
---|
71 | |
---|
72 | //uint64 Mx3; |
---|
73 | //uint64 Mx2y; |
---|
74 | //uint64 Mxy2; |
---|
75 | //uint64 My3; |
---|
76 | #endif |
---|
77 | } RegionStats; |
---|
78 | |
---|
79 | |
---|
80 | /* |
---|
81 | * ATTENTION x != (xmin+xmax)/2 |
---|
82 | * y != (ymin+ymax)/2 |
---|
83 | S != (xmax-xmin)(ymax-ymin) |
---|
84 | */ |
---|
85 | |
---|
86 | /* |
---|
87 | * n = S = phi0(x1) - phi0(x0-1) = x1 - x0 + 1 |
---|
88 | * Sx = phi1(x1) - phi1(x0-1) |
---|
89 | * Sx2 = phi2(x1) - phi2(x0-1) |
---|
90 | * Sx3 = phi3(x1) - phi3(x0-1) |
---|
91 | * Sy = nY |
---|
92 | * Sy2 = nY2 |
---|
93 | * Sxy = Y.Sx |
---|
94 | * Sx2y = Y.Sx2 |
---|
95 | * Sxy2 = Y2.Sx |
---|
96 | * Sy3 = nY3 |
---|
97 | * |
---|
98 | * phi1(x ) = x(x+1)/2 |
---|
99 | * phi1(x-1) = x(x-1)/2 |
---|
100 | * phi2(x ) = x(x+1)(2x+1)/6 |
---|
101 | * phi2(x-1) = x(x-1)(2x-1)/6 |
---|
102 | * phi3(x ) = Phi1(x).Phi1(x) |
---|
103 | * |
---|
104 | * Mx2 = Sx2 - Sx.Sx / n |
---|
105 | * My2 = Sy2 - Sy.Sy / n |
---|
106 | * Mxy = Sxy - Sx.Sy / n |
---|
107 | * |
---|
108 | * Mx3 = Sx3 - 3.Sx.Sx2 / n + 2.Sx.Sx.Sx / n2 |
---|
109 | * Mx2y = Sx2y - Sx2.Sy / n - 2.Sx.Sxy / n + 2.Sx.Sx.Sy / n2 |
---|
110 | * Mxy2 = Sxy2 - Sy2.Sx / n - 2.Sy.Sxy / n + 2.Sx.Sy.Sy / n2 |
---|
111 | * My3 = Sy3 - 3.Sy.Sy2 / n + 2.Sy.Sy.Sy / n2 |
---|
112 | */ |
---|
113 | |
---|
114 | /* ------------------------------ */ |
---|
115 | /* --- RegionStats after 2009 --- */ |
---|
116 | /* ------------------------------ */ |
---|
117 | // pas mieux que les fonctions precedentes -> a supprimer a terme (LL 2014) |
---|
118 | |
---|
119 | RegionStats* RegionStatsVector (int i0, int i1); |
---|
120 | RegionStats* RegionStatsVector0 (int i0, int i1); |
---|
121 | void free_RegionStatsVector (RegionStats *v, int i0, int i1); |
---|
122 | |
---|
123 | RegionStats** RegionStatsMatrix (int i0, int i1, int j0, int j1); |
---|
124 | RegionStats** RegionStatsMatrix0 (int i0, int i1, int j0, int j1); |
---|
125 | void free_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1); |
---|
126 | |
---|
127 | void zero_RegionStats (RegionStats *x); |
---|
128 | void zero_RegionStatsVector(RegionStats *v, int i0, int i1); |
---|
129 | void zero_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1); |
---|
130 | |
---|
131 | void display_RegionStats (RegionStats *x, char *name); |
---|
132 | void display_RegionStatsVector(RegionStats *v, int i0, int i1, char *name); |
---|
133 | void display_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1, char *name); |
---|
134 | |
---|
135 | void save_RegionStats (RegionStats *x, char *name); |
---|
136 | void save_RegionStatsVector(RegionStats *v, int i0, int i1, char *name); |
---|
137 | void save_RegionStatsMatrix(RegionStats **m, int i0, int i1, int j0, int j1, char *name); |
---|
138 | |
---|
139 | /* ----------------------------------------- */ |
---|
140 | /* --- RegionStats functions before 2009 --- */ |
---|
141 | /* ----------------------------------------- */ |
---|
142 | |
---|
143 | void RegionStats_Constructor (RegionStats **Stats, uint32 nemax); |
---|
144 | RegionStats* RegionStats_pConstructor( uint32 nemax); |
---|
145 | void RegionStats_Destructor (RegionStats **Stats, uint32 nemax); |
---|
146 | void RegionStats_pDestructor (RegionStats *Stats, uint32 nemax); |
---|
147 | void RegionStats_Clear (RegionStats *Stats, uint32 nemax); |
---|
148 | |
---|
149 | int RegionStats_Create_File (char *filename); // for read |
---|
150 | int RegionStats_Open_File (char *filename); // for write |
---|
151 | void RegionStats_Close_File (int fd); |
---|
152 | |
---|
153 | int RegionStats_Read_Header ( int fd); // return ne |
---|
154 | void RegionStats_Write_Header(int ne, int fd); |
---|
155 | |
---|
156 | void RegionStats_Read_Stats1 (int fd, int ne, RegionStats *stats); |
---|
157 | void RegionStats_Read_Stats2 (int fd, int ne, RegionStats *stats); |
---|
158 | |
---|
159 | void RegionStats_Write_Stats1(RegionStats *Stats, int ne, int fd); |
---|
160 | void RegionStats_Write_Stats2(RegionStats *Stats, int ne, int fd); |
---|
161 | |
---|
162 | void RegionStats_Write_Stats1_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1, int fd); |
---|
163 | |
---|
164 | void RegionStats_Load_Stats1 (char *filename, int *ne, RegionStats **Stats); |
---|
165 | void RegionStats_Load_Stats2 (char *filename, int *ne, RegionStats **Stats); |
---|
166 | |
---|
167 | void RegionStats_MLoad_Stats1(char *filename, int *ne, RegionStats *Stats); // Stats must have been allocated |
---|
168 | void RegionStats_MLoad_Stats2(char *filename, int *ne, RegionStats *Stats); // Stats must have been allocated |
---|
169 | |
---|
170 | void RegionStats_Save_Stats1(RegionStats *Stats, int ne, char *filename); |
---|
171 | void RegionStats_Save_Stats2(RegionStats *Stats, int ne, char *filename); |
---|
172 | |
---|
173 | void RegionStats_Display_Stats1(RegionStats *Stats, int ne, char *name); |
---|
174 | void RegionStats_Display_Stats2(RegionStats *Stats, int ne, char *name); |
---|
175 | |
---|
176 | //void RegionStats_Rectangle_Computation(RegionStats *Stats, Image *imageL); |
---|
177 | void RegionStats_SetRectangle (RegionStats *Stats, int e, int ymin, int ymax, int xmin, int xmax); |
---|
178 | |
---|
179 | // pointeur de tableau de Stats (ECC: pour LSL parallel |
---|
180 | |
---|
181 | void RegionStats_Save_pStats1(RegionStats **pStats, int ne, char *filename); |
---|
182 | void RegionStats_Save_pStats2(RegionStats **pStats, int ne, char *filename); |
---|
183 | |
---|
184 | void RegionStats_Display_pStats1(RegionStats **pStats, int ne, char *name); |
---|
185 | void RegionStats_Display_pStats2(RegionStats **pStats, int ne, char *name); |
---|
186 | |
---|
187 | void Region32_Calc1_Features_1Pass(RegionStats *Stats, uint32 e, int i, int j); |
---|
188 | // faire une version pointFeaturesComputation (cf line et image) |
---|
189 | // ------------------------ |
---|
190 | // --- RegionStats 2013 --- |
---|
191 | // ------------------------ |
---|
192 | void RegionStats_Calc_Rectangle_Moment1(uint32 **E, int height, int width, RegionStats *Stats); |
---|
193 | void RegionStats_calc_Status(RegionStats *Stats, uint32 ne, uint32 min_height, uint32 min_width, uint32 min_area, uint8 *status); |
---|
194 | uint32 RegionStats_UpdateEQ_with_Status(uint8 *status, uint32 ne, uint32 *EQ); |
---|
195 | void RegionStats_UpdateStats_with_EQ(uint32 *EQ, uint32 ne, RegionStats *Stats); |
---|
196 | |
---|
197 | |
---|
198 | // RegioStats 2014 (Laurent Cabaret) |
---|
199 | void featuresComputation(uint32 **E, int height,int width,RegionStats *Stats); // ne plus utiliser |
---|
200 | |
---|
201 | void pointFeaturesComputation_Dummy(uint32 **E, int i, int j, RegionStats *Stats); |
---|
202 | void pointFeaturesComputation (uint32 **E, int i, int j, RegionStats *Stats); |
---|
203 | |
---|
204 | void lineFeaturesComputation_Dummy(uint32 **E, int i, int width, RegionStats *Stats); |
---|
205 | void lineFeaturesComputation (uint32 **E, int i, int width, RegionStats *Stats); |
---|
206 | |
---|
207 | void bandFeaturesComputation_Dummy(uint32 **E, int i0, int i1, int width, RegionStats *Stats); |
---|
208 | void bandFeaturesComputation (uint32 **E, int i0, int i1, int width, RegionStats *Stats); |
---|
209 | |
---|
210 | void imageFeaturesComputation_Dummy(uint32 **E, int height, int width, RegionStats *Stats); |
---|
211 | void imageFeaturesComputation (uint32 **E, int height, int width, RegionStats *Stats); |
---|
212 | |
---|
213 | // ------------------------ |
---|
214 | // --- RegionStats 2014 --- |
---|
215 | // ------------------------ |
---|
216 | |
---|
217 | void RegionStats_Copy_Stats1_From_Index(RegionStats *Stats, int dst_index, int src_index); |
---|
218 | void RegionStats_Accumulate_Stats1_From_Index(RegionStats *Stats, int dst_index, int src_index); |
---|
219 | |
---|
220 | void RegionStats_Save_Stats1_Sparse(RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1, char *filename); |
---|
221 | void RegionStats_DisplayStats_Sparse(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name); |
---|
222 | // affichage des Stats pour les etiquettes roots/ancetres de leur composante (pour algo Suzuki) |
---|
223 | |
---|
224 | void RegionStats_DisplayStats_Range(uint32 *EQ, uint32 ne0, uint32 ne1, RegionStats *Stats, char *name); |
---|
225 | |
---|
226 | // nb de composantes connexes pour Suzuki MK2 |
---|
227 | uint32 RegionStats_Count_Roots_Sparse1(RegionStats *Stats, uint32 *EQ, uint32 nemax); |
---|
228 | uint32 RegionStats_Count_Roots_Sparse (RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1); |
---|
229 | |
---|
230 | uint32 RegionStats_Count_Labels_Sparse1(RegionStats *Stats, uint32 *EQ, uint32 nemax); |
---|
231 | uint32 RegionStats_Count_Labels_Sparse (RegionStats *Stats, uint32 *EQ, uint32 ne0, uint32 ne1); |
---|
232 | |
---|
233 | void copy_features_ui32matrix(RegionStats *Stats, uint32 ne, uint32 **m); |
---|
234 | void copy_ui32matrix_features(uint32 **m, uint32 ne, RegionStats *Stats); |
---|
235 | void sortv_ui32matrix_col(uint32 **m, int i0, int i1, int j0, int j1, int col); |
---|
236 | void RegionStats_SortFeatures(RegionStats *Stats, uint32 nemax); |
---|
237 | |
---|
238 | // version paralleles avec OpenMP2 ou OpenMP4 |
---|
239 | void imageFeaturesComputation_omp0(uint32 **E, int height, int width, RegionStats *Stats); // wrong |
---|
240 | void imageFeaturesComputation_omp2(uint32 **E, int height, int width, RegionStats *Stats); // OpenMP 2.0 critical |
---|
241 | void imageFeaturesComputation_omp3(uint32 **E, int height, int width, RegionStats *Stats); // OpenMP 2.0 critical + atomic |
---|
242 | void imageFeaturesComputation_omp4(uint32 **E, int height, int width, RegionStats *Stats); // OpenMP 3.0 task + OpenMP 4.0 depend |
---|
243 | void imageFeaturesComputation_omp5(uint32 **E, int height, int width, uint16* Xmin, uint16* Xmax, uint16* Ymin, uint16* Ymax, uint32* S, uint32* Sx, uint32* Sy); |
---|
244 | |
---|
245 | int RegionStats_Compare(RegionStats *S1, RegionStats *S2); |
---|
246 | int RegionStatsVector_Compare(RegionStats *S1, int i0, int i1, RegionStats *S2); |
---|
247 | int RegionStatsVector_Match (RegionStats *S1, int i0, int i1, RegionStats *S2, int j0, int j1); |
---|
248 | |
---|
249 | #ifdef __cplusplus |
---|
250 | } |
---|
251 | #endif |
---|
252 | |
---|
253 | #endif /* __FEATURES_H__ */ |
---|