Leptonica 1.68
C Image Processing Library

expand_reg.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  * expand_reg.c
00018  *
00019  */
00020 
00021 #include <stdio.h>
00022 #include <stdlib.h>
00023 #include "allheaders.h"
00024 
00025 #define  BINARY_IMAGE             "test1.png"
00026 #define  TWO_BPP_IMAGE_NO_CMAP    "weasel2.4g.png"
00027 #define  TWO_BPP_IMAGE_CMAP       "weasel2.4c.png"
00028 #define  FOUR_BPP_IMAGE_NO_CMAP   "weasel4.16g.png"
00029 #define  FOUR_BPP_IMAGE_CMAP      "weasel4.16c.png"
00030 #define  EIGHT_BPP_IMAGE_NO_CMAP  "weasel8.149g.png"
00031 #define  EIGHT_BPP_IMAGE_CMAP     "weasel8.240c.png"
00032 #define  RGB_IMAGE                "marge.jpg"
00033 
00034 
00035 main(int    argc,
00036      char **argv)
00037 {
00038 l_int32      i, w, h, same;
00039 char         filename[][64] = {BINARY_IMAGE,
00040                                TWO_BPP_IMAGE_NO_CMAP, TWO_BPP_IMAGE_CMAP,
00041                                FOUR_BPP_IMAGE_NO_CMAP, FOUR_BPP_IMAGE_CMAP,
00042                                EIGHT_BPP_IMAGE_NO_CMAP, EIGHT_BPP_IMAGE_CMAP,
00043                                RGB_IMAGE};
00044 BOX         *box;
00045 PIX         *pix, *pixs, *pixt, *pixt1, *pixt2, *pixt3, *pixt4, *pixt5, *pixd;
00046 static char  mainName[] = "expand_reg";
00047 
00048     if (argc != 1)
00049         exit(ERROR_INT(" Syntax:  expand_reg", mainName, 1));
00050 
00051     pixDisplayWrite(NULL, -1);
00052     for (i = 0; i < 8; i++) {
00053         pixs = pixRead(filename[i]);
00054         pixt = pixExpandReplicate(pixs, 2);
00055         pixDisplayWrite(pixt, 1);
00056         pixDestroy(&pixt);
00057         pixt = pixExpandReplicate(pixs, 3);
00058         pixDisplayWrite(pixt, 1);
00059         pixDestroy(&pixt);
00060 
00061         if (i == 4) {
00062             pixt = pixScale(pixs, 3.0, 3.0);
00063             pixWrite("/tmp/junkpixt.png", pixt, IFF_PNG);
00064             pixDestroy(&pixt);
00065         }
00066         pixDestroy(&pixs);
00067     }
00068               
00069     pix = pixRead("test1.png");
00070     pixGetDimensions(pix, &w, &h, NULL);
00071     for (i = 1; i <= 15; i++) {
00072         box = boxCreate(13 * i, 13 * i, w - 13 * i, h - 13 * i);
00073         pixs = pixClipRectangle(pix, box, NULL);
00074         pixt = pixExpandReplicate(pixs, 3);
00075         pixDisplayWrite(pixt, 1);
00076         boxDestroy(&box);
00077         pixDestroy(&pixt);
00078         pixDestroy(&pixs);
00079     }
00080     pixDestroy(&pix);
00081 
00082     pixs = pixRead("speckle.png");
00083         /* Test 2x expansion of 1 bpp */
00084     pixt = pixExpandBinaryPower2(pixs, 2);
00085     pixDisplayWrite(pixt, 1);
00086     pixd = pixReduceRankBinary2(pixt, 4, NULL);
00087     pixEqual(pixs, pixd, &same);
00088     if (!same)
00089         fprintf(stderr, "Error in 2x 1bpp expansion\n");
00090     pixDestroy(&pixt);
00091     pixDestroy(&pixd);
00092         /* Test 2x expansion of 2 bpp */
00093     pixt1 = pixConvert1To2(NULL, pixs, 3, 0);
00094     pixt2 = pixExpandReplicate(pixt1, 2);
00095     pixDisplayWrite(pixt2, 1);
00096     pixt3 = pixConvertTo8(pixt2, FALSE);
00097     pixt4 = pixThresholdToBinary(pixt3, 250);
00098     pixd = pixReduceRankBinary2(pixt4, 4, NULL);
00099     pixEqual(pixs, pixd, &same);
00100     if (!same)
00101         fprintf(stderr, "Error in 2x 2bpp expansion\n");
00102     pixt5 = pixExpandBinaryPower2(pixd, 2);
00103     pixDisplayWrite(pixt5, 1);
00104     pixDestroy(&pixt1);
00105     pixDestroy(&pixt2);
00106     pixDestroy(&pixt3);
00107     pixDestroy(&pixt4);
00108     pixDestroy(&pixt5);
00109     pixDestroy(&pixd);
00110         /* Test 4x expansion of 4 bpp */
00111     pixt1 = pixConvert1To4(NULL, pixs, 15, 0);
00112     pixt2 = pixExpandReplicate(pixt1, 4);
00113     pixDisplayWrite(pixt2, 2);
00114     pixt3 = pixConvertTo8(pixt2, FALSE);
00115     pixt4 = pixThresholdToBinary(pixt3, 250);
00116     pixDisplayWrite(pixt4, 2);
00117     pixd = pixReduceRankBinaryCascade(pixt4, 4, 4, 0, 0);
00118     pixEqual(pixs, pixd, &same);
00119     if (!same)
00120         fprintf(stderr, "Error in 4x 4bpp expansion\n");
00121     pixDestroy(&pixt1);
00122     pixDestroy(&pixt2);
00123     pixDestroy(&pixt3);
00124     pixDestroy(&pixt4);
00125     pixDestroy(&pixd);
00126         /* Test 8x expansion of 8 bpp */
00127     pixt1 = pixConvertTo8(pixs, FALSE);
00128     pixt2 = pixExpandReplicate(pixt1, 8);
00129     pixDisplayWrite(pixt2, 4);
00130     pixt3 = pixThresholdToBinary(pixt2, 250);
00131     pixDisplayWrite(pixt3, 4);
00132     pixd = pixReduceRankBinaryCascade(pixt3, 4, 4, 4, 0);
00133     pixEqual(pixs, pixd, &same);
00134     if (!same)
00135         fprintf(stderr, "Error in 4x 4bpp expansion\n");
00136     pixDestroy(&pixt1);
00137     pixDestroy(&pixt2);
00138     pixDestroy(&pixt3);
00139     pixDestroy(&pixd);
00140     pixDestroy(&pixs);
00141 
00142     pixDisplayMultiple("/tmp/junk_write_display*");
00143     return 0;
00144 }
00145 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines