Leptonica 1.68
C Image Processing Library

partitiontest.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  *   partitiontest.c
00018  *
00019  *      partitiontest <fname> type [maxboxes  ovlap]
00020  *
00021  *  where type is:
00022  *      5:   L_SORT_BY_WIDTH
00023  *      6:   L_SORT_BY_HEIGHT
00024  *      7:   L_SORT_BY_MIN_DIMENSION
00025  *      8:   L_SORT_BY_MAX_DIMENSION
00026  *      9:   L_SORT_BY_PERIMETER
00027  *      10:  L_SORT_BY_AREA
00028  */
00029 
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include "allheaders.h"
00033 
00034 #define  REDUCTION     1
00035 
00036 
00037 main(int    argc,
00038      char **argv)
00039 {
00040 char        *filename;
00041 l_int32      w, h, type, maxboxes;
00042 l_float32    ovlap;
00043 BOX         *box;
00044 BOXA        *boxa, *boxat, *boxad;
00045 PIX         *pix, *pixt, *pixs, *pixd;
00046 static char  mainName[] = "partitiontest";
00047 
00048     if (argc != 3 && argc != 5)
00049         return ERROR_INT("syntax: partitiontest <fname> type [maxboxes ovlap]",
00050                          mainName, 1);
00051 
00052     filename = argv[1];
00053     type = atoi(argv[2]);
00054     if (type == L_SORT_BY_WIDTH)
00055         fprintf(stderr, "Sorting by width:\n");
00056     else if (type == L_SORT_BY_HEIGHT)
00057         fprintf(stderr, "Sorting by height:\n");
00058     else if (type == L_SORT_BY_MAX_DIMENSION)
00059         fprintf(stderr, "Sorting by maximum dimension:\n");
00060     else if (type == L_SORT_BY_MIN_DIMENSION)
00061         fprintf(stderr, "Sorting by minimum dimension:\n");
00062     else if (type == L_SORT_BY_PERIMETER)
00063         fprintf(stderr, "Sorting by perimeter:\n");
00064     else if (type == L_SORT_BY_AREA)
00065         fprintf(stderr, "Sorting by area:\n");
00066     else {
00067         fprintf(stderr, "Use one of the following for 'type':\n"
00068                "     5:   L_SORT_BY_WIDTH\n"
00069                "     6:   L_SORT_BY_HEIGHT\n"
00070                "     7:   L_SORT_BY_MIN_DIMENSION\n"
00071                "     8:   L_SORT_BY_MAX_DIMENSION\n"
00072                "     9:   L_SORT_BY_PERIMETER\n"
00073                "    10:   L_SORT_BY_AREA\n");
00074         return ERROR_INT("invalid type: see source", mainName, 1);
00075     }
00076     if (argc == 5) {
00077         maxboxes = atoi(argv[3]);
00078         ovlap = atof(argv[4]);
00079     } else {
00080         maxboxes = 100;
00081         ovlap = 0.2;
00082     }
00083         
00084 
00085     pix = pixRead(filename);
00086     pixs = pixConvertTo1(pix, 128);
00087     pixDilateBrick(pixs, pixs, 5, 5);
00088     boxa = pixConnComp(pixs, NULL, 4);
00089     pixGetDimensions(pixs, &w, &h, NULL);
00090     box = boxCreate(0, 0, w, h);
00091     startTimer();
00092     boxaPermuteRandom(boxa, boxa);
00093     boxat = boxaSelectBySize(boxa, 500, 500, L_SELECT_IF_BOTH,
00094                              L_SELECT_IF_LT, NULL);
00095     boxad = boxaGetWhiteblocks(boxat, box, type, maxboxes, ovlap,
00096                                200, 0.15, 20000);
00097     fprintf(stderr, "Time: %7.3f sec\n", stopTimer());
00098     boxaWriteStream(stderr, boxad);
00099 
00100     pixDisplayWrite(NULL, -1);
00101     pixDisplayWrite(pixs, REDUCTION);
00102 
00103         /* Display box outlines in a single color in a cmapped image */
00104     pixd = pixDrawBoxa(pixs, boxad, 7, 0xe0708000);
00105     pixDisplayWrite(pixd, REDUCTION);
00106     pixDestroy(&pixd);
00107 
00108         /* Display box outlines in a single color in an RGB image */
00109     pixt = pixConvertTo8(pixs, FALSE);
00110     pixd = pixDrawBoxa(pixt, boxad, 7, 0x40a0c000);
00111     pixDisplayWrite(pixd, REDUCTION);
00112     pixDestroy(&pixt);
00113     pixDestroy(&pixd);
00114 
00115         /* Display box outlines with random colors in a cmapped image */
00116     pixd = pixDrawBoxaRandom(pixs, boxad, 7);
00117     pixDisplayWrite(pixd, REDUCTION);
00118     pixDestroy(&pixd);
00119 
00120         /* Display box outlines with random colors in an RGB image */
00121     pixt = pixConvertTo8(pixs, FALSE);
00122     pixd = pixDrawBoxaRandom(pixt, boxad, 7);
00123     pixDisplayWrite(pixd, REDUCTION);
00124     pixDestroy(&pixt);
00125     pixDestroy(&pixd);
00126 
00127         /* Display boxes in the same color in a cmapped image */
00128     pixd = pixPaintBoxa(pixs, boxad, 0x60e0a000);
00129     pixDisplayWrite(pixd, REDUCTION);
00130     pixDestroy(&pixd);
00131 
00132         /* Display boxes in the same color in an RGB image */
00133     pixt = pixConvertTo8(pixs, FALSE);
00134     pixd = pixPaintBoxa(pixt, boxad, 0xc030a000);
00135     pixDisplayWrite(pixd, REDUCTION);
00136     pixDestroy(&pixt);
00137     pixDestroy(&pixd);
00138 
00139         /* Display boxes in random colors in a cmapped image */
00140     pixd = pixPaintBoxaRandom(pixs, boxad);
00141     pixDisplayWrite(pixd, REDUCTION);
00142     pixDestroy(&pixd);
00143 
00144         /* Display boxes in random colors in an RGB image */
00145     pixt = pixConvertTo8(pixs, FALSE);
00146     pixd = pixPaintBoxaRandom(pixt, boxad);
00147     pixDisplayWrite(pixd, REDUCTION);
00148     pixDestroy(&pixt);
00149     pixDestroy(&pixd);
00150 
00151     pixDisplayMultiple("/tmp/junk_write_display*");
00152 
00153     pixDestroy(&pix);
00154     pixDestroy(&pixs);
00155     boxDestroy(&box);
00156     boxaDestroy(&boxa);
00157     boxaDestroy(&boxat);
00158     boxaDestroy(&boxad);
00159     return 0;
00160 }
00161 
00162 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines