Leptonica 1.68
C Image Processing Library

smoothedge_reg.c

Go to the documentation of this file.
00001 
00002 /*
00003  * smoothedge_reg.c
00004  *
00005  *   Analyzes edges of a 1 bpp (connected component) image for smoothness.
00006  */
00007 
00008 #include <stdio.h>
00009 #include <stdlib.h>
00010 #include "allheaders.h"
00011 
00012 static l_int32 MIN_JUMP = 2;
00013 static l_int32 MIN_REVERSAL = 3;
00014 
00015 void PixAddEdgeData(PIXA *pixa, PIX *pixs, l_int32 side, l_int32 minjump,
00016                     l_int32 minreversal);
00017 
00018 
00019 main(int    argc,
00020      char **argv)
00021 {
00022 l_int32      w;
00023 PIX         *pixs, *pixt, *pixd;
00024 PIXA        *pixa;
00025 static char  mainName[] = "smoothedge_reg";
00026 
00027     pixs = pixRead("raggededge.png");
00028     w = pixGetWidth(pixs);
00029     pixa = pixaCreate(0);
00030     PixAddEdgeData(pixa, pixs, L_FROM_RIGHT, MIN_JUMP, MIN_REVERSAL);
00031     PixAddEdgeData(pixa, pixs, L_FROM_LEFT, MIN_JUMP, MIN_REVERSAL);
00032     pixt = pixRotateOrth(pixs, 1);
00033     PixAddEdgeData(pixa, pixt, L_FROM_BOTTOM, MIN_JUMP, MIN_REVERSAL);
00034     PixAddEdgeData(pixa, pixt, L_FROM_TOP, MIN_JUMP, MIN_REVERSAL);
00035     pixDestroy(&pixt);
00036     pixt = pixRotateOrth(pixs, 2);
00037     PixAddEdgeData(pixa, pixt, L_FROM_LEFT, MIN_JUMP, MIN_REVERSAL);
00038     PixAddEdgeData(pixa, pixt, L_FROM_RIGHT, MIN_JUMP, MIN_REVERSAL);
00039     pixDestroy(&pixt);
00040     pixt = pixRotateOrth(pixs, 3);
00041     PixAddEdgeData(pixa, pixt, L_FROM_TOP, MIN_JUMP, MIN_REVERSAL);
00042     PixAddEdgeData(pixa, pixt, L_FROM_BOTTOM, MIN_JUMP, MIN_REVERSAL);
00043     pixDestroy(&pixt);
00044     pixDestroy(&pixs);
00045 
00046         /* Display at 2x scaling */
00047     pixd = pixaDisplayTiledAndScaled(pixa, 32, 2 * (w + 10), 2, 0, 25, 2);
00048     pixWrite("/tmp/junkpixd.png", pixd, IFF_PNG);
00049     pixDestroy(&pixd);
00050     pixaDestroy(&pixa);
00051     return 0;
00052 }
00053 
00054 
00055 void PixAddEdgeData(PIXA    *pixa,
00056                     PIX     *pixs,
00057                     l_int32  side,
00058                     l_int32  minjump,
00059                     l_int32  minreversal)
00060 {
00061 l_float32  jpl, jspl, rpl;
00062 PIX       *pixt1, *pixt2;
00063 
00064     pixMeasureEdgeSmoothness(pixs, side, minjump, minreversal, &jpl,
00065                              &jspl, &rpl, "/tmp/junkedge.png");
00066     fprintf(stderr, "side = %d: jpl = %6.3f, jspl = %6.3f, rpl = %6.3f\n",
00067             side, jpl, jspl, rpl);
00068     pixt1 = pixRead("/tmp/junkedge.png");
00069     pixt2 = pixAddBorder(pixt1, 10, 0);  /* 10 pixel white border */
00070     pixaAddPix(pixa, pixt2, L_INSERT);
00071     pixDestroy(&pixt1);
00072     return;
00073 }
00074     
00075 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines