Leptonica 1.68
C Image Processing Library

colorsegtest.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  * colorsegtest.c
00018  *
00019  *   See colorseg.c for details.
00020  *
00021  *   Just for fun, try these combinations of the 4 parameters below on
00022  *   the image tetons.jpg:
00023  *      30 20 5 10    (20 colors)
00024  *      40 20 7 15    (19 colors)
00025  *      50 12 5 12    (12 colors)
00026  *      50 12 3 12    (12 colors)
00027  *      30 13 3 13    (12 colors)
00028  *      30 20 3 20    (20 colors)
00029  *      15 20 5 15    (19 colors)
00030  *      80 20 3 20    (12 colors)
00031  *      100 15 5 15   (7 colors)
00032  *      100 15 2 15   (7 colors)
00033  *      100 15 0 15   (7 colors)
00034  *      30 15 0 15    (12 colors)
00035  *      150 15 0 15   (4 colors)
00036  *      150 15 2 15   (4 colors)
00037  *      180 6 2 6     (3 colors)
00038  *      180 6 0 6     (3 colors)
00039  */
00040 
00041 #include <stdio.h>
00042 #include <stdlib.h>
00043 #include "allheaders.h"
00044 
00045 static const l_int32    MAX_DIST      = 120;
00046 static const l_int32    MAX_COLORS    = 15;
00047 static const l_int32    SEL_SIZE      = 4;
00048 static const l_int32    FINAL_COLORS  = 15;
00049 
00050 
00051 main(int    argc,
00052      char **argv)
00053 {
00054 l_int32      max_dist, max_colors, sel_size, final_colors;
00055 PIX         *pixs, *pixd, *pixt;
00056 char        *filein, *fileout;
00057 static char  mainName[] = "colorsegtest";
00058 
00059     if (argc != 3 && argc != 7)
00060         exit(ERROR_INT(
00061             "Syntax: colorsegtest filein fileout"
00062             " [max_dist max_colors sel_size final_colors]\n"
00063             " Default values are: max_dist = 120\n"
00064             "                     max_colors = 15\n"
00065             "                     sel_size = 4\n"
00066             "                     final_colors = 15\n", mainName, 1));
00067 
00068     filein = argv[1];
00069     fileout = argv[2];
00070     if (argc == 3) {  /* use default values */
00071         max_dist = MAX_DIST;
00072         max_colors = MAX_COLORS;
00073         sel_size = SEL_SIZE;
00074         final_colors = FINAL_COLORS;
00075     }
00076     else {  /* 6 input args */
00077         max_dist = atoi(argv[3]);
00078         max_colors = atoi(argv[4]);
00079         sel_size = atoi(argv[5]);
00080         final_colors = atoi(argv[6]);
00081     }
00082 
00083     if ((pixs = pixRead(filein)) == NULL)
00084         exit(ERROR_INT("pixs not made", mainName, 1));
00085             
00086     startTimer();
00087     pixt = pixRemoveColormap(pixs, REMOVE_CMAP_BASED_ON_SRC);
00088     pixd = pixColorSegment(pixt, max_dist, max_colors, sel_size, final_colors);
00089     fprintf(stderr, "Time to segment: %7.3f sec\n", stopTimer());
00090     pixWrite(fileout, pixd, IFF_PNG);
00091 
00092     pixDestroy(&pixs);
00093     pixDestroy(&pixd);
00094     return 0;
00095 }
00096 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines