Leptonica 1.68
C Image Processing Library

fhmtauto_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 /*
00018  * fhmtauto_reg.c
00019  *
00020  *    Basic regression test for hit-miss transform: rasterops & dwa.
00021  *
00022  *    Tests hmt from a set of hmt structuring elements
00023  *    by comparing the full image rasterop results with the
00024  *    automatically generated dwa results.
00025  *
00026  *    Results must be identical for all operations.
00027  */
00028 
00029 #include <stdio.h>
00030 #include <stdlib.h>
00031 #include "allheaders.h"
00032 
00033 
00034 main(int    argc,
00035      char **argv)
00036 {
00037 l_int32      i, nsels, same1, same2, ok;
00038 char        *filein, *selname;
00039 PIX         *pixs, *pixref, *pixt1, *pixt2, *pixt3, *pixt4;
00040 SEL         *sel;
00041 SELA        *sela;
00042 static char  mainName[] = "fhmtauto_reg";
00043 
00044     if (argc != 2)
00045         exit(ERROR_INT(" Syntax:  fhmtauto_reg filein", mainName, 1));
00046 
00047     filein = argv[1];
00048     if ((pixs = pixRead(filein)) == NULL)
00049         exit(ERROR_INT("pixs not made", mainName, 1));
00050 
00051     sela = selaAddHitMiss(NULL);
00052     nsels = selaGetCount(sela);
00053 
00054     ok = TRUE;
00055     for (i = 0; i < nsels; i++)
00056     {
00057         sel = selaGetSel(sela, i);
00058         selname = selGetName(sel);
00059 
00060         pixref = pixHMT(NULL, pixs, sel);
00061 
00062         pixt1 = pixAddBorder(pixs, 32, 0);
00063         pixt2 = pixFHMTGen_1(NULL, pixt1, selname);
00064         pixt3 = pixRemoveBorder(pixt2, 32);
00065        
00066         pixt4 = pixHMTDwa_1(NULL, pixs, selname);
00067 
00068         pixEqual(pixref, pixt3, &same1);
00069         pixEqual(pixref, pixt4, &same2);
00070         if (same1 && same2)
00071             fprintf(stderr, "hmt are identical for sel %d (%s)\n", i, selname);
00072         else {
00073             fprintf(stderr, "hmt differ for sel %d (%s)\n", i, selname);
00074             ok = FALSE;
00075         }
00076 
00077         pixDestroy(&pixref);
00078         pixDestroy(&pixt1);
00079         pixDestroy(&pixt2);
00080         pixDestroy(&pixt3);
00081         pixDestroy(&pixt4);
00082     }
00083 
00084     if (ok)
00085         fprintf(stderr, "\n ********  All hmt are correct *******\n");
00086     else
00087         fprintf(stderr, "\n ********  ERROR in at least one hmt *******\n");
00088 
00089     pixDestroy(&pixs);
00090     selaDestroy(&sela);
00091     exit(0);
00092 }
00093 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines