Leptonica 1.68
C Image Processing Library

livre_tophat.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  * livre_tophat.c
00018  *
00019  */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include "allheaders.h"
00024 
00025 
00026 main(int    argc,
00027      char **argv)
00028 {
00029 PIX         *pixs, *pixsg, *pixg, *pixd;
00030 PIXA        *pixa;
00031 static char  mainName[] = "livre_tophat";
00032 
00033     if (argc != 1)
00034         return ERROR_INT(" Syntax: livre_tophat", mainName, 1);
00035 
00036         /* Read the image in at 150 ppi. */
00037     if ((pixs = pixRead("brothers.150.jpg")) == NULL)
00038         return ERROR_INT("pix not made", mainName, 1);
00039     pixDisplayWrite(NULL, -1);
00040     pixDisplayWriteFormat(pixs, 2, IFF_JFIF_JPEG);
00041 
00042     pixsg = pixConvertRGBToLuminance(pixs);
00043 
00044         /* Black tophat (closing - original-image) and invert */
00045     pixg = pixTophat(pixsg, 15, 15, L_TOPHAT_BLACK);
00046     pixInvert(pixg, pixg);
00047     pixDisplayWriteFormat(pixg, 2, IFF_JFIF_JPEG);
00048 
00049         /* Set black point at 200, white point at 245. */
00050     pixd = pixGammaTRC(NULL, pixg, 1.0, 200, 245);
00051     pixDisplayWriteFormat(pixd, 2, IFF_JFIF_JPEG);
00052     pixDestroy(&pixg);
00053     pixDestroy(&pixd);
00054 
00055         /* Generate the output image */
00056     pixa = pixaReadFiles("/tmp", "junk_write_display");
00057     pixd = pixaDisplayTiledAndScaled(pixa, 8, 350, 3, 0, 25, 2);
00058     pixWrite("/tmp/tophat.jpg", pixd, IFF_JFIF_JPEG);
00059     pixDisplay(pixd, 0, 0);
00060     pixDestroy(&pixd);
00061 
00062     pixDestroy(&pixs);
00063     pixDestroy(&pixsg);
00064     return 0;
00065 }
00066 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines