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 * rotatetest1.c 00018 * 00019 * rotatetest1 filein angle(in degrees) fileout 00020 */ 00021 00022 #include <stdio.h> 00023 #include <stdlib.h> 00024 #include "allheaders.h" 00025 00026 #define NTIMES 180 00027 #define NITERS 3 00028 00029 00030 main(int argc, 00031 char **argv) 00032 { 00033 l_int32 i, w, h, d, rotflag; 00034 PIX *pixs, *pixt, *pixd; 00035 l_float32 angle, deg2rad, pops, ang; 00036 char *filein, *fileout; 00037 static char mainName[] = "rotatetest1"; 00038 00039 if (argc != 4) 00040 exit(ERROR_INT(" Syntax: rotatetest1 filein angle fileout", 00041 mainName, 1)); 00042 00043 filein = argv[1]; 00044 angle = atof(argv[2]); 00045 fileout = argv[3]; 00046 deg2rad = 3.1415926535 / 180.; 00047 00048 if ((pixs = pixRead(filein)) == NULL) 00049 exit(ERROR_INT("pix not made", mainName, 1)); 00050 if (pixGetDepth(pixs) == 1) { 00051 pixt = pixScaleToGray3(pixs); 00052 pixDestroy(&pixs); 00053 pixs = pixAddBorderGeneral(pixt, 1, 0, 1, 0, 255); 00054 pixDestroy(&pixt); 00055 } 00056 00057 pixGetDimensions(pixs, &w, &h, &d); 00058 fprintf(stderr, "w = %d, h = %d\n", w, h); 00059 00060 #if 0 00061 /* repertory of rotation operations to choose from */ 00062 pixd = pixRotateAM(pixs, deg2rad * angle, L_BRING_IN_WHITE); 00063 pixd = pixRotateAMColor(pixs, deg2rad * angle, 0xffffff00); 00064 pixd = pixRotateAMColorFast(pixs, deg2rad * angle, 255); 00065 pixd = pixRotateAMCorner(pixs, deg2rad * angle, L_BRING_IN_WHITE); 00066 pixd = pixRotateShear(pixs, w /2, h / 2, deg2rad * angle, 00067 L_BRING_IN_WHITE); 00068 pixd = pixRotate3Shear(pixs, w /2, h / 2, deg2rad * angle, 00069 L_BRING_IN_WHITE); 00070 pixRotateShearIP(pixs, w / 2, h / 2, deg2rad * angle); pixd = pixs; 00071 #endif 00072 00073 #if 0 00074 /* timing of shear rotation */ 00075 for (i = 0; i < NITERS; i++) { 00076 pixd = pixRotateShear(pixs, (i * w) / NITERS, 00077 (i * h) / NITERS, deg2rad * angle, 00078 L_BRING_IN_WHITE); 00079 pixDisplay(pixd, 100 + 20 * i, 100 + 20 * i); 00080 pixDestroy(&pixd); 00081 } 00082 #endif 00083 00084 #if 0 00085 /* timing of in-place shear rotation */ 00086 for (i = 0; i < NITERS; i++) { 00087 pixRotateShearIP(pixs, w/2, h/2, deg2rad * angle, L_BRING_IN_WHITE); 00088 /* pixRotateShearCenterIP(pixs, deg2rad * angle, L_BRING_IN_WHITE); */ 00089 pixDisplay(pixs, 100 + 20 * i, 100 + 20 * i); 00090 } 00091 pixd = pixs; 00092 if (pixGetDepth(pixd) == 1) 00093 pixWrite(fileout, pixd, IFF_PNG); 00094 else 00095 pixWrite(fileout, pixd, IFF_JFIF_JPEG); 00096 pixDestroy(&pixs); 00097 #endif 00098 00099 #if 0 00100 /* timing of various rotation operations (choose) */ 00101 startTimer(); 00102 w = pixGetWidth(pixs); 00103 h = pixGetHeight(pixs); 00104 for (i = 0; i < NTIMES; i++) { 00105 pixd = pixRotateShearCenter(pixs, deg2rad * angle, L_BRING_IN_WHITE); 00106 pixDestroy(&pixd); 00107 } 00108 pops = (l_float32)(w * h * NTIMES / 1000000.) / stopTimer(); 00109 fprintf(stderr, "vers. 1, mpops: %f\n", pops); 00110 startTimer(); 00111 w = pixGetWidth(pixs); 00112 h = pixGetHeight(pixs); 00113 for (i = 0; i < NTIMES; i++) { 00114 pixRotateShearIP(pixs, w/2, h/2, deg2rad * angle, L_BRING_IN_WHITE); 00115 } 00116 pops = (l_float32)(w * h * NTIMES / 1000000.) / stopTimer(); 00117 fprintf(stderr, "shear, mpops: %f\n", pops); 00118 pixWrite(fileout, pixs, IFF_PNG); 00119 for (i = 0; i < NTIMES; i++) { 00120 pixRotateShearIP(pixs, w/2, h/2, -deg2rad * angle, L_BRING_IN_WHITE); 00121 } 00122 pixWrite("/usr/tmp/junkout", pixs, IFF_PNG); 00123 #endif 00124 00125 #if 0 00126 /* area-mapping rotation operations */ 00127 pixd = pixRotateAM(pixs, deg2rad * angle, L_BRING_IN_WHITE); 00128 /* pixd = pixRotateAMColorFast(pixs, deg2rad * angle, 255); */ 00129 if (pixGetDepth(pixd) == 1) 00130 pixWrite(fileout, pixd, IFF_PNG); 00131 else 00132 pixWrite(fileout, pixd, IFF_JFIF_JPEG); 00133 #endif 00134 00135 #if 0 00136 /* compare the standard area-map color rotation with 00137 * the fast area-map color rotation, on a pixel basis */ 00138 { 00139 PIX *pix1, *pix2; 00140 NUMA *nar, *nag, *nab, *naseq; 00141 GPLOT *gplot; 00142 00143 startTimer(); 00144 pix1 = pixRotateAMColor(pixs, 0.12, 0xffffff00); 00145 fprintf(stderr, " standard color rotate: %7.2f sec\n", stopTimer()); 00146 pixWrite("junkcolor1", pix1, IFF_JFIF_JPEG); 00147 startTimer(); 00148 pix2 = pixRotateAMColorFast(pixs, 0.12, 0xffffff00); 00149 fprintf(stderr, " fast color rotate: %7.2f sec\n", stopTimer()); 00150 pixWrite("junkcolor2", pix2, IFF_JFIF_JPEG); 00151 pixd = pixAbsDifference(pix1, pix2); 00152 pixGetColorHistogram(pixd, 1, &nar, &nag, &nab); 00153 naseq = numaMakeSequence(0., 1., 256); 00154 gplot = gplotCreate("junk_absdiff", GPLOT_X11, "Number vs diff", 00155 "diff", "number"); 00156 gplotAddPlot(gplot, naseq, nar, GPLOT_POINTS, "red"); 00157 gplotAddPlot(gplot, naseq, nag, GPLOT_POINTS, "green"); 00158 gplotAddPlot(gplot, naseq, nab, GPLOT_POINTS, "blue"); 00159 gplotMakeOutput(gplot); 00160 pixDestroy(&pix1); 00161 pixDestroy(&pix2); 00162 pixDestroy(&pixd); 00163 numaDestroy(&nar); 00164 numaDestroy(&nag); 00165 numaDestroy(&nab); 00166 numaDestroy(&naseq); 00167 gplotDestroy(&gplot); 00168 } 00169 #endif 00170 00171 /* Do a succession of 180 7-degree rotations in a cw 00172 * direction, and unwind the result with another set in 00173 * a ccw direction. Although there is a considerable amount 00174 * of distortion after successive rotations, after all 00175 * 360 rotations, the resulting image is restored to 00176 * its original pristine condition! */ 00177 #if 1 00178 rotflag = L_ROTATE_AREA_MAP; 00179 /* rotflag = L_ROTATE_SHEAR; */ 00180 /* rotflag = L_ROTATE_SAMPLING; */ 00181 ang = 7.0 * deg2rad; 00182 pixGetDimensions(pixs, &w, &h, NULL); 00183 pixd = pixRotate(pixs, ang, rotflag, L_BRING_IN_WHITE, w, h); 00184 pixWrite("junkrot7", pixd, IFF_PNG); 00185 for (i = 1; i < 180; i++) { 00186 pixs = pixd; 00187 pixd = pixRotate(pixs, ang, rotflag, L_BRING_IN_WHITE, w, h); 00188 if ((i % 30) == 0) pixDisplay(pixd, 600, 0); 00189 pixDestroy(&pixs); 00190 } 00191 00192 pixWrite("junkspin", pixd, IFF_PNG); 00193 pixDisplay(pixd, 0, 0); 00194 00195 for (i = 0; i < 180; i++) { 00196 pixs = pixd; 00197 pixd = pixRotate(pixs, -ang, rotflag, L_BRING_IN_WHITE, w, h); 00198 if (i && (i % 30) == 0) pixDisplay(pixd, 600, 500); 00199 pixDestroy(&pixs); 00200 } 00201 00202 pixWrite("junkunspin", pixd, IFF_PNG); 00203 pixDisplay(pixd, 0, 500); 00204 pixDestroy(&pixd); 00205 #endif 00206 00207 return 0; 00208 } 00209