Leptonica 1.68
C Image Processing Library

threshnorm_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  * threshnorm__reg.c
00018  *
00019  *      Regression test for adaptive threshold normalization.
00020  */
00021 
00022 #include <string.h>
00023 #include "allheaders.h"
00024 
00025 static void AddTestSet(PIXA *pixa, PIX *pixs,
00026                        l_int32 filtertype, l_int32 edgethresh,
00027                        l_int32 smoothx, l_int32 smoothy,
00028                        l_float32 gamma, l_int32 minval,
00029                        l_int32 maxval, l_int32 targetthresh);
00030 
00031 main(int    argc,
00032      char **argv)
00033 {
00034 PIX          *pixs, *pixd;
00035 PIXA         *pixa;
00036 L_REGPARAMS  *rp;
00037 
00038     if (regTestSetup(argc, argv, &rp))
00039         return 1;
00040 
00041     pixs = pixRead("stampede2.jpg");
00042     pixa = pixaCreate(0);
00043     pixSaveTiled(pixs, pixa, 1, 1, 20, 8);
00044             
00045     AddTestSet(pixa, pixs, L_SOBEL_EDGE, 18, 40, 40, 0.7, -25, 280, 128);
00046     AddTestSet(pixa, pixs, L_TWO_SIDED_EDGE, 18, 40, 40, 0.7, -25, 280, 128);
00047     AddTestSet(pixa, pixs, L_SOBEL_EDGE, 10, 40, 40, 0.7, -15, 305, 128);
00048     AddTestSet(pixa, pixs, L_TWO_SIDED_EDGE, 10, 40, 40, 0.7, -15, 305, 128);
00049     AddTestSet(pixa, pixs, L_SOBEL_EDGE, 15, 40, 40, 0.6, -45, 285, 158);
00050     AddTestSet(pixa, pixs, L_TWO_SIDED_EDGE, 15, 40, 40, 0.6, -45, 285, 158);
00051 
00052     pixDestroy(&pixs);
00053     pixd = pixaDisplay(pixa, 0, 0);
00054     regTestWritePixAndCheck(rp, pixd, IFF_JFIF_JPEG);  /* 0 */
00055     pixDisplayWithTitle(pixd, 100, 100, NULL, rp->display);
00056 
00057     pixDestroy(&pixd);
00058     pixaDestroy(&pixa);
00059     regTestCleanup(rp);
00060     return 0;
00061 }
00062 
00063 
00064 void
00065 AddTestSet(PIXA      *pixa,
00066            PIX       *pixs,
00067            l_int32    filtertype,
00068            l_int32    edgethresh,
00069            l_int32    smoothx,
00070            l_int32    smoothy,
00071            l_float32  gamma,
00072            l_int32    minval,
00073            l_int32    maxval,
00074            l_int32    targetthresh)
00075 {
00076 PIX  *pixb, *pixd, *pixth;
00077 
00078     pixThresholdSpreadNorm(pixs, filtertype, edgethresh,
00079                            smoothx, smoothy, gamma, minval,
00080                            maxval, targetthresh, &pixth, NULL, &pixd); 
00081     pixSaveTiled(pixth, pixa, 1, 1, 20, 0);
00082     pixSaveTiled(pixd, pixa, 1, 0, 20, 0);
00083     pixb = pixThresholdToBinary(pixd, targetthresh - 20);
00084     pixSaveTiled(pixb, pixa, 1, 0, 20, 0);
00085     pixDestroy(&pixb);
00086     pixb = pixThresholdToBinary(pixd, targetthresh);
00087     pixSaveTiled(pixb, pixa, 1, 0, 20, 0);
00088     pixDestroy(&pixb);
00089     pixb = pixThresholdToBinary(pixd, targetthresh + 20);
00090     pixSaveTiled(pixb, pixa, 1, 0, 20, 0);
00091     pixDestroy(&pixb);
00092     pixb = pixThresholdToBinary(pixd, targetthresh + 40);
00093     pixSaveTiled(pixb, pixa, 1, 0, 20, 0);
00094     pixDestroy(&pixb);
00095     pixDestroy(&pixth);
00096     pixDestroy(&pixd);
00097     return;
00098 }
00099 
00100 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines