Leptonica 1.68
C Image Processing Library

logicops_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  * logicops_reg.c
00018  *
00019  */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include "allheaders.h"
00024 
00025 #define   DISPLAY    0
00026 
00027 main(int    argc,
00028      char **argv)
00029 {
00030 l_int32      same;
00031 PIX         *pixs, *pixt1, *pixt2, *pixt3, *pixt4;
00032 static char  mainName[] = "logicops_reg";
00033 
00034     if (argc != 1)
00035         exit(ERROR_INT(" Syntax: logicops_reg", mainName, 1));
00036 
00037     pixs = pixRead("test1.png");
00038     pixDisplayWrite(pixs, DISPLAY);
00039 
00040         /* pixInvert */
00041     pixt1 = pixInvert(NULL, pixs);
00042     pixt2 = pixCreateTemplate(pixs);  /* into pixd of same size */
00043     pixInvert(pixt2, pixs);
00044     pixEqual(pixt1, pixt2, &same);
00045     if (!same)
00046         fprintf(stderr, "Error: pixInvert\n");
00047     else
00048         fprintf(stderr, "Correct: pixInvert\n");
00049     pixDisplayWrite(pixt1, DISPLAY); 
00050 
00051     pixt3 = pixRead("marge.jpg");  /* into pixd of different size */
00052     pixInvert(pixt3, pixs);
00053     pixEqual(pixt1, pixt3, &same);
00054     if (!same)
00055         fprintf(stderr, "Error: pixInvert\n");
00056     else
00057         fprintf(stderr, "Correct: pixInvert\n");
00058     pixDisplayWrite(pixt3, DISPLAY); 
00059     pixDestroy(&pixt1);
00060     pixDestroy(&pixt2);
00061     pixDestroy(&pixt3);
00062 
00063     pixt1 = pixOpenBrick(NULL, pixs, 1, 9);
00064     pixt2 = pixDilateBrick(NULL, pixs, 1, 9);
00065     pixDisplayWrite(pixt1, DISPLAY); 
00066     pixDisplayWrite(pixt2, DISPLAY); 
00067 
00068         /* pixOr */
00069     pixt3 = pixCreateTemplate(pixs);
00070     pixOr(pixt3, pixs, pixt1);  /* existing */
00071     pixt4 = pixOr(NULL, pixs, pixt1);  /* new */
00072     pixEqual(pixt3, pixt4, &same);
00073     if (!same)
00074         fprintf(stderr, "Error: pixOr\n");
00075     else
00076         fprintf(stderr, "Correct: pixOr\n");
00077     pixDisplayWrite(pixt3, DISPLAY); 
00078     pixCopy(pixt4, pixt1);
00079     pixOr(pixt4, pixt4, pixs);  /* in-place */
00080     pixEqual(pixt3, pixt4, &same);
00081     if (!same)
00082         fprintf(stderr, "Error: pixOr\n");
00083     else
00084         fprintf(stderr, "Correct: pixOr\n");
00085     pixDestroy(&pixt3);
00086     pixDestroy(&pixt4);
00087 
00088     pixt3 = pixCreateTemplate(pixs);
00089     pixOr(pixt3, pixs, pixt2);  /* existing */
00090     pixt4 = pixOr(NULL, pixs, pixt2);  /* new */
00091     pixEqual(pixt3, pixt4, &same);
00092     if (!same)
00093         fprintf(stderr, "Error: pixOr\n");
00094     else
00095         fprintf(stderr, "Correct: pixOr\n");
00096     pixDisplayWrite(pixt3, DISPLAY); 
00097     pixCopy(pixt4, pixt2);
00098     pixOr(pixt4, pixt4, pixs);  /* in-place */
00099     pixEqual(pixt3, pixt4, &same);
00100     if (!same)
00101         fprintf(stderr, "Error: pixOr\n");
00102     else
00103         fprintf(stderr, "Correct: pixOr\n");
00104     pixDestroy(&pixt3);
00105     pixDestroy(&pixt4);
00106 
00107         /* pixAnd */
00108     pixt3 = pixCreateTemplate(pixs);
00109     pixAnd(pixt3, pixs, pixt1);  /* existing */
00110     pixt4 = pixAnd(NULL, pixs, pixt1);  /* new */
00111     pixEqual(pixt3, pixt4, &same);
00112     if (!same)
00113         fprintf(stderr, "Error: pixAnd\n");
00114     else
00115         fprintf(stderr, "Correct: pixAnd\n");
00116     pixDisplayWrite(pixt3, DISPLAY); 
00117     pixCopy(pixt3, pixt1);
00118     pixAnd(pixt3, pixt3, pixs);  /* in-place */
00119     pixEqual(pixt3, pixt4, &same);
00120     if (!same)
00121         fprintf(stderr, "Error: pixAnd\n");
00122     else
00123         fprintf(stderr, "Correct: pixAnd\n");
00124     pixDestroy(&pixt3);
00125     pixDestroy(&pixt4);
00126 
00127     pixt3 = pixCreateTemplate(pixs);
00128     pixAnd(pixt3, pixs, pixt2);  /* existing */
00129     pixt4 = pixAnd(NULL, pixs, pixt2);  /* new */
00130     pixEqual(pixt3, pixt4, &same);
00131     if (!same)
00132         fprintf(stderr, "Error: pixAnd\n");
00133     else
00134         fprintf(stderr, "Correct: pixAnd\n");
00135     pixDisplayWrite(pixt3, DISPLAY); 
00136     pixCopy(pixt3, pixt2);
00137     pixAnd(pixt3, pixt3, pixs);  /* in-place */
00138     pixEqual(pixt3, pixt4, &same);
00139     if (!same)
00140         fprintf(stderr, "Error: pixAnd\n");
00141     else
00142         fprintf(stderr, "Correct: pixAnd\n");
00143     pixDestroy(&pixt3);
00144     pixDestroy(&pixt4);
00145 
00146         /* pixXor */
00147     pixt3 = pixCreateTemplate(pixs);
00148     pixXor(pixt3, pixs, pixt1);  /* existing */
00149     pixt4 = pixXor(NULL, pixs, pixt1);  /* new */
00150     pixEqual(pixt3, pixt4, &same);
00151     if (!same)
00152         fprintf(stderr, "Error: pixXor\n");
00153     else
00154         fprintf(stderr, "Correct: pixXor\n");
00155     pixDisplayWrite(pixt3, DISPLAY); 
00156     pixCopy(pixt3, pixt1);
00157     pixXor(pixt3, pixt3, pixs);  /* in-place */
00158     pixEqual(pixt3, pixt4, &same);
00159     if (!same)
00160         fprintf(stderr, "Error: pixXor\n");
00161     else
00162         fprintf(stderr, "Correct: pixXor\n");
00163     pixDestroy(&pixt3);
00164     pixDestroy(&pixt4);
00165 
00166     pixt3 = pixCreateTemplate(pixs);
00167     pixXor(pixt3, pixs, pixt2);  /* existing */
00168     pixt4 = pixXor(NULL, pixs, pixt2);  /* new */
00169     pixEqual(pixt3, pixt4, &same);
00170     if (!same)
00171         fprintf(stderr, "Error: pixXor\n");
00172     else
00173         fprintf(stderr, "Correct: pixXor\n");
00174     pixDisplayWrite(pixt3, DISPLAY); 
00175     pixCopy(pixt3, pixt2);
00176     pixXor(pixt3, pixt3, pixs);  /* in-place */
00177     pixEqual(pixt3, pixt4, &same);
00178     if (!same)
00179         fprintf(stderr, "Error: pixXor\n");
00180     else
00181         fprintf(stderr, "Correct: pixXor\n");
00182     pixDestroy(&pixt3);
00183     pixDestroy(&pixt4);
00184 
00185         /* pixSubtract */
00186     pixt3 = pixCreateTemplate(pixs);
00187     pixSubtract(pixt3, pixs, pixt1);  /* existing */
00188     pixt4 = pixSubtract(NULL, pixs, pixt1);  /* new */
00189     pixEqual(pixt3, pixt4, &same);
00190     if (!same)
00191         fprintf(stderr, "Error: pixSubtract\n");
00192     else
00193         fprintf(stderr, "Correct: pixSubtract\n");
00194     pixDisplayWrite(pixt3, DISPLAY); 
00195     pixCopy(pixt4, pixt1);
00196     pixSubtract(pixt4, pixs, pixt4);  /* in-place */
00197     pixEqual(pixt3, pixt4, &same);
00198     if (!same)
00199         fprintf(stderr, "Error: pixSubtract\n");
00200     else
00201         fprintf(stderr, "Correct: pixSubtract\n");
00202     pixDestroy(&pixt3);
00203     pixDestroy(&pixt4);
00204 
00205     pixt3 = pixCreateTemplate(pixs);
00206     pixSubtract(pixt3, pixs, pixt2);  /* existing */
00207     pixt4 = pixSubtract(NULL, pixs, pixt2);  /* new */
00208     pixEqual(pixt3, pixt4, &same);
00209     if (!same)
00210         fprintf(stderr, "Error: pixSubtract\n");
00211     else
00212         fprintf(stderr, "Correct: pixSubtract\n");
00213     pixDisplayWrite(pixt3, DISPLAY); 
00214     pixCopy(pixt4, pixt2);
00215     pixSubtract(pixt4, pixs, pixt4);  /* in-place */
00216     pixEqual(pixt3, pixt4, &same);
00217     if (!same)
00218         fprintf(stderr, "Error: pixSubtract\n");
00219     else
00220         fprintf(stderr, "Correct: pixSubtract\n");
00221     pixCopy(pixt4, pixt2);
00222     pixSubtract(pixs, pixs, pixt4);  /* in-place */
00223     pixEqual(pixt3, pixs, &same);
00224     if (!same)
00225         fprintf(stderr, "Error: pixSubtract\n");
00226     else
00227         fprintf(stderr, "Correct: pixSubtract\n");
00228     pixDestroy(&pixt3);
00229     pixDestroy(&pixt4);
00230 
00231     pixt4 = pixRead("marge.jpg");
00232     pixSubtract(pixt4, pixs, pixs);  /* subtract from itself; should be empty */
00233     pixt3 = pixCreateTemplate(pixs);
00234     pixEqual(pixt3, pixt4, &same);
00235     if (!same)
00236         fprintf(stderr, "Error: pixSubtract\n");
00237     else
00238         fprintf(stderr, "Correct: pixSubtract\n");
00239     pixDestroy(&pixt3);
00240     pixDestroy(&pixt4);
00241 
00242     pixSubtract(pixs, pixs, pixs);  /* subtract from itself; should be empty */
00243     pixt3 = pixCreateTemplate(pixs);
00244     pixEqual(pixt3, pixs, &same);
00245     if (!same)
00246         fprintf(stderr, "Error: pixSubtract\n");
00247     else
00248         fprintf(stderr, "Correct: pixSubtract\n");
00249     pixDestroy(&pixt3);
00250 
00251     pixDestroy(&pixs);
00252     pixDestroy(&pixt1);
00253     pixDestroy(&pixt2);
00254     exit(0);
00255 }
00256 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines