Leptonica 1.68
C Image Processing Library

sheartest.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  * sheartest.c
00018  *
00019  *     sheartest filein angle fileout
00020  *
00021  *     where angle is expressed in degrees
00022  */
00023 
00024 #include <stdio.h>
00025 #include <stdlib.h>
00026 #include "allheaders.h"
00027 
00028 #define   NTIMES   10 
00029 
00030 
00031 main(int    argc,
00032      char **argv)
00033 {
00034 char        *filein, *fileout;
00035 l_int32      i, w, h, liney, linex, same;
00036 l_float32    angle, deg2rad;
00037 PIX         *pixt1, *pixt2, *pixs, *pixd;
00038 static char  mainName[] = "sheartest";
00039 
00040     if (argc != 4)
00041         exit(ERROR_INT(" Syntax:  sheartest filein angle fileout",
00042                     mainName, 1));
00043 
00044         /* Compare in-place H shear with H shear to a new pix */
00045     pixt1 = pixRead("marge.jpg");
00046     pixGetDimensions(pixt1, &w, &h, NULL);
00047     pixt2 = pixHShear(NULL, pixt1, (l_int32)(0.3 * h), 0.17, L_BRING_IN_WHITE);
00048     pixHShearIP(pixt1, (l_int32)(0.3 * h), 0.17, L_BRING_IN_WHITE);
00049     pixEqual(pixt1, pixt2, &same);
00050     if (same)
00051         fprintf(stderr, "Correct for H shear\n");
00052     else
00053         fprintf(stderr, "Error for H shear\n");
00054     pixDestroy(&pixt1);
00055     pixDestroy(&pixt2);
00056 
00057         /* Compare in-place V shear with V shear to a new pix */
00058     pixt1 = pixRead("marge.jpg");
00059     pixGetDimensions(pixt1, &w, &h, NULL);
00060     pixt2 = pixVShear(NULL, pixt1, (l_int32)(0.3 * w), 0.17, L_BRING_IN_WHITE);
00061     pixVShearIP(pixt1, (l_int32)(0.3 * w), 0.17, L_BRING_IN_WHITE);
00062     pixEqual(pixt1, pixt2, &same);
00063     if (same)
00064         fprintf(stderr, "Correct for V shear\n");
00065     else
00066         fprintf(stderr, "Error for V shear\n");
00067     pixDestroy(&pixt1);
00068     pixDestroy(&pixt2);
00069 
00070     filein = argv[1];
00071     angle = atof(argv[2]);
00072     fileout = argv[3];
00073     deg2rad = 3.1415926535 / 180.;
00074 
00075     if ((pixs = pixRead(filein)) == NULL)
00076         exit(ERROR_INT("pix not made", mainName, 1));
00077 
00078     pixGetDimensions(pixs, &w, &h, NULL);
00079 
00080 #if 0
00081         /* Select an operation from this list ...
00082          * ------------------------------------------
00083     pixd = pixHShear(NULL, pixs, liney, deg2rad * angle, L_BRING_IN_WHITE);
00084     pixd = pixVShear(NULL, pixs, linex, deg2rad * angle, L_BRING_IN_WHITE);
00085     pixd = pixHShearCorner(NULL, pixs, deg2rad * angle, L_BRING_IN_WHITE);
00086     pixd = pixVShearCorner(NULL, pixs, deg2rad * angle, L_BRING_IN_WHITE);
00087     pixd = pixHShearCenter(NULL, pixs, deg2rad * angle, L_BRING_IN_WHITE);
00088     pixd = pixVShearCenter(NULL, pixs, deg2rad * angle, L_BRING_IN_WHITE);
00089     pixHShearIP(pixs, liney, deg2rad * angle, L_BRING_IN_WHITE); pixd = pixs;
00090     pixVShearIP(pixs, linex, deg2rad * angle, L_BRING_IN_WHITE); pixd = pixs;
00091     pixRasteropHip(pixs, 0, h/3, -50, L_BRING_IN_WHITE); pixd = pixs;
00092     pixRasteropVip(pixs, 0, w/3, -50, L_BRING_IN_WHITE); pixd = pixs;
00093          * ------------------------------------------
00094          *  ... and use it in the following:         */
00095     pixd = pixHShear(NULL, pixs, liney, deg2rad * angle, L_BRING_IN_WHITE);
00096     pixWrite(fileout, pixd, IFF_PNG);
00097     pixDisplay(pixd, 50, 50);
00098     pixDestroy(&pixd);
00099 #endif
00100 
00101 #if 0
00102         /* Do a horizontal shear about a line */
00103     for (i = 0; i < NTIMES; i++) {
00104         liney = i * h / (NTIMES - 1);
00105         if (liney >= h)
00106             liney = h - 1;
00107         pixd = pixHShear(NULL, pixs, liney, deg2rad * angle, L_BRING_IN_WHITE);
00108         pixDisplay(pixd, 50 + 10 * i, 50 + 10 * i);
00109         pixDestroy(&pixd);
00110     }
00111 #endif
00112 
00113 #if 0
00114         /* Do a vertical shear about a line */
00115     for (i = 0; i < NTIMES; i++) {
00116         linex = i * w / (NTIMES - 1);
00117         if (linex >= w)
00118             linex = w - 1;
00119         pixd = pixVShear(NULL, pixs, linex, deg2rad * angle, L_BRING_IN_WHITE);
00120         pixDisplay(pixd, 50 + 10 * i, 50 + 10 * i);
00121         pixDestroy(&pixd);
00122     }
00123 #endif
00124 
00125 #if 0
00126         /* Do a horizontal in-place shear about a line */
00127     pixSetPadBits(pixs, 0);
00128     for (i = 0; i < NTIMES; i++) {
00129         pixd = pixCopy(NULL, pixs);
00130         liney = i * h / (NTIMES - 1);
00131         if (liney >= h)
00132             liney = h - 1;
00133         pixHShearIP(pixd, liney, deg2rad * angle, L_BRING_IN_WHITE);
00134         pixDisplay(pixd, 50 + 10 * i, 50 + 10 * i);
00135         pixDestroy(&pixd);
00136     }
00137 #endif
00138 
00139 #if 0
00140         /* Do a vertical in-place shear about a line */
00141     for (i = 0; i < NTIMES; i++) {
00142         pixd = pixCopy(NULL, pixs);
00143         linex = i * w / (NTIMES - 1);
00144         if (linex >= w)
00145             linex = w - 1;
00146         pixVShearIP(pixd, linex, deg2rad * angle, L_BRING_IN_WHITE);
00147         pixDisplay(pixd, 50 + 10 * i, 50 + 10 * i);
00148         pixDestroy(&pixd);
00149     }
00150 #endif
00151 
00152     pixDestroy(&pixs);
00153     exit(0);
00154 }
00155 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines