Leptonica 1.68
C Image Processing Library

misctest1.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  *   misctest1.c
00018  */
00019 
00020 #include "allheaders.h"
00021 
00022 #define   SHOW    0
00023 
00024 main(int    argc,
00025      char **argv)
00026 {
00027 l_int32   w, h;
00028 BOXA     *boxa;
00029 PIX      *pixs, *pixt1, *pixt2, *pixg, *pixb, *pixd, *pixc;
00030 PIX      *pixm, *pixm2, *pixd2, *pixs2;
00031 PIXA     *pixa, *pixac;
00032 PIXCMAP  *cmap, *cmapg;
00033 
00034     pixac = pixaCreate(0);
00035 
00036         /* Combine two grayscale images using a mask */
00037     pixd = pixRead("feyn.tif");
00038     pixs = pixRead("rabi.png");
00039     pixm = pixRead("pageseg2-seed.png");
00040     pixd2 = pixScaleToGray2(pixd);
00041     pixs2 = pixScaleToGray2(pixs);
00042     pixSaveTiled(pixd2, pixac, 2, 1, 40, 32);
00043     pixSaveTiled(pixs2, pixac, 2, 0, 40, 0);
00044     pixSaveTiled(pixm, pixac, 2, 0, 40, 0);
00045     pixCombineMaskedGeneral(pixd2, pixs2, pixm, 100, 100);
00046     pixSaveTiled(pixd2, pixac, 2, 1, 40, 0);
00047     pixDisplayWithTitle(pixd2, 100, 100, NULL, SHOW);
00048     pixDestroy(&pixd2);
00049     pixDestroy(&pixs2);
00050 
00051         /* Combine two binary images using a mask */
00052     pixm2 = pixExpandBinaryReplicate(pixm, 2);
00053     pixt1 = pixCopy(NULL, pixd);
00054     pixCombineMaskedGeneral(pixd, pixs, pixm2, 200, 200);
00055     pixSaveTiled(pixd, pixac, 4, 0, 40, 0);
00056     pixDisplayWithTitle(pixd, 700, 100, NULL, SHOW);
00057     pixCombineMasked(pixt1, pixs, pixm2);
00058     pixSaveTiled(pixt1, pixac, 4, 0, 40, 0);
00059     pixDestroy(&pixd);
00060     pixDestroy(&pixt1);
00061     pixDestroy(&pixs);
00062     pixDestroy(&pixm);
00063     pixDestroy(&pixm2);
00064 
00065         /* Do a restricted seedfill */
00066     pixs = pixRead("pageseg2-seed.png");
00067     pixm = pixRead("pageseg2-mask.png");
00068     pixd = pixSeedfillBinaryRestricted(NULL, pixs, pixm, 8, 50, 175);
00069     pixSaveTiled(pixs, pixac, 2, 1, 40, 0);
00070     pixSaveTiled(pixm, pixac, 2, 0, 40, 0);
00071     pixSaveTiled(pixd, pixac, 2, 0, 40, 0);
00072     pixDestroy(&pixs);
00073     pixDestroy(&pixm);
00074     pixDestroy(&pixd);
00075 
00076         /* Colorize a grayscale image */
00077     pixs = pixRead("lucasta.150.jpg");
00078     pixGetDimensions(pixs, &w, &h, NULL);
00079     pixb = pixThresholdToBinary(pixs, 128);
00080     boxa = pixConnComp(pixb, &pixa, 8);
00081     pixSaveTiled(pixs, pixac, 1, 1, 40, 0);
00082     cmap = pixcmapGrayToColor(0x6f90c0);
00083     pixSetColormap(pixs, cmap);
00084     pixSaveTiled(pixs, pixac, 1, 0, 40, 0);
00085     pixc = pixaDisplayRandomCmap(pixa, w, h);
00086     pixcmapResetColor(pixGetColormap(pixc), 0, 255, 255, 255);
00087     pixSaveTiled(pixc, pixac, 1, 0, 40, 0);
00088     pixDestroy(&pixs);
00089     pixDestroy(&pixb);
00090     pixDestroy(&pixc);
00091     boxaDestroy(&boxa);
00092     pixaDestroy(&pixa);
00093 
00094         /* Convert color to gray */
00095     pixs = pixRead("weasel4.16c.png");
00096     pixSaveTiled(pixs, pixac, 1, 1, 20, 0);
00097     pixc = pixConvertTo32(pixs);
00098     pixt1 = pixConvertRGBToGray(pixc, 3., 7., 5.);
00099     pixSaveTiled(pixt1, pixac, 1, 0, 20, 0);
00100     pixt2 = pixConvertRGBToGrayFast(pixc);
00101     pixSaveTiled(pixt2, pixac, 1, 0, 20, 0);
00102     pixg = pixCopy(NULL, pixs);
00103     cmap = pixGetColormap(pixs);
00104     cmapg = pixcmapColorToGray(cmap, 4., 6., 3.);
00105     pixSetColormap(pixg, cmapg);
00106     pixSaveTiled(pixg, pixac, 1, 0, 20, 0);
00107     pixDestroy(&pixs);
00108     pixDestroy(&pixc);
00109     pixDestroy(&pixt1);
00110     pixDestroy(&pixt2);
00111     pixDestroy(&pixg);
00112 
00113     pixd = pixaDisplay(pixac, 0, 0);
00114     pixDisplayWithTitle(pixd, 100, 100, NULL, 1);
00115     pixWrite("/tmp/misc1.png", pixd, IFF_PNG);
00116     pixDestroy(&pixd);
00117     pixaDestroy(&pixac);
00118 
00119     return 0;
00120 }
00121 
00122 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines