Leptonica 1.68
C Image Processing Library
|
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 * extrema_reg.c 00018 * 00019 * Tests procedure for locating extrema (minima and maxima) 00020 * of a sampled function. 00021 */ 00022 00023 #include <stdio.h> 00024 #include <stdlib.h> 00025 #include <math.h> 00026 #include "allheaders.h" 00027 00028 00029 main(int argc, 00030 char **argv) 00031 { 00032 l_int32 i, ival, n; 00033 l_float32 f, val; 00034 GPLOT *gplot; 00035 NUMA *na1, *na2, *na3; 00036 static char mainName[] = "extrema_reg"; 00037 00038 if (argc != 1) 00039 return ERROR_INT("Syntax: extrema_reg", mainName, 1); 00040 00041 /* Generate a 1D signal and plot it */ 00042 na1 = numaCreate(500); 00043 for (i = 0; i < 500; i++) { 00044 f = 48.3 * sin(0.13 * (l_float32)i); 00045 f += 63.4 * cos(0.21 * (l_float32)i); 00046 numaAddNumber(na1, f); 00047 } 00048 gplot = gplotCreate("/tmp/junktest", GPLOT_X11, "Extrema test", "x", "y"); 00049 gplotAddPlot(gplot, NULL, na1, GPLOT_LINES, "plot 1"); 00050 00051 /* Find the local min and max and plot them */ 00052 na2 = numaFindExtrema(na1, 38.3); 00053 n = numaGetCount(na2); 00054 na3 = numaCreate(n); 00055 for (i = 0; i < n; i++) { 00056 numaGetIValue(na2, i, &ival); 00057 numaGetFValue(na1, ival, &val); 00058 numaAddNumber(na3, val); 00059 } 00060 gplotAddPlot(gplot, na2, na3, GPLOT_POINTS, "plot 2"); 00061 gplotMakeOutput(gplot); 00062 gplotDestroy(&gplot); 00063 numaDestroy(&na1); 00064 numaDestroy(&na2); 00065 numaDestroy(&na3); 00066 00067 return 0; 00068 }