Leptonica 1.68
C Image Processing Library

locminmax_reg.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  * locminmax_reg.c
00018  *
00019  */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include <math.h>
00024 #include "allheaders.h"
00025 
00026 
00027 main(int    argc,
00028      char **argv)
00029 {
00030 l_int32      i, j;
00031 l_float32    f;
00032 l_uint32     redval, greenval;
00033 PIX         *pixs, *pixd, *pixt0, *pixt1, *pixt2, *pixt3;
00034 static char  mainName[] = "locminmax_reg";
00035 
00036     if (argc != 1)
00037         exit(ERROR_INT("syntax: locminmax_reg", mainName, 1));
00038 
00039     pixs = pixCreate(500, 500, 8);
00040     for (i = 0; i < 500; i++) {
00041         for (j = 0; j < 500; j++) {
00042             f = 128.0 + 26.3 * sin(0.0438 * (l_float32)i);
00043             f += 33.4 * cos(0.0712 * (l_float32)i);
00044             f += 18.6 * sin(0.0561 * (l_float32)j);
00045             f += 23.6 * cos(0.0327 * (l_float32)j);
00046             pixSetPixel(pixs, j, i, (l_int32)f);
00047         }
00048     }
00049     pixDisplay(pixs, 0, 0);
00050     pixWrite("/tmp/junkpattern.png", pixs, IFF_PNG);
00051 
00052     startTimer();
00053 /*    pixSelectedLocalExtrema(pixs, 1, &pixt1, &pixt2); */
00054     pixLocalExtrema(pixs, 0, 0, &pixt1, &pixt2);
00055     fprintf(stderr, "Time for extrema: %7.3f\n", stopTimer());
00056     composeRGBPixel(255, 0, 0, &redval);
00057     composeRGBPixel(0, 255, 0, &greenval);
00058     pixd = pixConvertTo32(pixs);
00059     pixPaintThroughMask(pixd, pixt2, 0, 0, greenval);
00060     pixPaintThroughMask(pixd, pixt1, 0, 0, redval);
00061     pixDisplay(pixd, 510, 0);
00062     pixWrite("/tmp/junkpixd.png", pixd, IFF_PNG);
00063     pixDestroy(&pixt1);
00064     pixDestroy(&pixt2);
00065     pixDestroy(&pixs);
00066     pixDestroy(&pixd);
00067 
00068     pixt0 = pixRead("karen8.jpg");
00069     pixs = pixBlockconv(pixt0, 10, 10);
00070     pixDisplay(pixs, 0, 400);
00071     pixWrite("/tmp/junkconv.png", pixs, IFF_PNG);
00072     startTimer();
00073 /*    pixSelectedLocalExtrema(pixs, 1, &pixt1, &pixt2); */
00074     pixLocalExtrema(pixs, 50, 100, &pixt1, &pixt2);
00075     fprintf(stderr, "Time for extrema: %7.3f\n", stopTimer());
00076     composeRGBPixel(255, 0, 0, &redval);
00077     composeRGBPixel(0, 255, 0, &greenval);
00078     pixd = pixConvertTo32(pixs);
00079     pixPaintThroughMask(pixd, pixt2, 0, 0, greenval);
00080     pixPaintThroughMask(pixd, pixt1, 0, 0, redval);
00081     pixDisplay(pixd, 350, 400);
00082     pixWrite("/tmp/junkpixd2.png", pixd, IFF_PNG);
00083     pixDestroy(&pixt0);
00084     pixDestroy(&pixt1);
00085     pixDestroy(&pixt2);
00086     pixDestroy(&pixs);
00087     pixDestroy(&pixd);
00088 
00089     return 0;
00090 }
00091 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines