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 * pixa1_reg.c 00018 * 00019 * Tests removal of connected components. 00020 */ 00021 00022 #include <stdio.h> 00023 #include <stdlib.h> 00024 #include "allheaders.h" 00025 00026 static const l_int32 CONNECTIVITY = 8; 00027 00028 00029 main(int argc, 00030 char **argv) 00031 { 00032 l_int32 size, i, n, n0; 00033 BOXA *boxa; 00034 GPLOT *gplot; 00035 NUMA *nax, *nay1, *nay2; 00036 PIX *pixs, *pixd; 00037 static char mainName[] = "pixa1_reg"; 00038 00039 if (argc != 1) 00040 exit(ERROR_INT(" Syntax: pixa1_reg", mainName, 1)); 00041 00042 if ((pixs = pixRead("feyn.tif")) == NULL) 00043 exit(ERROR_INT("pixs not made", mainName, 1)); 00044 00045 /* ---------------- Remove small components --------------- */ 00046 boxa = pixConnComp(pixs, NULL, 8); 00047 n0 = boxaGetCount(boxa); 00048 nax = numaMakeSequence(0, 2, 51); 00049 nay1 = numaCreate(51); 00050 nay2 = numaCreate(51); 00051 boxaDestroy(&boxa); 00052 00053 fprintf(stderr, "\n Select Large if Both\n"); 00054 fprintf(stderr, "Iter 0: n = %d\n", n0); 00055 numaAddNumber(nay1, n0); 00056 for (i = 1; i <= 50; i++) { 00057 size = 2 * i; 00058 pixd = pixSelectBySize(pixs, size, size, CONNECTIVITY, 00059 L_SELECT_IF_BOTH, L_SELECT_IF_GTE, NULL); 00060 boxa = pixConnComp(pixd, NULL, 8); 00061 n = boxaGetCount(boxa); 00062 numaAddNumber(nay1, n); 00063 fprintf(stderr, "Iter %d: n = %d\n", i, n); 00064 boxaDestroy(&boxa); 00065 pixDestroy(&pixd); 00066 } 00067 00068 fprintf(stderr, "\n Select Large if Either\n"); 00069 fprintf(stderr, "Iter 0: n = %d\n", n0); 00070 numaAddNumber(nay2, n0); 00071 for (i = 1; i <= 50; i++) { 00072 size = 2 * i; 00073 pixd = pixSelectBySize(pixs, size, size, CONNECTIVITY, 00074 L_SELECT_IF_EITHER, L_SELECT_IF_GTE, NULL); 00075 boxa = pixConnComp(pixd, NULL, 8); 00076 n = boxaGetCount(boxa); 00077 numaAddNumber(nay2, n); 00078 fprintf(stderr, "Iter %d: n = %d\n", i, n); 00079 boxaDestroy(&boxa); 00080 pixDestroy(&pixd); 00081 } 00082 00083 gplot = gplotCreate("/tmp/junkroot1", GPLOT_X11, 00084 "Select large: number of cc vs size removed", 00085 "min size", "number of c.c."); 00086 gplotAddPlot(gplot, nax, nay1, GPLOT_LINES, "select if both"); 00087 gplotAddPlot(gplot, nax, nay2, GPLOT_LINES, "select if either"); 00088 gplotMakeOutput(gplot); 00089 gplotDestroy(&gplot); 00090 00091 /* ---------------- Remove large components --------------- */ 00092 numaEmpty(nay1); 00093 numaEmpty(nay2); 00094 00095 fprintf(stderr, "\n Select Small if Both\n"); 00096 fprintf(stderr, "Iter 0: n = %d\n", 0); 00097 numaAddNumber(nay1, 0); 00098 for (i = 1; i <= 50; i++) { 00099 size = 2 * i; 00100 pixd = pixSelectBySize(pixs, size, size, CONNECTIVITY, 00101 L_SELECT_IF_BOTH, L_SELECT_IF_LTE, NULL); 00102 boxa = pixConnComp(pixd, NULL, 8); 00103 n = boxaGetCount(boxa); 00104 numaAddNumber(nay1, n); 00105 fprintf(stderr, "Iter %d: n = %d\n", i, n); 00106 boxaDestroy(&boxa); 00107 pixDestroy(&pixd); 00108 } 00109 00110 fprintf(stderr, "\n Select Small if Either\n"); 00111 fprintf(stderr, "Iter 0: n = %d\n", 0); 00112 numaAddNumber(nay2, 0); 00113 for (i = 1; i <= 50; i++) { 00114 size = 2 * i; 00115 pixd = pixSelectBySize(pixs, size, size, CONNECTIVITY, 00116 L_SELECT_IF_EITHER, L_SELECT_IF_LTE, NULL); 00117 boxa = pixConnComp(pixd, NULL, 8); 00118 n = boxaGetCount(boxa); 00119 numaAddNumber(nay2, n); 00120 fprintf(stderr, "Iter %d: n = %d\n", i, n); 00121 boxaDestroy(&boxa); 00122 pixDestroy(&pixd); 00123 } 00124 00125 gplot = gplotCreate("/tmp/junkroot2", GPLOT_X11, 00126 "Remove large: number of cc vs size removed", 00127 "min size", "number of c.c."); 00128 gplotAddPlot(gplot, nax, nay1, GPLOT_LINES, "select if both"); 00129 gplotAddPlot(gplot, nax, nay2, GPLOT_LINES, "select if either"); 00130 gplotMakeOutput(gplot); 00131 gplotDestroy(&gplot); 00132 00133 numaDestroy(&nax); 00134 numaDestroy(&nay1); 00135 numaDestroy(&nay2); 00136 pixDestroy(&pixs); 00137 exit(0); 00138 } 00139