1 /*====================================================================*
2 - Copyright (C) 2001 Leptonica. All rights reserved.
3 -
4 - Redistribution and use in source and binary forms, with or without
5 - modification, are permitted provided that the following conditions
6 - are met:
7 - 1. Redistributions of source code must retain the above copyright
8 - notice, this list of conditions and the following disclaimer.
9 - 2. Redistributions in binary form must reproduce the above
10 - copyright notice, this list of conditions and the following
11 - disclaimer in the documentation and/or other materials
12 - provided with the distribution.
13 -
14 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
15 - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
16 - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
17 - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ANY
18 - CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
19 - EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
20 - PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
21 - PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
22 - OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
23 - NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
24 - SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 *====================================================================*/
26
27 /*
28 * edgetest.c
29 *
30 * Regression test for sobel edge filter.
31 */
32
33 #include "allheaders.h"
34
main(int argc,char ** argv)35 int main(int argc,
36 char **argv)
37 {
38 l_int32 i, w, h;
39 PIX *pixs, *pix1, *pix2, *pix3, *pix4;
40 L_REGPARAMS *rp;
41
42 if (regTestSetup(argc, argv, &rp))
43 return 1;
44
45 pixs = pixRead("test8.jpg");
46
47 /* Test speed: about 60 Mpix/sec/GHz */
48 startTimer();
49 for (i = 0; i < 100; i++) {
50 pix1 = pixSobelEdgeFilter(pixs, L_HORIZONTAL_EDGES);
51 pix2 = pixThresholdToBinary(pix1, 60);
52 pixInvert(pix2, pix2);
53 pixDestroy(&pix1);
54 pixDestroy(&pix2);
55 }
56 pixGetDimensions(pixs, &w, &h, NULL);
57 fprintf(stderr, "Sobel edge MPix/sec: %7.3f\n",
58 0.0001 * w * h / stopTimer());
59
60 /* Horiz and vert sobel edges (1 bpp) */
61 pix1 = pixSobelEdgeFilter(pixs, L_HORIZONTAL_EDGES);
62 pix2 = pixThresholdToBinary(pix1, 60);
63 pixInvert(pix2, pix2);
64 regTestWritePixAndCheck(rp, pix2, IFF_PNG); /* 0 */
65 pixDisplayWithTitle(pix2, 0, 50, "Horizontal edges", rp->display);
66 pix3 = pixSobelEdgeFilter(pixs, L_VERTICAL_EDGES);
67 pix4 = pixThresholdToBinary(pix3, 60);
68 pixInvert(pix4, pix4);
69 regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 1 */
70 pixDisplayWithTitle(pix4, 625, 50, "Vertical edges", rp->display);
71 pixOr(pix4, pix4, pix2);
72 regTestWritePixAndCheck(rp, pix4, IFF_PNG); /* 2 */
73 pixDisplayWithTitle(pix4, 1200, 50, "Horiz and vert edges", rp->display);
74 pixDestroy(&pix2);
75 pixDestroy(&pix4);
76
77 /* Horizontal and vertical sobel edges (8 bpp) */
78 pixMinOrMax(pix1, pix1, pix3, L_CHOOSE_MAX);
79 pixInvert(pix1, pix1);
80 regTestWritePixAndCheck(rp, pix1, IFF_JFIF_JPEG); /* 3 */
81 pixDisplayWithTitle(pix1, 0, 525, "8bpp Horiz and vert edges", rp->display);
82 pixDestroy(&pix1);
83 pixDestroy(&pix3);
84 pixDestroy(&pixs);
85 return regTestCleanup(rp);
86 }
87
88