Leptonica 1.68
C Image Processing Library

splitcomp_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  * splitcomp_reg.c
00018  *
00019  *   Regression test for splittings of a single component and for an image
00020  *   composed of several components, using different components and
00021  *   parameters.  Note that:
00022  *      (1) All coverings must cover the fg of the mask.
00023  *      (2) The first set of parameters is small and generates
00024  *          a proper tiling, covering ONLY the mask fg.
00025  *      (3) The tilings generated on 90 degree rotated components
00026  *          are identical (rotated) to those on un-rotated components.
00027  */
00028 
00029 #include "allheaders.h"
00030 
00031 main(int    argc,
00032      char **argv)
00033 {
00034 l_int32       i, j, w, h;
00035 l_int32       minsum[5] =    { 2, 40, 50, 50, 70};
00036 l_int32       skipdist[5] =  { 5,  5, 10, 10, 30};
00037 l_int32       delta[5] =     { 2, 10, 10, 25, 40};
00038 l_int32       maxbg[5] =     {10, 15, 10, 20, 40};
00039 BOX          *box1, *box2, *box3, *box4;
00040 BOXA         *boxa;
00041 PIX          *pixs, *pixc, *pixt, *pixd, *pix32;
00042 PIXA         *pixas, *pixad;
00043 L_REGPARAMS  *rp;
00044 
00045     if (regTestSetup(argc, argv, &rp))
00046         return 1;
00047 
00048         /* Generate and save 1 bpp masks */
00049     pixas = pixaCreate(0);
00050     pixs = pixCreate(300, 250, 1);
00051     pixSetAll(pixs);
00052     box1 = boxCreate(50, 0, 140, 25);
00053     box2 = boxCreate(120, 100, 100, 25);
00054     box3 = boxCreate(75, 170, 80, 20);
00055     box4 = boxCreate(150, 80, 25, 70);
00056 
00057     pixClearInRect(pixs, box1);
00058     pixaAddPix(pixas, pixs, L_COPY);
00059     pixt = pixRotateOrth(pixs, 1);
00060     pixaAddPix(pixas, pixt, L_INSERT);
00061 
00062     pixClearInRect(pixs, box2);
00063     pixaAddPix(pixas, pixs, L_COPY);
00064     pixt = pixRotateOrth(pixs, 1);
00065     pixaAddPix(pixas, pixt, L_INSERT);
00066 
00067     pixClearInRect(pixs, box3);
00068     pixaAddPix(pixas, pixs, L_COPY);
00069     pixt = pixRotateOrth(pixs, 1);
00070     pixaAddPix(pixas, pixt, L_INSERT);
00071 
00072     pixClearInRect(pixs, box4);
00073     pixaAddPix(pixas, pixs, L_COPY);
00074     pixt = pixRotateOrth(pixs, 1);
00075     pixaAddPix(pixas, pixt, L_INSERT);
00076 
00077     boxDestroy(&box1);
00078     boxDestroy(&box2);
00079     boxDestroy(&box3);
00080     boxDestroy(&box4);
00081     pixDestroy(&pixs);
00082 
00083         /* Do 5 splittings on each of the 8 masks */
00084     pixad = pixaCreate(0);
00085     for (j = 0; j < 8; j++) {
00086         pixt = pixaGetPix(pixas, j, L_CLONE);
00087         pixGetDimensions(pixt, &w, &h, NULL);
00088         pix32 = pixCreate(w, h, 32);
00089         pixSetAll(pix32);
00090         pixPaintThroughMask(pix32, pixt, 0, 0, 0xc0c0c000);
00091         pixSaveTiled(pix32, pixad, 1, 1, 30, 32);
00092         for (i = 0; i < 5; i++) {
00093             pixc = pixCopy(NULL, pix32);
00094             boxa = pixSplitComponentIntoBoxa(pixt, NULL, minsum[i], skipdist[i],
00095                                              delta[i], maxbg[i], 0, 1);
00096 /*            boxaWriteStream(stderr, boxa); */
00097             pixd = pixBlendBoxaRandom(pixc, boxa, 0.4);
00098             pixRenderBoxaArb(pixd, boxa, 2, 255, 0, 0);
00099             pixSaveTiled(pixd, pixad, 1, 0, 30, 32);
00100             pixDestroy(&pixd);
00101             pixDestroy(&pixc);
00102             boxaDestroy(&boxa);
00103         }
00104         pixDestroy(&pixt);
00105         pixDestroy(&pix32);
00106     }
00107 
00108         /* Display results */
00109     pixd = pixaDisplay(pixad, 0, 0);
00110     regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 0 */
00111     pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00112     pixDestroy(&pixd);
00113     pixaDestroy(&pixad);
00114 
00115         /* Put the 8 masks all together, and split 5 ways */
00116     pixad = pixaCreate(0);
00117     pixs = pixaDisplayOnLattice(pixas, 325, 325);
00118     pixGetDimensions(pixs, &w, &h, NULL);
00119     pix32 = pixCreate(w, h, 32);
00120     pixSetAll(pix32);
00121     pixPaintThroughMask(pix32, pixs, 0, 0, 0xc0c0c000);
00122     pixSaveTiled(pix32, pixad, 1, 1, 30, 32);
00123     for (i = 0; i < 5; i++) {
00124         pixc = pixCopy(NULL, pix32);
00125         boxa = pixSplitIntoBoxa(pixs, minsum[i], skipdist[i],
00126                                 delta[i], maxbg[i], 0, 1);
00127 /*        boxaWriteStream(stderr, boxa); */
00128         pixd = pixBlendBoxaRandom(pixc, boxa, 0.4);
00129         pixRenderBoxaArb(pixd, boxa, 2, 255, 0, 0);
00130         pixSaveTiled(pixd, pixad, 1, 0, 30, 32);
00131         pixDestroy(&pixd);
00132         pixDestroy(&pixc);
00133         boxaDestroy(&boxa);
00134     }
00135     pixDestroy(&pix32);
00136     pixDestroy(&pixs);
00137 
00138         /* Display results */
00139     pixd = pixaDisplay(pixad, 0, 0);
00140     regTestWritePixAndCheck(rp, pixd, IFF_PNG);  /* 1 */
00141     pixDisplayWithTitle(pixd, 600, 100, NULL, rp->display);
00142     pixDestroy(&pixd);
00143     pixaDestroy(&pixad);
00144 
00145     pixaDestroy(&pixas);
00146     regTestCleanup(rp);
00147     return 0;
00148 }
00149 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines