File: seedfilltest.c

package info (click to toggle)
leptonlib 1.57-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 9,724 kB
  • ctags: 3,900
  • sloc: ansic: 89,715; sh: 3,516; makefile: 718
file content (159 lines) | stat: -rw-r--r-- 4,782 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/*====================================================================*
 -  Copyright (C) 2001 Leptonica.  All rights reserved.
 -  This software is distributed in the hope that it will be
 -  useful, but with NO WARRANTY OF ANY KIND.
 -  No author or distributor accepts responsibility to anyone for the
 -  consequences of using this software, or for whether it serves any
 -  particular purpose or works at all, unless he or she says so in
 -  writing.  Everyone is granted permission to copy, modify and
 -  redistribute this source code, for commercial or non-commercial
 -  purposes, with the following restrictions: (1) the origin of this
 -  source code must not be misrepresented; (2) modified versions must
 -  be plainly marked as such; and (3) this notice may not be removed
 -  or altered from any source or modified source distribution.
 *====================================================================*/


/*
 * seedfilltest.c
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include "allheaders.h"

#define  NTIMES             5
#define  CONNECTIVITY       8
#define  XS                 150
#define  YS                 150

#define  DFLAG              1

main(int    argc,
     char **argv)
{
char        *filein, *fileout;
l_int32      i;
l_uint32     val;
l_float32    size;
PIX         *pixs, *pixd, *pixm, *pixmi, *pixt1, *pixt2, *pixt3;
static char  mainName[] = "seedfilltest";

    if (argc != 3)
	exit(ERROR_INT(" Syntax:  seedfilltest filein fileout", mainName, 1));

    filein = argv[1];
    fileout = argv[2];
    pixd = NULL;

    if ((pixm = pixRead(filein)) == NULL)
	exit(ERROR_INT("pixm not made", mainName, 1));
    pixmi = pixInvert(NULL, pixm);
	    
    size = pixGetWidth(pixm) * pixGetHeight(pixm);
    pixs = pixCreateTemplate(pixm);
    for (i = 0; i < 100; i++) {
	pixGetPixel(pixm, XS + 5 * i, YS + 5 * i, &val);
	if (val == 0) break;
    }
    if (i == 100)
	exit(ERROR_INT("no seed pixel found", mainName, 1));
    pixSetPixel(pixs, XS + 5 * i, YS + 5 * i, 1);

#if 1
        /* hole filling; use "hole-filler.png" */
    pixt1 = pixHDome(pixmi, 100, 4);
    pixt2 = pixThresholdToBinary(pixt1, 10);
/*    pixInvert(pixt1, pixt1); */
    pixDisplay(pixt1, 100, 500);
    pixDisplay(pixt2, 600, 500);
    pixt3 = pixHolesByFilling(pixt2, 4);
    pixDilateBrick(pixt3, pixt3, 7, 7);
    pixd = pixConvertTo8(pixt3, FALSE);
    pixDisplay(pixd, 0, 100);
    pixSeedfillGray(pixd, pixmi, CONNECTIVITY);
    pixInvert(pixd, pixd);
    pixDisplay(pixmi, 500, 100);
    pixDisplay(pixd, 1000, 100);
    pixWrite("junkpixm", pixmi, IFF_PNG);
    pixWrite("junkpixd", pixd, IFF_PNG);
#endif

#if 0
        /* hole filling; use "hole-filler.png" */
    pixt1 = pixThresholdToBinary(pixm, 110);
    pixInvert(pixt1, pixt1);
    pixDisplay(pixt1, 100, 500);
    pixt2 = pixHolesByFilling(pixt1, 4);
    pixd = pixConvertTo8(pixt2, FALSE);
    pixDisplay(pixd, 0, 100);
    pixSeedfillGray(pixd, pixmi, CONNECTIVITY);
    pixInvert(pixd, pixd);
    pixDisplay(pixmi, 500, 100);
    pixDisplay(pixd, 1000, 100);
    pixWrite("junkpixm", pixmi, IFF_PNG);
    pixWrite("junkpixd", pixd, IFF_PNG);
#endif

#if 0
        /* hole filling; use "hole-filler.png" */
    pixd = pixInvert(NULL, pixm);
    pixAddConstantGray(pixd, -50);
    pixDisplay(pixd, 0, 100);
/*    pixt1 = pixThresholdToBinary(pixd, 20);
    pixDisplayWithTitle(pixt1, 600, 600, "pixt1", DFLAG); */
    pixSeedfillGray(pixd, pixmi, CONNECTIVITY);
/*    pixInvert(pixd, pixd); */
    pixDisplay(pixmi, 500, 100);
    pixDisplay(pixd, 1000, 100);
    pixWrite("junkpixm", pixmi, IFF_PNG);
    pixWrite("junkpixd", pixd, IFF_PNG);
#endif

#if 0  
	/* test in-place seedfill for speed */
    pixd = pixClone(pixs);
    startTimer();
    pixSeedfillBinary(pixs, pixs, pixmi, CONNECTIVITY);
    fprintf(stderr, "Filling rate: %7.4f Mpix/sec\n",
        (size/1000000.) / stopTimer());

    pixWrite(fileout, pixd, IFF_PNG);
    pixOr(pixd, pixd, pixm);
    pixWrite("junkout1", pixd, IFF_PNG);
#endif

#if 0
	/* test seedfill to dest for speed */
    pixd = pixCreateTemplate(pixm);
    startTimer();
    for (i = 0; i < NTIMES; i++) {
	pixSeedfillBinary(pixd, pixs, pixmi, CONNECTIVITY);
    }
    fprintf(stderr, "Filling rate: %7.4f Mpix/sec\n",
        (size/1000000.) * NTIMES / stopTimer());

    pixWrite(fileout, pixd, IFF_PNG);
    pixOr(pixd, pixd, pixm);
    pixWrite("junkout1", pixd, IFF_PNG);
#endif

        /* use same connectivity to compare with the result of the
	 * slow parallel operation */
#if 0
    pixDestroy(&pixd);
    pixd = pixSeedfillMorph(pixs, pixmi, CONNECTIVITY);
    pixOr(pixd, pixd, pixm);
    pixWrite("junkout2", pixd, IFF_PNG);
#endif

    pixDestroy(&pixs);
    pixDestroy(&pixm);
    pixDestroy(&pixmi);
    pixDestroy(&pixd);

    exit(0);
}