Leptonica 1.68
C Image Processing Library

ranktest.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  * ranktest.c
00018  *  
00019  *     Tests rank filters on 8 and 32 bpp images.
00020  */
00021 
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include "allheaders.h"
00025 
00026 
00027 main(int    argc,
00028      char **argv)
00029 {
00030 l_int32      i, wf, hf, w, h, d, same;
00031 l_float32    rank, time;
00032 PIX         *pixs, *pixd, *pixt1, *pixt2, *pixt3, *pixt4;
00033 PIXA        *pixa;
00034 char        *filein, *fileout;
00035 static char  mainName[] = "ranktest";
00036 
00037     if (argc != 6)
00038         exit(ERROR_INT(" Syntax:  ranktest filein wf hf rank fileout",
00039                        mainName, 1));
00040 
00041     filein = argv[1];
00042     wf = atoi(argv[2]);
00043     hf = atoi(argv[3]);
00044     rank = atof(argv[4]);
00045     fileout = argv[5];
00046 
00047     if ((pixs = pixRead(filein)) == NULL)
00048         exit(ERROR_INT("pix not made", mainName, 1));
00049     pixGetDimensions(pixs, &w, &h, &d);
00050     if (d != 8 && d != 32)
00051         exit(ERROR_INT("pix neither 8 nor 32 bpp", mainName, 1));
00052 
00053     startTimer();
00054     pixd = pixRankFilter(pixs, wf, hf, rank);
00055     time = stopTimer();
00056     fprintf(stderr, "Time =  %7.3f sec\n", time);
00057     fprintf(stderr, "MPix/sec: %7.3f\n", 0.000001 * w * h / time);
00058     pixDisplay(pixs, 0, 0);
00059     pixDisplay(pixd, 600, 0);
00060     pixWrite(fileout, pixd, IFF_PNG);
00061     pixDestroy(&pixd);
00062 
00063         /* Get results for different rank values */
00064     for (i = 0; i <= 10; i++) {
00065         pixd = pixRankFilter(pixs, wf, hf, 0.1 * i);
00066         pixDisplayWrite(pixd, 1);
00067         pixDestroy(&pixd);
00068     }
00069 
00070         /* Make the dimensions odd to compare with dilation & erosion */
00071     if (wf % 2 == 0) wf++;
00072     if (hf % 2 == 0) hf++;
00073 
00074         /* Get results for dilation and erosion */
00075     if (d == 8) {
00076         pixt1 = pixDilateGray(pixs, wf, hf);
00077         pixt2 = pixErodeGray(pixs, wf, hf);
00078     } else {
00079         pixt1 = pixColorMorph(pixs, L_MORPH_DILATE, wf, hf);
00080         pixt2 = pixColorMorph(pixs, L_MORPH_ERODE, wf, hf);
00081     }
00082     pixDisplayWrite(pixt1, 1);  /* dilation */
00083 
00084         /* Get results using the rank filter for rank = 0.0 and 1.0.
00085          * Don't use 0.0 or 1.0, because those are dispatched
00086          * automatically to erosion and dilation! */
00087     pixt3 = pixRankFilter(pixs, wf, hf, 0.0001);
00088     pixt4 = pixRankFilter(pixs, wf, hf, 0.9999);
00089 
00090         /* Compare */
00091     pixEqual(pixt1, pixt4, &same);
00092     if (same)
00093         fprintf(stderr, "Correct: dilation results same as rank 1.0\n");
00094     else
00095         fprintf(stderr, "Error: dilation results differ from rank 1.0\n");
00096     pixEqual(pixt2, pixt3, &same);
00097     if (same)
00098         fprintf(stderr, "Correct: erosion results same as rank 0.0\n");
00099     else
00100         fprintf(stderr, "Error: erosion results differ from rank 0.0\n");
00101     pixDestroy(&pixt1);
00102     pixDestroy(&pixt2);
00103     pixDestroy(&pixt3);
00104     pixDestroy(&pixt4);
00105 
00106         /* Display tiled */
00107     pixa = pixaReadFiles("/tmp", "junk_write_display");
00108     pixd = pixaDisplayTiledAndScaled(pixa, d, 400, 3, 0, 25, 2);
00109     pixWrite("/tmp/junktiles.jpg", pixd, IFF_JFIF_JPEG);
00110     pixDestroy(&pixd);
00111     pixaDestroy(&pixa);
00112 
00113     pixDestroy(&pixs);
00114     return 0;
00115 }
00116 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines