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  * runlengthtest.c
29  *
30  *    Set 1 tests the runlength and 1-component dynamic range transform.
31  *    Set 2 tests the 3-component (rgb) dynamic range transform.
32  */
33 
34 #include "allheaders.h"
35 
main(int argc,char ** argv)36 int main(int    argc,
37          char **argv)
38 {
39 l_float32    avediff, rmsdiff;
40 PIX         *pix1, *pix2, *pix3, *pix4, *pix5, *pix6, *pix7;
41 static char  mainName[] = "runlengthtest";
42 
43     if (argc != 1)
44         return ERROR_INT(" Syntax:  runlengthtest", mainName, 1);
45 
46     setLeptDebugOK(1);
47     lept_mkdir("lept/run");
48 
49         /* Set 1 */
50     startTimer();
51     pix1 = pixRead("rabi.png");
52     pix2 = pixRunlengthTransform(pix1, 0, L_HORIZONTAL_RUNS, 8);
53     pix3 = pixRunlengthTransform(pix1, 0, L_VERTICAL_RUNS, 8);
54     pix4 = pixMinOrMax(NULL, pix2, pix3, L_CHOOSE_MIN);
55     pix5 = pixMaxDynamicRange(pix4, L_LOG_SCALE);
56     pix6 = pixMinOrMax(NULL, pix2, pix3, L_CHOOSE_MAX);
57     pix7 = pixMaxDynamicRange(pix6, L_LOG_SCALE);
58     fprintf(stderr, "Time for set 1: %7.3f sec\n", stopTimer());
59     pixDisplay(pix2, 0, 0);
60     pixDisplay(pix3, 600, 0);
61     pixDisplay(pix4, 1200, 0);
62     pixDisplay(pix5, 1800, 0);
63     pixDisplay(pix6, 1200, 0);
64     pixDisplay(pix7, 1800, 0);
65     pixWrite("/tmp/lept/run/pixh.png", pix2, IFF_PNG);
66     pixWrite("/tmp/lept/run/pixv.png", pix3, IFF_PNG);
67     pixWrite("/tmp/lept/run/pixmin.png", pix4, IFF_PNG);
68     pixWrite("/tmp/lept/run/pixminlog.png", pix5, IFF_PNG);
69     pixWrite("/tmp/lept/run/pixmax.png", pix6, IFF_PNG);
70     pixWrite("/tmp/lept/run/pixmaxlog.png", pix7, IFF_PNG);
71     pixDestroy(&pix1);
72     pixDestroy(&pix2);
73     pixDestroy(&pix3);
74     pixDestroy(&pix4);
75     pixDestroy(&pix5);
76     pixDestroy(&pix6);
77     pixDestroy(&pix7);
78 
79         /* Set 2 */
80     startTimer();
81     pix1 = pixRead("test24.jpg");
82     pixWriteJpeg("/tmp/lept/run/junk24.jpg", pix1, 5, 0);
83     pix2 = pixRead("/tmp/lept/run/junk24.jpg");
84     pixCompareGrayOrRGB(pix1, pix2, L_COMPARE_ABS_DIFF, GPLOT_PNG,
85                         NULL, &avediff, &rmsdiff, &pix3);
86     fprintf(stderr, "Ave diff = %6.3f, RMS diff = %6.3f\n", avediff, rmsdiff);
87     pix4 = pixMaxDynamicRangeRGB(pix3, L_LINEAR_SCALE);
88     pix5 = pixMaxDynamicRangeRGB(pix3, L_LOG_SCALE);
89     fprintf(stderr, "Time for set 2: %7.3f sec\n", stopTimer());
90     pixDisplay(pix4, 0, 800);
91     pixDisplay(pix5, 1000, 800);
92     pixWrite("/tmp/lept/run/linear.png", pix4, IFF_PNG);
93     pixWrite("/tmp/lept/run/log.png", pix5, IFF_PNG);
94 
95     pixDestroy(&pix1);
96     pixDestroy(&pix2);
97     pixDestroy(&pix3);
98     pixDestroy(&pix4);
99     pixDestroy(&pix5);
100 
101     return 0;
102 }
103