Leptonica 1.68
C Image Processing Library
|
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 * colormorphtest.c 00019 */ 00020 00021 #include <stdio.h> 00022 #include <stdlib.h> 00023 #include "allheaders.h" 00024 00025 static void pixCompare(PIX *pix, PIX *pix2, const char *msg1, const char *msg2); 00026 00027 /* MSVC can't handle arrays dimensioned by static const integers */ 00028 #define L_BUF_SIZE 256 00029 00030 00031 main(int argc, 00032 char **argv) 00033 { 00034 char *filein; 00035 char buf[L_BUF_SIZE]; 00036 l_int32 size; 00037 PIX *pixs, *pixt1, *pixt2; 00038 static char mainName[] = "colormorphtest"; 00039 00040 if (argc != 3) 00041 exit(ERROR_INT(" Syntax: colormorphtest filein size", 00042 mainName, 1)); 00043 00044 filein = argv[1]; 00045 size = atoi(argv[2]); 00046 if (size % 2 == 0) size++; 00047 00048 if ((pixs = pixRead(filein)) == NULL) 00049 exit(ERROR_INT("pixs not read", mainName, 1)); 00050 00051 pixt1 = pixColorMorph(pixs, L_MORPH_DILATE, size, size); 00052 sprintf(buf, "d%d.%d", size, size); 00053 pixt2 = pixColorMorphSequence(pixs, buf, 0, 0); 00054 pixCompare(pixt1, pixt2, "Correct for dilation", "Error on dilation"); 00055 pixDestroy(&pixt1); 00056 pixDestroy(&pixt2); 00057 00058 pixt1 = pixColorMorph(pixs, L_MORPH_ERODE, size, size); 00059 sprintf(buf, "e%d.%d", size, size); 00060 pixt2 = pixColorMorphSequence(pixs, buf, 0, 0); 00061 pixCompare(pixt1, pixt2, "Correct for erosion", "Error on erosion"); 00062 pixDestroy(&pixt1); 00063 pixDestroy(&pixt2); 00064 00065 pixt1 = pixColorMorph(pixs, L_MORPH_OPEN, size, size); 00066 sprintf(buf, "o%d.%d", size, size); 00067 pixt2 = pixColorMorphSequence(pixs, buf, 0, 0); 00068 pixCompare(pixt1, pixt2, "Correct for opening", "Error on opening"); 00069 pixDestroy(&pixt1); 00070 pixDestroy(&pixt2); 00071 00072 pixt1 = pixColorMorph(pixs, L_MORPH_CLOSE, size, size); 00073 sprintf(buf, "c%d.%d", size, size); 00074 pixt2 = pixColorMorphSequence(pixs, buf, 0, 0); 00075 pixCompare(pixt1, pixt2, "Correct for closing", "Error on closing"); 00076 pixDestroy(&pixt1); 00077 pixDestroy(&pixt2); 00078 00079 pixDisplayMultiple("/tmp/junk_write_display*"); 00080 00081 pixDestroy(&pixs); 00082 return 0; 00083 } 00084 00085 /* Simple comparison function */ 00086 static void pixCompare(PIX *pix1, 00087 PIX *pix2, 00088 const char *msg1, 00089 const char *msg2) 00090 { 00091 l_int32 same; 00092 pixEqual(pix1, pix2, &same); 00093 if (same) { 00094 fprintf(stderr, "%s\n", msg1); 00095 pixDisplayWrite(pix1, 1); 00096 } 00097 else { 00098 fprintf(stderr, "%s\n", msg2); 00099 pixDisplayWrite(pix1, 1); 00100 pixDisplayWrite(pix2, 1); 00101 } 00102 return; 00103 } 00104