Leptonica 1.68
C Image Processing Library

fmorphauto_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  * fmorphauto_reg.c
00018  *
00019  *    Basic regression test for erosion & dilation: rasterops & dwa.
00020  *
00021  *    Tests erosion and dilation from 58 structuring elements
00022  *    by comparing the full image rasterop results with the
00023  *    automatically generated dwa results.
00024  *
00025  *    Results must be identical for all operations.
00026  */
00027 
00028 #include <stdio.h>
00029 #include <stdlib.h>
00030 #include "allheaders.h"
00031 
00032     /* defined in morph.c */
00033 LEPT_DLL extern l_int32 MORPH_BC;
00034 
00035 
00036 main(int    argc,
00037      char **argv)
00038 {
00039 l_int32      i, nsels, same, xorcount;
00040 char        *filein, *selname;
00041 PIX         *pixs, *pixs1, *pixt1, *pixt2, *pixt3, *pixt4;
00042 SEL         *sel;
00043 SELA        *sela;
00044 static char  mainName[] = "fmorphauto_reg";
00045 
00046     if (argc != 2)
00047         exit(ERROR_INT(" Syntax:  fmorphauto_reg filein", mainName, 1));
00048 
00049     filein = argv[1];
00050 
00051     if ((pixs = pixRead(filein)) == NULL)
00052         exit(ERROR_INT("pix not made", mainName, 1));
00053 
00054     sela = selaAddBasic(NULL);
00055     nsels = selaGetCount(sela);
00056 
00057     for (i = 0; i < nsels; i++)
00058     {
00059         sel = selaGetSel(sela, i);
00060         selname = selGetName(sel);
00061 
00062             /*  ---------  dilation  ----------*/
00063 
00064         pixt1 = pixDilate(NULL, pixs, sel);
00065 
00066         pixs1 = pixAddBorder(pixs, 32, 0);
00067         pixt2 = pixFMorphopGen_1(NULL, pixs1, L_MORPH_DILATE, selname);
00068         pixt3 = pixRemoveBorder(pixt2, 32);
00069 
00070         pixt4 = pixXor(NULL, pixt1, pixt3);
00071         pixZero(pixt4, &same);
00072 
00073         if (same == 1) {
00074             fprintf(stderr, "dilations are identical for sel %d (%s)\n",
00075                     i, selname);
00076         }
00077         else {
00078             fprintf(stderr, "dilations differ for sel %d (%s)\n", i, selname);
00079             pixCountPixels(pixt4, &xorcount, NULL);
00080             fprintf(stderr, "Number of pixels in XOR: %d\n", xorcount);
00081         }
00082 
00083         pixDestroy(&pixt1);
00084         pixDestroy(&pixt2);
00085         pixDestroy(&pixt3);
00086         pixDestroy(&pixt4);
00087         pixDestroy(&pixs1);
00088 
00089             /*  ---------  erosion with asymmetric b.c  ----------*/
00090 
00091         resetMorphBoundaryCondition(ASYMMETRIC_MORPH_BC);
00092         fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC);
00093         pixt1 = pixErode(NULL, pixs, sel);
00094 
00095         if (MORPH_BC == ASYMMETRIC_MORPH_BC)
00096             pixs1 = pixAddBorder(pixs, 32, 0);  /* OFF border pixels */
00097         else
00098             pixs1 = pixAddBorder(pixs, 32, 1);  /* ON border pixels */
00099         pixt2 = pixFMorphopGen_1(NULL, pixs1, L_MORPH_ERODE, selname);
00100         pixt3 = pixRemoveBorder(pixt2, 32);
00101 
00102         pixt4 = pixXor(NULL, pixt1, pixt3);
00103         pixZero(pixt4, &same);
00104 
00105         if (same == 1) {
00106             fprintf(stderr, "erosions are identical for sel %d (%s)\n",
00107                     i, selname);
00108         }
00109         else {
00110             fprintf(stderr, "erosions differ for sel %d (%s)\n", i, selname);
00111             pixCountPixels(pixt4, &xorcount, NULL);
00112             fprintf(stderr, "Number of pixels in XOR: %d\n", xorcount);
00113         }
00114 
00115         pixDestroy(&pixt1);
00116         pixDestroy(&pixt2);
00117         pixDestroy(&pixt3);
00118         pixDestroy(&pixt4);
00119         pixDestroy(&pixs1);
00120         
00121             /*  ---------  erosion with symmetric b.c  ----------*/
00122 
00123         resetMorphBoundaryCondition(SYMMETRIC_MORPH_BC);
00124         fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC);
00125         pixt1 = pixErode(NULL, pixs, sel);
00126 
00127         if (MORPH_BC == ASYMMETRIC_MORPH_BC)
00128             pixs1 = pixAddBorder(pixs, 32, 0);  /* OFF border pixels */
00129         else
00130             pixs1 = pixAddBorder(pixs, 32, 1);  /* ON border pixels */
00131         pixt2 = pixFMorphopGen_1(NULL, pixs1, L_MORPH_ERODE, selname);
00132         pixt3 = pixRemoveBorder(pixt2, 32);
00133 
00134         pixt4 = pixXor(NULL, pixt1, pixt3);
00135         pixZero(pixt4, &same);
00136 
00137         if (same == 1) {
00138             fprintf(stderr, "erosions are identical for sel %d (%s)\n",
00139                     i, selname);
00140         }
00141         else {
00142             fprintf(stderr, "erosions differ for sel %d (%s)\n", i, selname);
00143             pixCountPixels(pixt4, &xorcount, NULL);
00144             fprintf(stderr, "Number of pixels in XOR: %d\n", xorcount);
00145         }
00146 
00147         pixDestroy(&pixt1);
00148         pixDestroy(&pixt2);
00149         pixDestroy(&pixt3);
00150         pixDestroy(&pixt4);
00151         pixDestroy(&pixs1);
00152     }
00153 
00154     exit(0);
00155 }
00156 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines