Leptonica 1.68
C Image Processing Library

edgetest.c

Go to the documentation of this file.
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  * edgetest.c
00018  */
00019 
00020 #include <stdio.h>
00021 #include <stdlib.h>
00022 #include "allheaders.h"
00023 
00024 
00025 main(int    argc,
00026      char **argv)
00027 {
00028 l_int32      i, w, h, d;
00029 l_float32    time;
00030 PIX         *pixs, *pixf, *pixd;
00031 PIXA        *pixa;
00032 char        *filein, *fileout;
00033 static char  mainName[] = "edgetest";
00034 
00035     if (argc != 3)
00036         exit(ERROR_INT(" Syntax:  edgetest filein fileout", mainName, 1));
00037 
00038     filein = argv[1];
00039     fileout = argv[2];
00040 
00041     if ((pixs = pixRead(filein)) == NULL)
00042         exit(ERROR_INT("pix not made", mainName, 1));
00043     pixGetDimensions(pixs, &w, &h, &d);
00044     if (d != 8)
00045         exit(ERROR_INT("pix not 8 bpp", mainName, 1));
00046 
00047         /* Speed: about 12 Mpix/GHz/sec */
00048     startTimer();
00049     pixf = pixSobelEdgeFilter(pixs, L_HORIZONTAL_EDGES);
00050     pixd = pixThresholdToBinary(pixf, 60);
00051     pixInvert(pixd, pixd);
00052     time = stopTimer();
00053     fprintf(stderr, "Time =  %7.3f sec\n", time);
00054     fprintf(stderr, "MPix/sec: %7.3f\n", 0.000001 * w * h / time);
00055     pixDisplay(pixs, 0, 0);
00056     pixInvert(pixf, pixf);
00057     pixDisplay(pixf, 480, 0);
00058     pixDisplay(pixd, 960, 0);
00059     pixWrite(fileout, pixf, IFF_PNG);
00060     pixDestroy(&pixd);
00061 
00062         /* Threshold at different values */
00063     pixInvert(pixf, pixf);
00064     for (i = 10; i <= 120; i += 10) {
00065         pixd = pixThresholdToBinary(pixf, i);
00066         pixInvert(pixd, pixd);
00067         pixDisplayWrite(pixd, 1);
00068         pixDestroy(&pixd);
00069     }
00070     pixDestroy(&pixf);
00071 
00072         /* Display tiled */
00073     pixa = pixaReadFiles("/tmp", "junk_write_display");
00074     pixd = pixaDisplayTiledAndScaled(pixa, 8, 400, 3, 0, 25, 2);
00075     pixWrite("/tmp/junktiles.jpg", pixd, IFF_JFIF_JPEG);
00076     pixDestroy(&pixd);
00077     pixaDestroy(&pixa);
00078 
00079     pixDestroy(&pixs);
00080     exit(0);
00081 }
00082 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines