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 * quadtreetest.c 00018 * 00019 * test of quadtree statistical functions 00020 */ 00021 00022 #include "allheaders.h" 00023 00024 main(int argc, 00025 char **argv) 00026 { 00027 l_int32 i, j, w, h, error; 00028 l_float32 val1, val2; 00029 l_float32 val00, val10, val01, val11, valc00, valc10, valc01, valc11; 00030 PIX *pixs, *pixg, *pixt1, *pixt2, *pixt3, *pixt4, *pixt5; 00031 FPIXA *fpixam, *fpixav, *fpixarv; 00032 BOXAA *baa; 00033 static char mainName[] = "quadtreetest"; 00034 00035 if (argc != 1) 00036 return ERROR_INT(" Syntax: quadtreetest", mainName, 1); 00037 00038 /* Test generation of quadtree regions. */ 00039 baa = boxaaQuadtreeRegions(1000, 500, 3); 00040 boxaaWriteStream(stderr, baa); 00041 boxaaDestroy(&baa); 00042 baa = boxaaQuadtreeRegions(1001, 501, 3); 00043 boxaaWriteStream(stderr, baa); 00044 boxaaDestroy(&baa); 00045 00046 /* Test quadtree stats generation */ 00047 #if 1 00048 pixs = pixRead("rabi.png"); 00049 pixg = pixScaleToGray4(pixs); 00050 #else 00051 pixs = pixRead("test24.jpg"); 00052 pixg = pixConvertTo8(pixs, 0); 00053 #endif 00054 pixQuadtreeMean(pixg, 8, NULL, &fpixam); 00055 pixt1 = fpixaDisplayQuadtree(fpixam, 4); 00056 pixDisplay(pixt1, 100, 0); 00057 pixWrite("/tmp/quadtree1.png", pixt1, IFF_PNG); 00058 pixQuadtreeVariance(pixg, 8, NULL, NULL, &fpixav, &fpixarv); 00059 pixt2 = fpixaDisplayQuadtree(fpixav, 4); 00060 pixDisplay(pixt2, 100, 200); 00061 pixWrite("/tmp/quadtree2.png", pixt2, IFF_PNG); 00062 pixt3 = fpixaDisplayQuadtree(fpixarv, 4); 00063 pixDisplay(pixt3, 100, 400); 00064 pixWrite("/tmp/quadtree3.png", pixt3, IFF_PNG); 00065 00066 /* Compare with fixed-size tiling at a resolution corresponding 00067 * to the deepest level of the quadtree above */ 00068 pixt4 = pixGetAverageTiled(pixg, 5, 6, L_MEAN_ABSVAL); 00069 pixt5 = pixExpandReplicate(pixt4, 4); 00070 pixWrite("/tmp/quadtree4.png", pixt5, IFF_PNG); 00071 pixDisplay(pixt5, 800, 0); 00072 pixDestroy(&pixt4); 00073 pixDestroy(&pixt5); 00074 pixt4 = pixGetAverageTiled(pixg, 5, 6, L_STANDARD_DEVIATION); 00075 pixt5 = pixExpandReplicate(pixt4, 4); 00076 pixWrite("/tmp/quadtree5.png", pixt5, IFF_PNG); 00077 pixDisplay(pixt5, 800, 400); 00078 00079 /* Test quadtree parent/child access */ 00080 error = FALSE; 00081 fpixaGetFPixDimensions(fpixam, 4, &w, &h); 00082 for (i = 0; i < w; i += 2) { 00083 for (j = 0; j < h; j += 2) { 00084 quadtreeGetParent(fpixam, 4, j, i, &val1); 00085 fpixaGetPixel(fpixam, 3, j / 2, i / 2, &val2); 00086 if (val1 != val2) error = TRUE; 00087 } 00088 } 00089 if (error) 00090 fprintf(stderr, "\n======================\nError: parent access\n"); 00091 else 00092 fprintf(stderr, "\n======================\nSuccess: parent access\n"); 00093 error = FALSE; 00094 for (i = 0; i < w; i++) { 00095 for (j = 0; j < h; j++) { 00096 quadtreeGetChildren(fpixam, 4, j, i, 00097 &val00, &val10, &val01, &val11); 00098 fpixaGetPixel(fpixam, 5, 2 * j, 2 * i, &valc00); 00099 fpixaGetPixel(fpixam, 5, 2 * j + 1, 2 * i, &valc10); 00100 fpixaGetPixel(fpixam, 5, 2 * j, 2 * i + 1, &valc01); 00101 fpixaGetPixel(fpixam, 5, 2 * j + 1, 2 * i + 1, &valc11); 00102 if ((val00 != valc00) || (val10 != valc10) || 00103 (val01 != valc01) || (val11 != valc11)) 00104 error = TRUE; 00105 } 00106 } 00107 if (error) 00108 fprintf(stderr, "Error: child access\n======================\n"); 00109 else 00110 fprintf(stderr, "Success: child access\n======================\n"); 00111 00112 pixDestroy(&pixs); 00113 pixDestroy(&pixg); 00114 pixDestroy(&pixt1); 00115 pixDestroy(&pixt2); 00116 pixDestroy(&pixt3); 00117 pixDestroy(&pixt4); 00118 pixDestroy(&pixt5); 00119 fpixaDestroy(&fpixam); 00120 fpixaDestroy(&fpixav); 00121 fpixaDestroy(&fpixarv); 00122 return 0; 00123 } 00124 00125