Leptonica 1.68
C Image Processing Library

bincompare.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  * bincompare.c
00019  *
00020  *    Bitwise comparison of two binary images
00021  */
00022 
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include "allheaders.h"
00026 
00027     /* set one of these to 1 */
00028 #define   XOR                   1
00029 #define   SUBTRACT_1_FROM_2     0
00030 #define   SUBTRACT_2_FROM_1     0
00031 
00032 main(int    argc,
00033      char **argv)
00034 {
00035 l_int32      w, h, d, n;
00036 char        *filein1, *filein2, *fileout;
00037 PIX         *pixs1, *pixs2, *pixd;
00038 static char  mainName[] = "bincompare";
00039 
00040     if (argc != 4)
00041         exit(ERROR_INT(" Syntax:  bincompare filein1 filein2 fileout",
00042                        mainName, 1));
00043 
00044     filein1 = argv[1];
00045     filein2 = argv[2];
00046     fileout = argv[3];
00047 
00048     if ((pixs1 = pixRead(filein1)) == NULL)
00049         exit(ERROR_INT("pixs1 not made", mainName, 1));
00050     if ((pixs2 = pixRead(filein2)) == NULL)
00051         exit(ERROR_INT("pixs2 not made", mainName, 1));
00052 
00053     w = pixGetWidth(pixs1);
00054     h = pixGetHeight(pixs1);
00055     d = pixGetDepth(pixs1);
00056     if (d != 1)
00057         exit(ERROR_INT("pixs1 not binary", mainName, 1));
00058 
00059     pixCountPixels(pixs1, &n, NULL);
00060     fprintf(stderr, "Number of fg pixels in file1 = %d\n", n);
00061     pixCountPixels(pixs2, &n, NULL);
00062     fprintf(stderr, "Number of fg pixels in file2 = %d\n", n);
00063 
00064 #if XOR 
00065     fprintf(stderr, "xor: 1 ^ 2\n");
00066     pixRasterop(pixs1, 0, 0, w, h, PIX_SRC ^ PIX_DST, pixs2, 0, 0);
00067     pixCountPixels(pixs1, &n, NULL);
00068     fprintf(stderr, "Number of fg pixels in XOR = %d\n", n);
00069     pixWrite(fileout, pixs1, IFF_PNG);
00070 #elif  SUBTRACT_1_FROM_2
00071     fprintf(stderr, "subtract: 2 - 1\n");
00072     pixRasterop(pixs1, 0, 0, w, h, PIX_SRC & PIX_NOT(PIX_DST), pixs2, 0, 0);
00073     pixCountPixels(pixs1, &n, NULL);
00074     fprintf(stderr, "Number of fg pixels in 2 - 1 = %d\n", n);
00075     pixWrite(fileout, pixs1, IFF_PNG);
00076 #elif  SUBTRACT_2_FROM_1
00077     fprintf(stderr, "subtract: 1 - 2\n");
00078     pixRasterop(pixs1, 0, 0, w, h, PIX_DST & PIX_NOT(PIX_SRC), pixs2, 0, 0);
00079     pixCountPixels(pixs1, &n, NULL);
00080     fprintf(stderr, "Number of fg pixels in 1 - 2 = %d\n", n);
00081     pixWrite(fileout, pixs1, IFF_PNG);
00082 #else
00083     fprintf(stderr, "no comparison selected\n");
00084 #endif
00085 
00086     return 0;
00087 }
00088 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines