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 * findpattern3.c 00018 * 00019 * findpattern3 00020 * 00021 * This is setup with input parameters to work on feyn.tif. 00022 * 00023 * This uses pixGenerateSelBoundary() to generate the sels. 00024 * 00025 * (1) We extract a "c" bitmap, generate a hit-miss sel, and 00026 * then produce several 4 bpp colormapped renditions, 00027 * with the pattern either removed or highlighted. 00028 * 00029 * (2) We do the same with the word "Caltech". 00030 */ 00031 00032 #include <stdio.h> 00033 #include <stdlib.h> 00034 #include "allheaders.h" 00035 00036 /* for pixDisplayHitMissSel() */ 00037 static const l_uint32 HitColor = 0x33aa4400; 00038 static const l_uint32 MissColor = 0xaa44bb00; 00039 00040 00041 main(int argc, 00042 char **argv) 00043 { 00044 BOX *box; 00045 PIX *pixs, *pixc, *pixp, *pixsel, *pixhmt; 00046 PIX *pixd1, *pixd2, *pixd3; 00047 SEL *selhm; 00048 static char mainName[] = "findpattern3"; 00049 00050 if (argc != 1) 00051 exit(ERROR_INT(" Syntax: findpattern3", mainName, 1)); 00052 00053 if ((pixs = pixRead("feyn.tif")) == NULL) 00054 exit(ERROR_INT("pixs not made", mainName, 1)); 00055 00056 /* -------------------------------------------- * 00057 * Extract the pattern for a single character * 00058 * ---------------------------------------------*/ 00059 box = boxCreate(599, 1055, 18, 23); 00060 pixc = pixClipRectangle(pixs, box, NULL); 00061 00062 /* Make a hit-miss sel */ 00063 selhm = pixGenerateSelBoundary(pixc, 1, 2, 2, 2, 1, 1, 0, 0, &pixp); 00064 00065 /* Display the sel */ 00066 pixsel = pixDisplayHitMissSel(pixp, selhm, 7, HitColor, MissColor); 00067 pixDisplay(pixsel, 200, 200); 00068 pixWrite("/tmp/junkpixsel1", pixsel, IFF_PNG); 00069 00070 /* Use the Sel to find all instances in the page */ 00071 startTimer(); 00072 pixhmt = pixHMT(NULL, pixs, selhm); 00073 fprintf(stderr, "Time to find patterns = %7.3f\n", stopTimer()); 00074 00075 /* Color each instance at full res */ 00076 pixd1 = pixDisplayMatchedPattern(pixs, pixp, pixhmt, selhm->cx, 00077 selhm->cy, 0x0000ff00, 1.0, 5); 00078 pixWrite("/tmp/junkpixd11", pixd1, IFF_PNG); 00079 00080 /* Color each instance at 0.3 scale */ 00081 pixd2 = pixDisplayMatchedPattern(pixs, pixp, pixhmt, selhm->cx, 00082 selhm->cy, 0x0000ff00, 0.5, 5); 00083 pixWrite("/tmp/junkpixd12", pixd2, IFF_PNG); 00084 00085 /* Remove each instance from the input image */ 00086 pixd3 = pixCopy(NULL, pixs); 00087 pixRemoveMatchedPattern(pixd3, pixp, pixhmt, selhm->cx, 00088 selhm->cy, 1); 00089 pixWrite("/tmp/junkpixr1", pixd3, IFF_PNG); 00090 00091 boxDestroy(&box); 00092 selDestroy(&selhm); 00093 pixDestroy(&pixc); 00094 pixDestroy(&pixp); 00095 pixDestroy(&pixsel); 00096 pixDestroy(&pixhmt); 00097 pixDestroy(&pixd1); 00098 pixDestroy(&pixd2); 00099 pixDestroy(&pixd3); 00100 00101 00102 /* -------------------------------------------- * 00103 * Extract the pattern for a word * 00104 * ---------------------------------------------*/ 00105 box = boxCreate(208, 872, 130, 35); 00106 pixc = pixClipRectangle(pixs, box, NULL); 00107 00108 /* Make a hit-miss sel */ 00109 selhm = pixGenerateSelBoundary(pixc, 2, 2, 1, 4, 1, 1, 0, 0, &pixp); 00110 00111 /* Display the sel */ 00112 pixsel = pixDisplayHitMissSel(pixp, selhm, 7, HitColor, MissColor); 00113 pixDisplay(pixsel, 200, 200); 00114 pixWrite("/tmp/junkpixsel2", pixsel, IFF_PNG); 00115 00116 /* Use the Sel to find all instances in the page */ 00117 startTimer(); 00118 pixhmt = pixHMT(NULL, pixs, selhm); 00119 fprintf(stderr, "Time to find word patterns = %7.3f\n", stopTimer()); 00120 00121 /* Color each instance at full res */ 00122 pixd1 = pixDisplayMatchedPattern(pixs, pixp, pixhmt, selhm->cx, 00123 selhm->cy, 0x0000ff00, 1.0, 5); 00124 pixWrite("/tmp/junkpixd21", pixd1, IFF_PNG); 00125 00126 /* Color each instance at 0.3 scale */ 00127 pixd2 = pixDisplayMatchedPattern(pixs, pixp, pixhmt, selhm->cx, 00128 selhm->cy, 0x0000ff00, 0.5, 5); 00129 pixWrite("/tmp/junkpixd22", pixd2, IFF_PNG); 00130 00131 /* Remove each instance from the input image */ 00132 pixd3 = pixCopy(NULL, pixs); 00133 pixRemoveMatchedPattern(pixd3, pixp, pixhmt, selhm->cx, 00134 selhm->cy, 1); 00135 pixWrite("/tmp/junkpixr2", pixd3, IFF_PNG); 00136 00137 selDestroy(&selhm); 00138 boxDestroy(&box); 00139 pixDestroy(&pixc); 00140 pixDestroy(&pixp); 00141 pixDestroy(&pixsel); 00142 pixDestroy(&pixhmt); 00143 pixDestroy(&pixd1); 00144 pixDestroy(&pixd2); 00145 pixDestroy(&pixd3); 00146 pixDestroy(&pixs); 00147 return 0; 00148 } 00149