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 * ccthin1_reg.c 00018 * 00019 * Tests the "best" cc-preserving thinning functions. 00020 * Displays all the strong cc-preserving 3x3 Sels. 00021 */ 00022 00023 #include <stdio.h> 00024 #include <stdlib.h> 00025 #include "allheaders.h" 00026 00027 /* Sels for 4-connected thinning */ 00028 static const char *sel_4_1 = " x" 00029 "oCx" 00030 " x"; 00031 00032 static const char *sel_4_2 = " x" 00033 "oCx" 00034 " o "; 00035 00036 static const char *sel_4_3 = " o " 00037 "oCx" 00038 " x"; 00039 00040 static const char *sel_4_4 = " o " 00041 "oCx" 00042 " o "; 00043 00044 static const char *sel_4_5 = " ox" 00045 "oCx" 00046 " o "; 00047 00048 static const char *sel_4_6 = " o " 00049 "oCx" 00050 " ox"; 00051 00052 static const char *sel_4_7 = " xx" 00053 "oCx" 00054 " o "; 00055 00056 static const char *sel_4_8 = " x" 00057 "oCx" 00058 "o x"; 00059 00060 static const char *sel_4_9 = "o x" 00061 "oCx" 00062 " x"; 00063 00064 /* Sels for 8-connected thinning */ 00065 static const char *sel_8_1 = " x " 00066 "oCx" 00067 " x "; 00068 00069 static const char *sel_8_2 = " x " 00070 "oCx" 00071 "o "; 00072 00073 static const char *sel_8_3 = "o " 00074 "oCx" 00075 " x "; 00076 00077 static const char *sel_8_4 = "o " 00078 "oCx" 00079 "o "; 00080 00081 static const char *sel_8_5 = "o x" 00082 "oCx" 00083 "o "; 00084 00085 static const char *sel_8_6 = "o " 00086 "oCx" 00087 "o x"; 00088 00089 static const char *sel_8_7 = " x " 00090 "oCx" 00091 "oo "; 00092 00093 static const char *sel_8_8 = " x " 00094 "oCx" 00095 "ox "; 00096 00097 static const char *sel_8_9 = "ox " 00098 "oCx" 00099 " x "; 00100 00101 /* Sels for both 4 and 8-connected thinning */ 00102 static const char *sel_48_1 = " xx" 00103 "oCx" 00104 "oo "; 00105 00106 static const char *sel_48_2 = "o x" 00107 "oCx" 00108 "o x"; 00109 00110 00111 main(int argc, 00112 char **argv) 00113 { 00114 BOX *box; 00115 PIX *pix, *pixs, *pixd, *pixt; 00116 PIXA *pixa; 00117 SEL *sel, *sel1, *sel2, *sel3; 00118 SELA *sela4, *sela8, *sela48; 00119 static char mainName[] = "ccthin1_reg"; 00120 00121 if (argc != 1) 00122 exit(ERROR_INT(" Syntax: ccthin1_reg", mainName, 1)); 00123 00124 /* Generate and display all of the 4-cc sels */ 00125 sela4 = selaCreate(9); 00126 sel = selCreateFromString(sel_4_1, 3, 3, "sel_4_1"); 00127 selaAddSel(sela4, sel, NULL, 0); 00128 sel = selCreateFromString(sel_4_2, 3, 3, "sel_4_2"); 00129 selaAddSel(sela4, sel, NULL, 0); 00130 sel = selCreateFromString(sel_4_3, 3, 3, "sel_4_3"); 00131 selaAddSel(sela4, sel, NULL, 0); 00132 sel = selCreateFromString(sel_4_4, 3, 3, "sel_4_4"); 00133 selaAddSel(sela4, sel, NULL, 0); 00134 sel = selCreateFromString(sel_4_5, 3, 3, "sel_4_5"); 00135 selaAddSel(sela4, sel, NULL, 0); 00136 sel = selCreateFromString(sel_4_6, 3, 3, "sel_4_6"); 00137 selaAddSel(sela4, sel, NULL, 0); 00138 sel = selCreateFromString(sel_4_7, 3, 3, "sel_4_7"); 00139 selaAddSel(sela4, sel, NULL, 0); 00140 sel = selCreateFromString(sel_4_8, 3, 3, "sel_4_8"); 00141 selaAddSel(sela4, sel, NULL, 0); 00142 sel = selCreateFromString(sel_4_9, 3, 3, "sel_4_9"); 00143 selaAddSel(sela4, sel, NULL, 0); 00144 pixt = selaDisplayInPix(sela4, 35, 3, 15, 3); 00145 pixWrite("/tmp/junkallsel4.png", pixt, IFF_PNG); 00146 pixDestroy(&pixt); 00147 selaDestroy(&sela4); 00148 00149 /* Generate and display all of the 8-cc sels */ 00150 sela8 = selaCreate(9); 00151 sel = selCreateFromString(sel_8_1, 3, 3, "sel_8_1"); 00152 selaAddSel(sela8, sel, NULL, 0); 00153 sel = selCreateFromString(sel_8_2, 3, 3, "sel_8_2"); 00154 selaAddSel(sela8, sel, NULL, 0); 00155 sel = selCreateFromString(sel_8_3, 3, 3, "sel_8_3"); 00156 selaAddSel(sela8, sel, NULL, 0); 00157 sel = selCreateFromString(sel_8_4, 3, 3, "sel_8_4"); 00158 selaAddSel(sela8, sel, NULL, 0); 00159 sel = selCreateFromString(sel_8_5, 3, 3, "sel_8_5"); 00160 selaAddSel(sela8, sel, NULL, 0); 00161 sel = selCreateFromString(sel_8_6, 3, 3, "sel_8_6"); 00162 selaAddSel(sela8, sel, NULL, 0); 00163 sel = selCreateFromString(sel_8_7, 3, 3, "sel_8_7"); 00164 selaAddSel(sela8, sel, NULL, 0); 00165 sel = selCreateFromString(sel_8_8, 3, 3, "sel_8_8"); 00166 selaAddSel(sela8, sel, NULL, 0); 00167 sel = selCreateFromString(sel_8_9, 3, 3, "sel_8_9"); 00168 selaAddSel(sela8, sel, NULL, 0); 00169 pixt = selaDisplayInPix(sela8, 35, 3, 15, 3); 00170 pixWrite("/tmp/junkallsel8.png", pixt, IFF_PNG); 00171 pixDestroy(&pixt); 00172 selaDestroy(&sela8); 00173 00174 /* Generate and display all of the 4 and 8-cc preserving sels */ 00175 sela48 = selaCreate(3); 00176 sel = selCreateFromString(sel_48_1, 3, 3, "sel_48_1"); 00177 selaAddSel(sela48, sel, NULL, 0); 00178 sel = selCreateFromString(sel_48_2, 3, 3, "sel_48_2"); 00179 selaAddSel(sela48, sel, NULL, 0); 00180 pixt = selaDisplayInPix(sela48, 35, 3, 15, 4); 00181 pixWrite("/tmp/junkallsel48.png", pixt, IFF_PNG); 00182 pixDestroy(&pixt); 00183 selaDestroy(&sela48); 00184 00185 /* Generate and display three of the 4-cc sels and their rotations */ 00186 sela4 = selaCreate(3); 00187 sel = selCreateFromString(sel_4_1, 3, 3, "sel_4_1"); 00188 sel1 = selRotateOrth(sel, 1); 00189 sel2 = selRotateOrth(sel, 2); 00190 sel3 = selRotateOrth(sel, 3); 00191 selaAddSel(sela4, sel, NULL, 0); 00192 selaAddSel(sela4, sel1, "sel_4_1_90", 0); 00193 selaAddSel(sela4, sel2, "sel_4_1_180", 0); 00194 selaAddSel(sela4, sel3, "sel_4_1_270", 0); 00195 sel = selCreateFromString(sel_4_2, 3, 3, "sel_4_2"); 00196 sel1 = selRotateOrth(sel, 1); 00197 sel2 = selRotateOrth(sel, 2); 00198 sel3 = selRotateOrth(sel, 3); 00199 selaAddSel(sela4, sel, NULL, 0); 00200 selaAddSel(sela4, sel1, "sel_4_2_90", 0); 00201 selaAddSel(sela4, sel2, "sel_4_2_180", 0); 00202 selaAddSel(sela4, sel3, "sel_4_2_270", 0); 00203 sel = selCreateFromString(sel_4_3, 3, 3, "sel_4_3"); 00204 sel1 = selRotateOrth(sel, 1); 00205 sel2 = selRotateOrth(sel, 2); 00206 sel3 = selRotateOrth(sel, 3); 00207 selaAddSel(sela4, sel, NULL, 0); 00208 selaAddSel(sela4, sel1, "sel_4_3_90", 0); 00209 selaAddSel(sela4, sel2, "sel_4_3_180", 0); 00210 selaAddSel(sela4, sel3, "sel_4_3_270", 0); 00211 pixt = selaDisplayInPix(sela4, 35, 3, 15, 4); 00212 pixWrite("/tmp/junksel4.png", pixt, IFF_PNG); 00213 pixDestroy(&pixt); 00214 selaDestroy(&sela4); 00215 00216 /* Generate and display four of the 8-cc sels and their rotations */ 00217 sela8 = selaCreate(4); 00218 sel = selCreateFromString(sel_8_2, 3, 3, "sel_8_2"); 00219 sel1 = selRotateOrth(sel, 1); 00220 sel2 = selRotateOrth(sel, 2); 00221 sel3 = selRotateOrth(sel, 3); 00222 selaAddSel(sela8, sel, NULL, 0); 00223 selaAddSel(sela8, sel1, "sel_8_2_90", 0); 00224 selaAddSel(sela8, sel2, "sel_8_2_180", 0); 00225 selaAddSel(sela8, sel3, "sel_8_2_270", 0); 00226 sel = selCreateFromString(sel_8_3, 3, 3, "sel_8_3"); 00227 sel1 = selRotateOrth(sel, 1); 00228 sel2 = selRotateOrth(sel, 2); 00229 sel3 = selRotateOrth(sel, 3); 00230 selaAddSel(sela8, sel, NULL, 0); 00231 selaAddSel(sela8, sel1, "sel_8_3_90", 0); 00232 selaAddSel(sela8, sel2, "sel_8_3_180", 0); 00233 selaAddSel(sela8, sel3, "sel_8_3_270", 0); 00234 sel = selCreateFromString(sel_8_5, 3, 3, "sel_8_5"); 00235 sel1 = selRotateOrth(sel, 1); 00236 sel2 = selRotateOrth(sel, 2); 00237 sel3 = selRotateOrth(sel, 3); 00238 selaAddSel(sela8, sel, NULL, 0); 00239 selaAddSel(sela8, sel1, "sel_8_5_90", 0); 00240 selaAddSel(sela8, sel2, "sel_8_5_180", 0); 00241 selaAddSel(sela8, sel3, "sel_8_5_270", 0); 00242 sel = selCreateFromString(sel_8_6, 3, 3, "sel_8_6"); 00243 sel1 = selRotateOrth(sel, 1); 00244 sel2 = selRotateOrth(sel, 2); 00245 sel3 = selRotateOrth(sel, 3); 00246 selaAddSel(sela8, sel, NULL, 0); 00247 selaAddSel(sela8, sel1, "sel_8_6_90", 0); 00248 selaAddSel(sela8, sel2, "sel_8_6_180", 0); 00249 selaAddSel(sela8, sel3, "sel_8_6_270", 0); 00250 pixt = selaDisplayInPix(sela8, 35, 3, 15, 4); 00251 pixWrite("/tmp/junksel8.png", pixt, IFF_PNG); 00252 pixDestroy(&pixt); 00253 selaDestroy(&sela8); 00254 00255 /* Test the best 4 and 8 cc thinning */ 00256 pixDisplayWrite(NULL, 0); 00257 if ((pix = pixRead("feyn.tif")) == NULL) 00258 exit(ERROR_INT("pix not made", mainName, 1)); 00259 box = boxCreate(683, 799, 970, 479); 00260 pixs = pixClipRectangle(pix, box, NULL); 00261 pixDisplayWrite(pixs, 1); 00262 00263 pixt = pixThin(pixs, L_THIN_FG, 4, 0); 00264 pixDisplayWrite(pixt, 1); 00265 pixDestroy(&pixt); 00266 pixt = pixThin(pixs, L_THIN_BG, 4, 0); 00267 pixDisplayWrite(pixt, 1); 00268 pixDestroy(&pixt); 00269 00270 pixt = pixThin(pixs, L_THIN_FG, 8, 0); 00271 pixDisplayWrite(pixt, 1); 00272 pixDestroy(&pixt); 00273 pixt = pixThin(pixs, L_THIN_BG, 8, 0); 00274 pixDisplayWrite(pixt, 1); 00275 pixDestroy(&pixt); 00276 00277 /* Display tiled */ 00278 pixa = pixaReadFiles("/tmp", "junk_write_display"); 00279 pixd = pixaDisplayTiledAndScaled(pixa, 8, 500, 1, 0, 25, 2); 00280 pixWrite("/tmp/junktiles.jpg", pixd, IFF_JFIF_JPEG); 00281 pixDestroy(&pixd); 00282 pixaDestroy(&pixa); 00283 pixDestroy(&pix); 00284 pixDestroy(&pixs); 00285 boxDestroy(&box); 00286 00287 pixDisplayMultiple("/tmp/junk_write_display*"); 00288 return 0; 00289 } 00290 00291