Leptonica 1.68
C Image Processing Library

dwamorph1_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  * dwamorph1_reg.c
00018  *
00019  *     Fairly thorough regression test for autogen'd dwa.
00020  *
00021  *     The dwa code always implements safe closing.  With asymmetric
00022  *     b.c., the rasterop function must be pixCloseSafe().
00023  */
00024 
00025 #include "allheaders.h"
00026 
00027     /* defined in morph.c */
00028 LEPT_DLL extern l_int32 MORPH_BC;
00029 
00030     /* Complete set of linear brick dwa operations */
00031 PIX *pixMorphDwa_3(PIX *pixd, PIX *pixs, l_int32 operation, char *selname);
00032 PIX *pixFMorphopGen_3(PIX *pixd, PIX *pixs, l_int32 operation, char *selname);
00033 
00034 
00035 main(int    argc,
00036      char **argv)
00037 {
00038 l_int32       i, nsels, same, xorcount;
00039 char         *selname;
00040 PIX          *pixs, *pixs1, *pixt1, *pixt2, *pixt3;
00041 SEL          *sel;
00042 SELA         *sela;
00043 L_REGPARAMS  *rp;
00044 
00045     if (regTestSetup(argc, argv, &rp))
00046         return 1;
00047 
00048     if ((pixs = pixRead("feyn-fract.tif")) == NULL) {
00049         rp->success = FALSE;
00050         regTestCleanup(rp);
00051         return 1;
00052     }
00053     sela = selaAddDwaLinear(NULL);
00054     nsels = selaGetCount(sela);
00055 
00056     for (i = 0; i < nsels; i++)
00057     {
00058         sel = selaGetSel(sela, i);
00059         selname = selGetName(sel);
00060 
00061             /*  ---------  dilation  ----------*/
00062 
00063         pixt1 = pixDilate(NULL, pixs, sel);
00064         pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_DILATE, selname);
00065         pixEqual(pixt1, pixt2, &same);
00066 
00067         if (same == 1) {
00068             fprintf(stderr, "dilations are identical for sel %d (%s)\n",
00069                     i, selname);
00070         }
00071         else {
00072             rp->success = FALSE;
00073             fprintf(rp->fp, "dilations differ for sel %d (%s)\n", i, selname);
00074             pixt3 = pixXor(NULL, pixt1, pixt2);
00075             pixCountPixels(pixt3, &xorcount, NULL);
00076             fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount);
00077             pixDestroy(&pixt3);
00078         }
00079         pixDestroy(&pixt1);
00080         pixDestroy(&pixt2);
00081 
00082             /*  ---------  erosion with asymmetric b.c  ----------*/
00083 
00084         resetMorphBoundaryCondition(ASYMMETRIC_MORPH_BC);
00085         fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC);
00086 
00087         pixt1 = pixErode(NULL, pixs, sel);
00088         pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_ERODE, selname);
00089         pixEqual(pixt1, pixt2, &same);
00090 
00091         if (same == 1) {
00092             fprintf(stderr, "erosions are identical for sel %d (%s)\n",
00093                     i, selname);
00094         }
00095         else {
00096             rp->success = FALSE;
00097             fprintf(rp->fp, "erosions differ for sel %d (%s)\n", i, selname);
00098             pixt3 = pixXor(NULL, pixt1, pixt2);
00099             pixCountPixels(pixt3, &xorcount, NULL);
00100             fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount);
00101             pixDestroy(&pixt3);
00102         }
00103         pixDestroy(&pixt1);
00104         pixDestroy(&pixt2);
00105 
00106             /*  ---------  erosion with symmetric b.c  ----------*/
00107 
00108         resetMorphBoundaryCondition(SYMMETRIC_MORPH_BC);
00109         fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC);
00110 
00111         pixt1 = pixErode(NULL, pixs, sel);
00112         pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_ERODE, selname);
00113         pixEqual(pixt1, pixt2, &same);
00114 
00115         if (same == 1) {
00116             fprintf(stderr, "erosions are identical for sel %d (%s)\n",
00117                     i, selname);
00118         }
00119         else {
00120             rp->success = FALSE;
00121             fprintf(rp->fp, "erosions differ for sel %d (%s)\n", i, selname);
00122             pixt3 = pixXor(NULL, pixt1, pixt2);
00123             pixCountPixels(pixt3, &xorcount, NULL);
00124             fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount);
00125             pixDestroy(&pixt3);
00126         }
00127         pixDestroy(&pixt1);
00128         pixDestroy(&pixt2);
00129 
00130             /*  ---------  opening with asymmetric b.c  ----------*/
00131 
00132         resetMorphBoundaryCondition(ASYMMETRIC_MORPH_BC);
00133         fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC);
00134 
00135         pixt1 = pixOpen(NULL, pixs, sel);
00136         pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_OPEN, selname);
00137         pixEqual(pixt1, pixt2, &same);
00138 
00139         if (same == 1) {
00140             fprintf(stderr, "openings are identical for sel %d (%s)\n",
00141                     i, selname);
00142         }
00143         else {
00144             rp->success = FALSE;
00145             fprintf(rp->fp, "openings differ for sel %d (%s)\n", i, selname);
00146             pixt3 = pixXor(NULL, pixt1, pixt2);
00147             pixCountPixels(pixt3, &xorcount, NULL);
00148             fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount);
00149             pixDestroy(&pixt3);
00150         }
00151         pixDestroy(&pixt1);
00152         pixDestroy(&pixt2);
00153 
00154             /*  ---------  opening with symmetric b.c  ----------*/
00155 
00156         resetMorphBoundaryCondition(SYMMETRIC_MORPH_BC);
00157         fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC);
00158 
00159         pixt1 = pixOpen(NULL, pixs, sel);
00160         pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_OPEN, selname);
00161         pixEqual(pixt1, pixt2, &same);
00162 
00163         if (same == 1) {
00164             fprintf(stderr, "openings are identical for sel %d (%s)\n",
00165                     i, selname);
00166         }
00167         else {
00168             rp->success = FALSE;
00169             fprintf(rp->fp, "openings differ for sel %d (%s)\n", i, selname);
00170             pixt3 = pixXor(NULL, pixt1, pixt2);
00171             pixCountPixels(pixt3, &xorcount, NULL);
00172             fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount);
00173             pixDestroy(&pixt3);
00174         }
00175         pixDestroy(&pixt1);
00176         pixDestroy(&pixt2);
00177 
00178             /*  ---------  safe closing with asymmetric b.c  ----------*/
00179 
00180         resetMorphBoundaryCondition(ASYMMETRIC_MORPH_BC);
00181         fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC);
00182 
00183         pixt1 = pixCloseSafe(NULL, pixs, sel);  /* must use safe version */
00184         pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_CLOSE, selname);
00185         pixEqual(pixt1, pixt2, &same);
00186 
00187         if (same == 1) {
00188             fprintf(stderr, "closings are identical for sel %d (%s)\n",
00189                     i, selname);
00190         }
00191         else {
00192             rp->success = FALSE;
00193             fprintf(rp->fp, "closings differ for sel %d (%s)\n", i, selname);
00194             pixt3 = pixXor(NULL, pixt1, pixt2);
00195             pixCountPixels(pixt3, &xorcount, NULL);
00196             fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount);
00197             pixDestroy(&pixt3);
00198         }
00199         pixDestroy(&pixt1);
00200         pixDestroy(&pixt2);
00201 
00202             /*  ---------  safe closing with symmetric b.c  ----------*/
00203 
00204         resetMorphBoundaryCondition(SYMMETRIC_MORPH_BC);
00205         fprintf(stderr, "MORPH_BC = %d ... ", MORPH_BC);
00206 
00207         pixt1 = pixClose(NULL, pixs, sel);  /* safe version not required */
00208         pixt2 = pixMorphDwa_3(NULL, pixs, L_MORPH_CLOSE, selname);
00209         pixEqual(pixt1, pixt2, &same);
00210 
00211         if (same == 1) {
00212             fprintf(stderr, "closings are identical for sel %d (%s)\n",
00213                     i, selname);
00214         }
00215         else {
00216             rp->success = FALSE;
00217             fprintf(rp->fp, "closings differ for sel %d (%s)\n", i, selname);
00218             pixt3 = pixXor(NULL, pixt1, pixt2);
00219             pixCountPixels(pixt3, &xorcount, NULL);
00220             fprintf(rp->fp, "Number of pixels in XOR: %d\n", xorcount);
00221             pixDestroy(&pixt3);
00222         }
00223         pixDestroy(&pixt1);
00224         pixDestroy(&pixt2);
00225     }
00226 
00227     selaDestroy(&sela);
00228     pixDestroy(&pixs);
00229     regTestCleanup(rp);
00230     return 0;
00231 }
00232 
00233 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines