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 * binmorph2_reg.c 00018 * 00019 * Thorough regression test for binary separable rasterops, 00020 * using the sequence interpreters. This compares the 00021 * results for 2-way composite Sels with unitary Sels, 00022 * all invoked on the separable block morph ops. 00023 */ 00024 00025 #include "allheaders.h" 00026 00027 static const l_int32 MAX_SEL_SIZE = 120; 00028 00029 static void writeResult(char *sequence, l_int32 same); 00030 00031 00032 main(int argc, 00033 char **argv) 00034 { 00035 char *str; 00036 char buffer1[256]; 00037 char buffer2[256]; 00038 l_int32 i, same, same2, factor1, factor2, diff, success; 00039 PIX *pixs, *pixsd, *pixt1, *pixt2, *pixt3; 00040 SEL *sel1, *sel2; 00041 static char mainName[] = "binmorph2_reg"; 00042 00043 #if 1 00044 pixs = pixRead("rabi.png"); 00045 pixsd = pixMorphCompSequence(pixs, "d5.5", 0); 00046 success = TRUE; 00047 for (i = 1; i < MAX_SEL_SIZE; i++) { 00048 00049 /* Check if the size is exactly decomposable */ 00050 selectComposableSizes(i, &factor1, &factor2); 00051 diff = factor1 * factor2 - i; 00052 fprintf(stderr, "%d: (%d, %d): %d\n", i, factor1, factor2, diff); 00053 00054 /* Carry out operations on identical sized Sels: dilation */ 00055 sprintf(buffer1, "d%d.%d", i + diff, i + diff); 00056 sprintf(buffer2, "d%d.%d", i, i); 00057 pixt1 = pixMorphSequence(pixsd, buffer1, 0); 00058 pixt2 = pixMorphCompSequence(pixsd, buffer2, 0); 00059 pixEqual(pixt1, pixt2, &same); 00060 if (i < 64) { 00061 pixt3 = pixMorphCompSequenceDwa(pixsd, buffer2, 0); 00062 pixEqual(pixt1, pixt3, &same2); 00063 } else { 00064 pixt3 = NULL; 00065 same2 = TRUE; 00066 } 00067 if (same && same2) 00068 writeResult(buffer1, 1); 00069 else { 00070 writeResult(buffer1, 0); 00071 success = FALSE; 00072 } 00073 pixDestroy(&pixt1); 00074 pixDestroy(&pixt2); 00075 pixDestroy(&pixt3); 00076 00077 /* ... erosion */ 00078 sprintf(buffer1, "e%d.%d", i + diff, i + diff); 00079 sprintf(buffer2, "e%d.%d", i, i); 00080 pixt1 = pixMorphSequence(pixsd, buffer1, 0); 00081 pixt2 = pixMorphCompSequence(pixsd, buffer2, 0); 00082 pixEqual(pixt1, pixt2, &same); 00083 if (i < 64) { 00084 pixt3 = pixMorphCompSequenceDwa(pixsd, buffer2, 0); 00085 pixEqual(pixt1, pixt3, &same2); 00086 } else { 00087 pixt3 = NULL; 00088 same2 = TRUE; 00089 } 00090 if (same && same2) 00091 writeResult(buffer1, 1); 00092 else { 00093 writeResult(buffer1, 0); 00094 success = FALSE; 00095 } 00096 pixDestroy(&pixt1); 00097 pixDestroy(&pixt2); 00098 pixDestroy(&pixt3); 00099 00100 /* ... opening */ 00101 sprintf(buffer1, "o%d.%d", i + diff, i + diff); 00102 sprintf(buffer2, "o%d.%d", i, i); 00103 pixt1 = pixMorphSequence(pixsd, buffer1, 0); 00104 pixt2 = pixMorphCompSequence(pixsd, buffer2, 0); 00105 pixEqual(pixt1, pixt2, &same); 00106 if (i < 64) { 00107 pixt3 = pixMorphCompSequenceDwa(pixsd, buffer2, 0); 00108 pixEqual(pixt1, pixt3, &same2); 00109 } else { 00110 pixt3 = NULL; 00111 same2 = TRUE; 00112 } 00113 if (same && same2) 00114 writeResult(buffer1, 1); 00115 else { 00116 writeResult(buffer1, 0); 00117 success = FALSE; 00118 } 00119 pixDestroy(&pixt1); 00120 pixDestroy(&pixt2); 00121 pixDestroy(&pixt3); 00122 00123 /* ... closing */ 00124 sprintf(buffer1, "c%d.%d", i + diff, i + diff); 00125 sprintf(buffer2, "c%d.%d", i, i); 00126 pixt1 = pixMorphSequence(pixsd, buffer1, 0); 00127 pixt2 = pixMorphCompSequence(pixsd, buffer2, 0); 00128 pixEqual(pixt1, pixt2, &same); 00129 if (i < 64) { 00130 pixt3 = pixMorphCompSequenceDwa(pixsd, buffer2, 0); 00131 pixEqual(pixt1, pixt3, &same2); 00132 } else { 00133 pixt3 = NULL; 00134 same2 = TRUE; 00135 } 00136 if (same && same2) 00137 writeResult(buffer1, 1); 00138 else { 00139 writeResult(buffer1, 0); 00140 success = FALSE; 00141 } 00142 pixDestroy(&pixt1); 00143 pixDestroy(&pixt2); 00144 pixDestroy(&pixt3); 00145 00146 } 00147 pixDestroy(&pixs); 00148 pixDestroy(&pixsd); 00149 00150 if (success) 00151 fprintf(stderr, "\n---------- Success: no errors ----------\n"); 00152 else 00153 fprintf(stderr, "\n---------- Failure: error(s) found -----------\n"); 00154 #endif 00155 00156 00157 #if 0 00158 for (i = 1; i < 400; i++) { 00159 selectComposableSizes(i, &factor1, &factor2); 00160 diff = factor1 * factor2 - i; 00161 fprintf(stderr, "%d: (%d, %d): %d\n", 00162 i, factor1, factor2, diff); 00163 selectComposableSels(i, L_HORIZ, &sel1, &sel2); 00164 selDestroy(&sel1); 00165 selDestroy(&sel2); 00166 } 00167 #endif 00168 00169 #if 0 00170 selectComposableSels(68, L_HORIZ, &sel1, &sel2); /* 17, 4 */ 00171 str = selPrintToString(sel2); 00172 fprintf(stderr, str); 00173 selDestroy(&sel1); 00174 selDestroy(&sel2); 00175 lept_free(str); 00176 selectComposableSels(70, L_HORIZ, &sel1, &sel2); /* 10, 7 */ 00177 str = selPrintToString(sel2); 00178 selDestroy(&sel1); 00179 selDestroy(&sel2); 00180 fprintf(stderr, str); 00181 lept_free(str); 00182 selectComposableSels(85, L_HORIZ, &sel1, &sel2); /* 17, 5 */ 00183 str = selPrintToString(sel2); 00184 selDestroy(&sel1); 00185 selDestroy(&sel2); 00186 fprintf(stderr, str); 00187 lept_free(str); 00188 selectComposableSels(96, L_HORIZ, &sel1, &sel2); /* 12, 8 */ 00189 str = selPrintToString(sel2); 00190 selDestroy(&sel1); 00191 selDestroy(&sel2); 00192 fprintf(stderr, str); 00193 lept_free(str); 00194 00195 { SELA *sela; 00196 sela = selaAddBasic(NULL); 00197 selaWrite("/tmp/junksela.sela", sela); 00198 selaDestroy(&sela); 00199 } 00200 #endif 00201 00202 return 0; 00203 } 00204 00205 00206 static void writeResult(char *sequence, 00207 l_int32 same) 00208 { 00209 if (same) 00210 fprintf(stderr, "Sequence %s: SUCCESS\n", sequence); 00211 else 00212 fprintf(stderr, "Sequence %s: FAILURE\n", sequence); 00213 } 00214