1 | /**************************************************************************
|
---|
2 | *
|
---|
3 | * mgticstat.c -- Program to print out stats about a textual image library
|
---|
4 | * Copyright (C) 1994 Stuart Inglis
|
---|
5 | *
|
---|
6 | * This program is free software; you can redistribute it and/or modify
|
---|
7 | * it under the terms of the GNU General Public License as published by
|
---|
8 | * the Free Software Foundation; either version 2 of the License, or
|
---|
9 | * (at your option) any later version.
|
---|
10 | *
|
---|
11 | * This program is distributed in the hope that it will be useful,
|
---|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
14 | * GNU General Public License for more details.
|
---|
15 | *
|
---|
16 | * You should have received a copy of the GNU General Public License
|
---|
17 | * along with this program; if not, write to the Free Software
|
---|
18 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | *
|
---|
20 | * $Id: mgticstat.c 16583 2008-07-29 10:20:36Z davidb $
|
---|
21 | *
|
---|
22 | **************************************************************************/
|
---|
23 |
|
---|
24 | #include "sysfuncs.h"
|
---|
25 |
|
---|
26 | #include "marklist.h"
|
---|
27 | #include "pbmtools.h"
|
---|
28 | #include "extractor.h"
|
---|
29 | #include "utils.h"
|
---|
30 |
|
---|
31 | void
|
---|
32 | usage ()
|
---|
33 | {
|
---|
34 | fprintf (stderr, "usage:\n"
|
---|
35 | "\tmgticstat libraryfile\n");
|
---|
36 | exit (1);
|
---|
37 | }
|
---|
38 |
|
---|
39 | void
|
---|
40 | main (int argc, char *args[])
|
---|
41 | {
|
---|
42 | FILE *lib, *outf = (stdout);
|
---|
43 | int count;
|
---|
44 | int small1, small2, small4, small9, small16, small25, small36, small49,
|
---|
45 | small64, small81, small100;
|
---|
46 | marktype d;
|
---|
47 | int avx, avy;
|
---|
48 | int hhh, www, i;
|
---|
49 | int avruns_h = 0, avruns_v = 0;
|
---|
50 | int av_area = 0;
|
---|
51 | char *libraryname = NULL;
|
---|
52 |
|
---|
53 |
|
---|
54 | if (argc < 2)
|
---|
55 | usage ();
|
---|
56 |
|
---|
57 | for (i = 1; i < argc; i++)
|
---|
58 | {
|
---|
59 | if (!strcmp (args[i], "-v"))
|
---|
60 | V = 1;
|
---|
61 | else if (!strcmp (args[i], "-h"))
|
---|
62 | usage ();
|
---|
63 | else if (args[i][0] == '-')
|
---|
64 | error_msg (args[0], "unknown switch:", args[i]);
|
---|
65 | else if (!libraryname)
|
---|
66 | libraryname = args[i];
|
---|
67 | else
|
---|
68 | error_msg (args[0], "too many filenames", "");
|
---|
69 | }
|
---|
70 |
|
---|
71 | if (!libraryname)
|
---|
72 | error_msg (args[0], "please specify a library file", "");
|
---|
73 |
|
---|
74 |
|
---|
75 | lib = fopen (libraryname, "r");
|
---|
76 | if (lib == NULL)
|
---|
77 | error_msg (args[0], "Trouble opening library file", "");
|
---|
78 |
|
---|
79 | count = 0;
|
---|
80 | small1 = small2 = small4 = small9 = small16 = small25 = small36 = small49 = small64 = small81 = small100 = 0;
|
---|
81 | avx = avy = 0;
|
---|
82 | www = hhh = 0;
|
---|
83 | while (!isEOF (lib))
|
---|
84 | {
|
---|
85 | if (!read_library_mark (lib, &d))
|
---|
86 | error_msg (args[0], "error in library file", "");
|
---|
87 |
|
---|
88 | av_area += d.set;
|
---|
89 | if (d.set <= 1)
|
---|
90 | small1++;
|
---|
91 | if (d.set <= 2)
|
---|
92 | small2++;
|
---|
93 | if (d.set <= 4)
|
---|
94 | small4++;
|
---|
95 | if (d.set <= 9)
|
---|
96 | small9++;
|
---|
97 | if (d.set <= 16)
|
---|
98 | small16++;
|
---|
99 | if (d.set <= 25)
|
---|
100 | small25++;
|
---|
101 | if (d.set <= 36)
|
---|
102 | small36++;
|
---|
103 | if (d.set <= 49)
|
---|
104 | small49++;
|
---|
105 | if (d.set <= 64)
|
---|
106 | small64++;
|
---|
107 | if (d.set <= 81)
|
---|
108 | small81++;
|
---|
109 | if (d.set <= 100)
|
---|
110 | small100++;
|
---|
111 | avx += d.xcen;
|
---|
112 | avy += d.ycen;
|
---|
113 | www += d.w;
|
---|
114 | hhh += d.h;
|
---|
115 | avruns_h += d.h_runs;
|
---|
116 | avruns_v += d.v_runs;
|
---|
117 | pbm_freearray (&d.bitmap, d.h);
|
---|
118 | count++;
|
---|
119 | if (count % 5000 == 0)
|
---|
120 | fprintf (outf, "%dk ", count / 1000);
|
---|
121 | }
|
---|
122 | fprintf (outf, "number of marks=%d\n", count);
|
---|
123 | fprintf (outf, "average area=%d\n", av_area / count);
|
---|
124 | fprintf (outf, "area <=1:%d, <=2:%d, <=4:%d, <=9:%d, <=16:%d, <=25:%d, <=36:%d, <=49:%d, <=64:%d, <=81:%d, <=100:%d\n", small1, small2, small4, small9, small16, small25, small36, small49, small64, small81, small100);
|
---|
125 |
|
---|
126 | fprintf (outf, "average num runs, horizontal=%d, vertical=%d\n", avruns_h / count, avruns_v / count);
|
---|
127 | fprintf (outf, "average centroid position=(%d,%d)\n", avx / count, avy / count);
|
---|
128 | fprintf (outf, "average width=%d, average height=%d\n", www / count, hhh / count);
|
---|
129 | fclose (lib);
|
---|
130 | }
|
---|