Leptonica 1.68
C Image Processing Library

seedspread_reg.c

Go to the documentation of this file.
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  *   seedspread_reg.c
00018  *
00019  *   Tests the seedspreading (voronoi finding & filling) function
00020  *   for both 4 and 8 connectivity.
00021  */
00022 
00023 #include "allheaders.h"
00024 
00025 #define  REDUCTION     1
00026 
00027 main(int    argc,
00028      char **argv)
00029 {
00030 l_int32       i, j, x, y, val;
00031 PIX          *pixsq, *pixs, *pixc, *pixd;
00032 PIXA         *pixa;
00033 L_REGPARAMS  *rp;
00034 
00035     if (regTestSetup(argc, argv, &rp))
00036         return 1;
00037 
00038     pixsq = pixCreate(3, 3, 32);
00039     pixSetAllArbitrary(pixsq, 0x00ff0000);
00040     pixa = pixaCreate(6);
00041 
00042         /* Moderately dense */
00043     pixs = pixCreate(300, 300, 8);
00044     for (i = 0; i < 100; i++) {
00045         x = (153 * i * i * i + 59) % 299;
00046         y = (117 * i * i * i + 241) % 299;
00047         val = (97 * i + 74) % 256;
00048         pixSetPixel(pixs, x, y, val);
00049     }
00050 
00051     pixd = pixSeedspread(pixs, 4);  /* 4-cc */
00052     pixc = pixConvertTo32(pixd);
00053     for (i = 0; i < 100; i++) {
00054         x = (153 * i * i * i + 59) % 299;
00055         y = (117 * i * i * i + 241) % 299;
00056         pixRasterop(pixc, x - 1, y - 1, 3, 3, PIX_SRC, pixsq, 0, 0);
00057     }
00058     pixSaveTiled(pixc, pixa, REDUCTION, 1, 20, 32);
00059     regTestWritePixAndCheck(rp, pixc, IFF_PNG);  /* 0 */
00060     pixDisplayWithTitle(pixc, 100, 100, "4-cc", rp->display);
00061     pixDestroy(&pixd);
00062     pixDestroy(&pixc);
00063 
00064     pixd = pixSeedspread(pixs, 8);  /* 8-cc */
00065     pixc = pixConvertTo32(pixd);
00066     for (i = 0; i < 100; i++) {
00067         x = (153 * i * i * i + 59) % 299;
00068         y = (117 * i * i * i + 241) % 299;
00069         pixRasterop(pixc, x - 1, y - 1, 3, 3, PIX_SRC, pixsq, 0, 0);
00070     }
00071     pixSaveTiled(pixc, pixa, REDUCTION, 0, 20, 0);
00072     regTestWritePixAndCheck(rp, pixc, IFF_PNG);  /* 1 */
00073     pixDisplayWithTitle(pixc, 410, 100, "8-cc", rp->display);
00074     pixDestroy(&pixd);
00075     pixDestroy(&pixc);
00076     pixDestroy(&pixs);
00077 
00078         /* Regular lattice */
00079     pixs = pixCreate(200, 200, 8);
00080     for (i = 5; i <= 195; i += 10) {
00081         for (j = 5; j <= 195; j += 10) {
00082             pixSetPixel(pixs, i, j, (7 * i + 17 * j) % 255);
00083         }
00084     }
00085     pixd = pixSeedspread(pixs, 4);  /* 4-cc */
00086     pixc = pixConvertTo32(pixd);
00087     for (i = 5; i <= 195; i += 10) {
00088         for (j = 5; j <= 195; j += 10) {
00089             pixRasterop(pixc, j - 1, i - 1, 3, 3, PIX_SRC, pixsq, 0, 0);
00090         }
00091     }
00092     pixSaveTiled(pixc, pixa, REDUCTION, 1, 20, 0);
00093     regTestWritePixAndCheck(rp, pixc, IFF_PNG);  /* 2 */
00094     pixDisplayWithTitle(pixc, 100, 430, "4-cc", rp->display);
00095     pixDestroy(&pixd);
00096     pixDestroy(&pixc);
00097 
00098     pixd = pixSeedspread(pixs, 8);  /* 8-cc */
00099     pixc = pixConvertTo32(pixd);
00100     for (i = 5; i <= 195; i += 10) {
00101         for (j = 5; j <= 195; j += 10) {
00102             pixRasterop(pixc, j - 1, i - 1, 3, 3, PIX_SRC, pixsq, 0, 0);
00103         }
00104     }
00105     pixSaveTiled(pixc, pixa, REDUCTION, 0, 20, 0);
00106     regTestWritePixAndCheck(rp, pixc, IFF_PNG);  /* 3 */
00107     pixDisplayWithTitle(pixc, 310, 430, "8-cc", rp->display);
00108     pixDestroy(&pixd);
00109     pixDestroy(&pixc);
00110     pixDestroy(&pixs);
00111 
00112         /* Very sparse points */
00113     pixs = pixCreate(200, 200, 8);
00114     pixSetPixel(pixs, 60, 20, 90);
00115     pixSetPixel(pixs, 160, 40, 130);
00116     pixSetPixel(pixs, 80, 80, 205);
00117     pixSetPixel(pixs, 40, 160, 115);
00118     pixd = pixSeedspread(pixs, 4);  /* 4-cc */
00119     pixc = pixConvertTo32(pixd);
00120     pixRasterop(pixc, 60 - 1, 20 - 1, 3, 3, PIX_SRC, pixsq, 0, 0);
00121     pixRasterop(pixc, 160 - 1, 40 - 1, 3, 3, PIX_SRC, pixsq, 0, 0);
00122     pixRasterop(pixc, 80 - 1, 80 - 1, 3, 3, PIX_SRC, pixsq, 0, 0);
00123     pixRasterop(pixc, 40 - 1, 160 - 1, 3, 3, PIX_SRC, pixsq, 0, 0);
00124     pixSaveTiled(pixc, pixa, REDUCTION, 1, 20, 0);
00125     regTestWritePixAndCheck(rp, pixc, IFF_PNG);  /* 4 */
00126     pixDisplayWithTitle(pixc, 100, 600, "4-cc", rp->display);
00127     pixDestroy(&pixd);
00128     pixDestroy(&pixc);
00129 
00130     pixd = pixSeedspread(pixs, 8);  /* 8-cc */
00131     pixc = pixConvertTo32(pixd);
00132     pixRasterop(pixc, 60 - 1, 20 - 1, 3, 3, PIX_SRC, pixsq, 0, 0);
00133     pixRasterop(pixc, 160 - 1, 40 - 1, 3, 3, PIX_SRC, pixsq, 0, 0);
00134     pixRasterop(pixc, 80 - 1, 80 - 1, 3, 3, PIX_SRC, pixsq, 0, 0);
00135     pixRasterop(pixc, 40 - 1, 160 - 1, 3, 3, PIX_SRC, pixsq, 0, 0);
00136     pixSaveTiled(pixc, pixa, REDUCTION, 0, 20, 0);
00137     regTestWritePixAndCheck(rp, pixc, IFF_PNG);  /* 5 */
00138     pixDisplayWithTitle(pixc, 310, 660, "8-cc", rp->display);
00139     pixDestroy(&pixd);
00140     pixDestroy(&pixc);
00141     pixDestroy(&pixs);
00142     pixDestroy(&pixsq);
00143 
00144     pixd = pixaDisplay(pixa, 0, 0);
00145     regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 6 */
00146     pixDisplayWithTitle(pixc, 720, 100, "Final", rp->display);
00147 
00148     pixaDestroy(&pixa);
00149     pixDestroy(&pixd);
00150     regTestCleanup(rp);
00151     return 0;
00152 }
00153 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines