Leptonica 1.68
C Image Processing Library
|
00001 /*====================================================================* 00002 - Copyright (C) 2001 Leptonica. All rights reserved. 00003 - This software is distributed in the hope that it will be 00004 - useful, but with NO WARRANTY OF ANY KIND. 00005 - No author or distributor accepts responsibility to anyone for the 00006 - consequences of using this software, or for whether it serves any 00007 - particular purpose or works at all, unless he or she says so in 00008 - writing. Everyone is granted permission to copy, modify and 00009 - redistribute this source code, for commercial or non-commercial 00010 - purposes, with the following restrictions: (1) the origin of this 00011 - source code must not be misrepresented; (2) modified versions must 00012 - be plainly marked as such; and (3) this notice may not be removed 00013 - or altered from any source or modified source distribution. 00014 *====================================================================*/ 00015 00016 /* 00017 * dwamorph2_reg.c 00018 * 00019 * Compare the timings of various binary morphological implementations. 00020 */ 00021 00022 #include "allheaders.h" 00023 00024 #define HALFWIDTH 3 00025 00026 /* Complete set of linear brick dwa operations */ 00027 PIX *pixMorphDwa_3(PIX *pixd, PIX *pixs, l_int32 operation, char *selname); 00028 00029 static const l_int32 NTIMES = 20; 00030 00031 main(int argc, 00032 char **argv) 00033 { 00034 char *selname; 00035 l_int32 i, j, nsels, sx, sy; 00036 l_float32 fact, time; 00037 GPLOT *gplot; 00038 NUMA *na1, *na2, *na3, *na4, *nac1, *nac2, *nac3, *nac4, *nax; 00039 PIX *pixs, *pixt; 00040 PIXA *pixa; 00041 SEL *sel; 00042 SELA *selalinear; 00043 static char mainName[] = "dwamorph2_reg"; 00044 00045 if (argc != 1) 00046 exit(ERROR_INT(" Syntax: dwamorph2_reg", mainName, 1)); 00047 00048 if ((pixs = pixRead("feyn-fract.tif")) == NULL) 00049 exit(ERROR_INT("pix not made", mainName, 1)); 00050 pixt = pixCreateTemplate(pixs); 00051 00052 selalinear = selaAddDwaLinear(NULL); 00053 nsels = selaGetCount(selalinear); 00054 00055 fact = 1000. / (l_float32)NTIMES; /* converts to time in msec */ 00056 na1 = numaCreate(64); 00057 na2 = numaCreate(64); 00058 na3 = numaCreate(64); 00059 na4 = numaCreate(64); 00060 00061 /* --------- dilation ----------*/ 00062 00063 for (i = 0; i < nsels / 2; i++) 00064 { 00065 sel = selaGetSel(selalinear, i); 00066 selGetParameters(sel, &sy, &sx, NULL, NULL); 00067 selname = selGetName(sel); 00068 fprintf(stderr, " %d .", i); 00069 00070 startTimer(); 00071 for (j = 0; j < NTIMES; j++) 00072 pixDilate(pixt, pixs, sel); 00073 time = fact * stopTimer(); 00074 numaAddNumber(na1, time); 00075 00076 startTimer(); 00077 for (j = 0; j < NTIMES; j++) 00078 pixDilateCompBrick(pixt, pixs, sx, sy); 00079 time = fact * stopTimer(); 00080 numaAddNumber(na2, time); 00081 00082 startTimer(); 00083 for (j = 0; j < NTIMES; j++) 00084 pixMorphDwa_3(pixt, pixs, L_MORPH_DILATE, selname); 00085 time = fact * stopTimer(); 00086 numaAddNumber(na3, time); 00087 00088 startTimer(); 00089 for (j = 0; j < NTIMES; j++) 00090 pixDilateCompBrickDwa(pixt, pixs, sx, sy); 00091 time = fact * stopTimer(); 00092 numaAddNumber(na4, time); 00093 } 00094 00095 nax = numaMakeSequence(2, 1, nsels / 2); 00096 nac1 = numaWindowedMean(na1, HALFWIDTH); 00097 nac2 = numaWindowedMean(na2, HALFWIDTH); 00098 nac3 = numaWindowedMean(na3, HALFWIDTH); 00099 nac4 = numaWindowedMean(na4, HALFWIDTH); 00100 gplot = gplotCreate("/tmp/junkdilate", GPLOT_PNG, 00101 "Dilation time vs sel size", "size", "time (ms)"); 00102 gplotAddPlot(gplot, nax, nac1, GPLOT_LINES, "linear rasterop"); 00103 gplotAddPlot(gplot, nax, nac2, GPLOT_LINES, "composite rasterop"); 00104 gplotAddPlot(gplot, nax, nac3, GPLOT_LINES, "linear dwa"); 00105 gplotAddPlot(gplot, nax, nac4, GPLOT_LINES, "composite dwa"); 00106 gplotMakeOutput(gplot); 00107 gplotDestroy(&gplot); 00108 numaDestroy(&nac1); 00109 numaDestroy(&nac2); 00110 numaDestroy(&nac3); 00111 numaDestroy(&nac4); 00112 00113 /* --------- erosion ----------*/ 00114 00115 numaEmpty(na1); 00116 numaEmpty(na2); 00117 numaEmpty(na3); 00118 numaEmpty(na4); 00119 for (i = 0; i < nsels / 2; i++) 00120 { 00121 sel = selaGetSel(selalinear, i); 00122 selGetParameters(sel, &sy, &sx, NULL, NULL); 00123 selname = selGetName(sel); 00124 fprintf(stderr, " %d .", i); 00125 00126 startTimer(); 00127 for (j = 0; j < NTIMES; j++) 00128 pixErode(pixt, pixs, sel); 00129 time = fact * stopTimer(); 00130 numaAddNumber(na1, time); 00131 00132 startTimer(); 00133 for (j = 0; j < NTIMES; j++) 00134 pixErodeCompBrick(pixt, pixs, sx, sy); 00135 time = fact * stopTimer(); 00136 numaAddNumber(na2, time); 00137 00138 startTimer(); 00139 for (j = 0; j < NTIMES; j++) 00140 pixMorphDwa_3(pixt, pixs, L_MORPH_ERODE, selname); 00141 time = fact * stopTimer(); 00142 numaAddNumber(na3, time); 00143 00144 startTimer(); 00145 for (j = 0; j < NTIMES; j++) 00146 pixErodeCompBrickDwa(pixt, pixs, sx, sy); 00147 time = fact * stopTimer(); 00148 numaAddNumber(na4, time); 00149 } 00150 00151 nac1 = numaWindowedMean(na1, HALFWIDTH); 00152 nac2 = numaWindowedMean(na2, HALFWIDTH); 00153 nac3 = numaWindowedMean(na3, HALFWIDTH); 00154 nac4 = numaWindowedMean(na4, HALFWIDTH); 00155 gplot = gplotCreate("/tmp/junkerode", GPLOT_PNG, 00156 "Erosion time vs sel size", "size", "time (ms)"); 00157 gplotAddPlot(gplot, nax, nac1, GPLOT_LINES, "linear rasterop"); 00158 gplotAddPlot(gplot, nax, nac2, GPLOT_LINES, "composite rasterop"); 00159 gplotAddPlot(gplot, nax, nac3, GPLOT_LINES, "linear dwa"); 00160 gplotAddPlot(gplot, nax, nac4, GPLOT_LINES, "composite dwa"); 00161 gplotMakeOutput(gplot); 00162 gplotDestroy(&gplot); 00163 numaDestroy(&nac1); 00164 numaDestroy(&nac2); 00165 numaDestroy(&nac3); 00166 numaDestroy(&nac4); 00167 00168 /* --------- opening ----------*/ 00169 00170 numaEmpty(na1); 00171 numaEmpty(na2); 00172 numaEmpty(na3); 00173 numaEmpty(na4); 00174 for (i = 0; i < nsels / 2; i++) 00175 { 00176 sel = selaGetSel(selalinear, i); 00177 selGetParameters(sel, &sy, &sx, NULL, NULL); 00178 selname = selGetName(sel); 00179 fprintf(stderr, " %d .", i); 00180 00181 startTimer(); 00182 for (j = 0; j < NTIMES; j++) 00183 pixOpen(pixt, pixs, sel); 00184 time = fact * stopTimer(); 00185 numaAddNumber(na1, time); 00186 00187 startTimer(); 00188 for (j = 0; j < NTIMES; j++) 00189 pixOpenCompBrick(pixt, pixs, sx, sy); 00190 time = fact * stopTimer(); 00191 numaAddNumber(na2, time); 00192 00193 startTimer(); 00194 for (j = 0; j < NTIMES; j++) 00195 pixMorphDwa_3(pixt, pixs, L_MORPH_OPEN, selname); 00196 time = fact * stopTimer(); 00197 numaAddNumber(na3, time); 00198 00199 startTimer(); 00200 for (j = 0; j < NTIMES; j++) 00201 pixOpenCompBrickDwa(pixt, pixs, sx, sy); 00202 time = fact * stopTimer(); 00203 numaAddNumber(na4, time); 00204 } 00205 00206 nac1 = numaWindowedMean(na1, HALFWIDTH); 00207 nac2 = numaWindowedMean(na2, HALFWIDTH); 00208 nac3 = numaWindowedMean(na3, HALFWIDTH); 00209 nac4 = numaWindowedMean(na4, HALFWIDTH); 00210 gplot = gplotCreate("/tmp/junkopen", GPLOT_PNG, 00211 "Opening time vs sel size", "size", "time (ms)"); 00212 gplotAddPlot(gplot, nax, nac1, GPLOT_LINES, "linear rasterop"); 00213 gplotAddPlot(gplot, nax, nac2, GPLOT_LINES, "composite rasterop"); 00214 gplotAddPlot(gplot, nax, nac3, GPLOT_LINES, "linear dwa"); 00215 gplotAddPlot(gplot, nax, nac4, GPLOT_LINES, "composite dwa"); 00216 gplotMakeOutput(gplot); 00217 gplotDestroy(&gplot); 00218 numaDestroy(&nac1); 00219 numaDestroy(&nac2); 00220 numaDestroy(&nac3); 00221 numaDestroy(&nac4); 00222 00223 /* --------- closing ----------*/ 00224 00225 numaEmpty(na1); 00226 numaEmpty(na2); 00227 numaEmpty(na3); 00228 numaEmpty(na4); 00229 for (i = 0; i < nsels / 2; i++) 00230 { 00231 sel = selaGetSel(selalinear, i); 00232 selGetParameters(sel, &sy, &sx, NULL, NULL); 00233 selname = selGetName(sel); 00234 fprintf(stderr, " %d .", i); 00235 00236 startTimer(); 00237 for (j = 0; j < NTIMES; j++) 00238 pixClose(pixt, pixs, sel); 00239 time = fact * stopTimer(); 00240 numaAddNumber(na1, time); 00241 00242 startTimer(); 00243 for (j = 0; j < NTIMES; j++) 00244 pixCloseCompBrick(pixt, pixs, sx, sy); 00245 time = fact * stopTimer(); 00246 numaAddNumber(na2, time); 00247 00248 startTimer(); 00249 for (j = 0; j < NTIMES; j++) 00250 pixMorphDwa_3(pixt, pixs, L_MORPH_CLOSE, selname); 00251 time = fact * stopTimer(); 00252 numaAddNumber(na3, time); 00253 00254 startTimer(); 00255 for (j = 0; j < NTIMES; j++) 00256 pixCloseCompBrickDwa(pixt, pixs, sx, sy); 00257 time = fact * stopTimer(); 00258 numaAddNumber(na4, time); 00259 } 00260 00261 nac1 = numaWindowedMean(na1, HALFWIDTH); 00262 nac2 = numaWindowedMean(na2, HALFWIDTH); 00263 nac3 = numaWindowedMean(na3, HALFWIDTH); 00264 nac4 = numaWindowedMean(na4, HALFWIDTH); 00265 gplot = gplotCreate("/tmp/junkclose", GPLOT_PNG, 00266 "Closing time vs sel size", "size", "time (ms)"); 00267 gplotAddPlot(gplot, nax, nac1, GPLOT_LINES, "linear rasterop"); 00268 gplotAddPlot(gplot, nax, nac2, GPLOT_LINES, "composite rasterop"); 00269 gplotAddPlot(gplot, nax, nac3, GPLOT_LINES, "linear dwa"); 00270 gplotAddPlot(gplot, nax, nac4, GPLOT_LINES, "composite dwa"); 00271 gplotMakeOutput(gplot); 00272 gplotDestroy(&gplot); 00273 numaDestroy(&nac1); 00274 numaDestroy(&nac2); 00275 numaDestroy(&nac3); 00276 numaDestroy(&nac4); 00277 00278 00279 numaDestroy(&na1); 00280 numaDestroy(&na2); 00281 numaDestroy(&na3); 00282 numaDestroy(&na4); 00283 numaDestroy(&nax); 00284 selaDestroy(&selalinear); 00285 pixDestroy(&pixt); 00286 pixDestroy(&pixs); 00287 00288 /* Display the results together */ 00289 pixa = pixaCreate(0); 00290 pixs = pixRead("/tmp/junkdilate.png"); 00291 pixaAddPix(pixa, pixs, L_INSERT); 00292 pixs = pixRead("/tmp/junkerode.png"); 00293 pixaAddPix(pixa, pixs, L_INSERT); 00294 pixs = pixRead("/tmp/junkopen.png"); 00295 pixaAddPix(pixa, pixs, L_INSERT); 00296 pixs = pixRead("/tmp/junkclose.png"); 00297 pixaAddPix(pixa, pixs, L_INSERT); 00298 pixt = pixaDisplayTiledInRows(pixa, 32, 1500, 1.0, 0, 40, 3); 00299 pixWrite("/tmp/junktimings.png", pixt, IFF_PNG); 00300 pixDisplay(pixt, 100, 100); 00301 pixDestroy(&pixt); 00302 pixaDestroy(&pixa); 00303 return 0; 00304 } 00305