Leptonica 1.68
C Image Processing Library

lineremoval.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  * lineremoval.c
00018  *
00019  *     Use with dave-orig.png
00020  */
00021 
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include "allheaders.h"
00025 
00026 
00027 main(int    argc,
00028      char **argv)
00029 {
00030 char        *filein;
00031 l_float32    angle, conf, deg2rad;
00032 PIX         *pixs, *pix1, *pix2, *pix3, *pix4, *pix5;
00033 PIX         *pix6, *pix7, *pix8, *pix9;
00034 static char  mainName[] = "lineremoval";
00035 
00036     if (argc != 2)
00037         exit(ERROR_INT(" Syntax:  lineremoval filein", mainName, 1));
00038 
00039     filein = argv[1];
00040 
00041     deg2rad = 3.14159 / 180.;
00042     if ((pixs = pixRead(filein)) == NULL)
00043         exit(ERROR_INT("pix not made", mainName, 1));
00044 
00045         /* threshold to binary, extracting much of the lines */
00046     pix1 = pixThresholdToBinary(pixs, 170);
00047     pixWrite("/tmp/dave-proc1.png", pix1, IFF_PNG);
00048     pixDisplayWrite(pix1, 1);
00049 
00050         /* find the skew angle and deskew using an interpolated
00051          * rotator for anti-aliasing (to avoid jaggies) */
00052     pixFindSkew(pix1, &angle, &conf);
00053     pix2 = pixRotateAMGray(pixs, deg2rad * angle, 255);
00054     pixWrite("/tmp/dave-proc2.png", pix2, IFF_PNG);
00055     pixDisplayWrite(pix2, 1);
00056 
00057         /* extract the lines to be removed */
00058     pix3 = pixCloseGray(pix2, 51, 1);
00059     pixWrite("/tmp/dave-proc3.png", pix3, IFF_PNG);
00060     pixDisplayWrite(pix3, 1);
00061 
00062         /* solidify the lines to be removed */
00063     pix4 = pixErodeGray(pix3, 1, 5);
00064     pixWrite("/tmp/dave-proc4.png", pix4, IFF_PNG);
00065     pixDisplayWrite(pix4, 1);
00066 
00067         /* clean the background of those lines */
00068     pix5 = pixThresholdToValue(NULL, pix4, 210, 255);
00069     pixWrite("/tmp/dave-proc5.png", pix5, IFF_PNG);
00070     pixDisplayWrite(pix5, 1);
00071 
00072     pix6 = pixThresholdToValue(NULL, pix5, 200, 0);
00073     pixWrite("/tmp/dave-proc6.png", pix6, IFF_PNG);
00074     pixDisplayWrite(pix6, 1);
00075 
00076         /* get paint-through mask for changed pixels */
00077     pix7 = pixThresholdToBinary(pix6, 210);
00078     pixWrite("/tmp/dave-proc7.png", pix7, IFF_PNG);
00079     pixDisplayWrite(pix7, 1);
00080 
00081         /* add the inverted, cleaned lines to orig.  Because 
00082          * the background was cleaned, the inversion is 0,
00083          * so when you add, it doesn't lighten those pixels.
00084          * It only lightens (to white) the pixels in the lines! */
00085     pixInvert(pix6, pix6);
00086     pix8 = pixAddGray(NULL, pix2, pix6);
00087     pixWrite("/tmp/dave-proc8.png", pix8, IFF_PNG);
00088     pixDisplayWrite(pix8, 1);
00089 
00090     pix9 = pixOpenGray(pix8, 1, 9);
00091     pixWrite("/tmp/dave-proc9.png", pix9, IFF_PNG);
00092     pixDisplayWrite(pix9, 1);
00093 
00094     pixCombineMasked(pix8, pix9, pix7);
00095     pixWrite("/tmp/dave-result.png", pix8, IFF_PNG);
00096     pixDisplayWrite(pix8, 1);
00097 
00098     pixDisplayMultiple("/tmp/junk_write_display*");
00099     return 0;
00100 }
00101 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines