Leptonica 1.68
C Image Processing Library

colorseg_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  * colorseg_reg.c
00018  *
00019  *   This explores the space of the four parameters input for color
00020  *   segmentation.  Of the four, only two strongly determine the
00021  *   output result:
00022  *      maxdist (the maximum distance between pixels that get
00023  *               clustered: 20 is very small, 180 is very large)
00024  *      selsize (responsible for smoothing the result: 0 is no
00025  *               smoothing (fine texture), 8 is large smoothing)
00026  *
00027  *   For large selsize (>~ 6), large regions get the same color,
00028  *   and there are few colors in the final result.
00029  *
00030  *   The other two parameters, maxcolors and finalcolors, can be
00031  *   set small (~4) or large (~20).  When set large, @maxdist will
00032  *   be most influential in determining the actual number of colors.
00033  */
00034 
00035 #include <stdio.h>
00036 #include <stdlib.h>
00037 #include "allheaders.h"
00038 
00039 static const l_int32  MaxColors[] = {4, 8, 16};
00040 static const l_int32  FinalColors[] = {4, 8, 16};
00041 
00042 main(int    argc,
00043      char **argv)
00044 {
00045 char         namebuf[256];
00046 l_int32      i, j, k, maxdist, maxcolors, selsize, finalcolors;
00047 PIX         *pixs, *pixt, *pixd;
00048 PIXA        *pixa;
00049 static char  mainName[] = "colorseg_reg";
00050 
00051     if (argc != 1)
00052         exit(ERROR_INT("Syntax: colorseg_reg", mainName, 1));
00053 
00054     pixs = pixRead("tetons.jpg");
00055 
00056     for (k = 0; k < 3; k++) {
00057         maxcolors = MaxColors[k];
00058         finalcolors = FinalColors[k];
00059         pixa = pixaCreate(0);
00060         pixSaveTiled(pixs, pixa, 1, 1, 15, 32);
00061         for (i = 1; i <= 9; i++) {
00062             maxdist = 20 * i;
00063             for (j = 0; j <= 6; j++) {
00064                 selsize = j;
00065                 pixt = pixColorSegment(pixs, maxdist, maxcolors, selsize,
00066                                        finalcolors);
00067                 pixSaveTiled(pixt, pixa, 1, j == 0 ? 1 : 0, 15, 32);
00068                 pixDestroy(&pixt);
00069             }
00070         }
00071 
00072         pixd = pixaDisplay(pixa, 0, 0);
00073         pixDisplay(pixd, 100, 100);
00074         sprintf(namebuf, "/tmp/junkcolorseg%d.jpg", k);
00075         pixWrite(namebuf, pixd, IFF_JFIF_JPEG);
00076         pixDestroy(&pixd);
00077         pixaDestroy(&pixa);
00078     }
00079 
00080     pixDestroy(&pixs);
00081     return 0;
00082 }
00083 
00084 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines