home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0040 - 0049 / ibm0040-0049 / ibm0040.tar / ibm0040 / IMGPROC.ZIP / C10.ZIP / ARTEST.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-04-06  |  5.9 KB  |  197 lines

  1. /*  
  2. Copyright 1990 by John Wiley & Sons, Inc.
  3.           All Rights Reserved.
  4. */
  5. /****************************************/
  6. /*      Area Process Demo Program       */
  7. /*       written in Turbo C 2.0         */
  8. /*                by                    */
  9. /*         Craig A. Lindley             */
  10. /*                                      */
  11. /*   Vers: 1.0  Last Update: 12/26/89   */
  12. /****************************************/
  13.  
  14. #include <stdio.h>
  15. /* #include <stdlib.h> */
  16. #include <conio.h>
  17. #include <dos.h>
  18. #include <alloc.h>
  19. #include <process.h>
  20. #include <graphics.h>
  21. #include "misc.h"
  22. #include "pcx.h"
  23. #include "vga.h"
  24. #include "imagesup.h"
  25. #include "arprocess.h"
  26.  
  27. static double LP1[]=
  28. { 0.11111111, 0.11111111, 0.11111111,
  29.   0.11111111, 0.11111111, 0.11111111,
  30.   0.11111111, 0.11111111, 0.11111111 };
  31.  
  32. static short HP1[]=
  33. {  -1, -1, -1,
  34.    -1,  9, -1,
  35.    -1, -1, -1 };
  36.  
  37. static short LAP2[]=
  38. {  -1, -1, -1,
  39.    -1,  8, -1,
  40.    -1, -1, -1 };
  41.  
  42.  
  43. static short GN[]=
  44. {   1,  1,  1,
  45.     1, -2,  1,
  46.    -1, -1, -1 };
  47.  
  48. static short GE[]=
  49. {  -1,  1,  1,
  50.    -1, -2,  1,
  51.    -1,  1,  1 };
  52.  
  53. static short BLUR[]=
  54. {   1,  1,  1,  1,  1,
  55.     1,  1,  1,  1,  1,
  56.     1,  1,  1,  1,  1,
  57.     1,  1,  1,  1,  1,
  58.     1,  1,  1,  1,  1 };
  59.  
  60.  
  61. /* main area process demo program */
  62.  
  63. void main(void)
  64. {
  65.    char *InFileName1 = "p2c10i1a";
  66.    char *InFileName2 = "p2c10i2a";
  67.    char *InFileName3 = "p2c10i3a";
  68.    BYTE huge *TheInImage;
  69.    BYTE huge *TheOutImage;
  70.    unsigned GenPCXFiles = FALSE; /* controls the generation of output files */
  71.  
  72.  
  73.    InitGraphics();
  74.  
  75.    printf("Area Process Demonstration Program\n\n");
  76.    printf("Reading the Image PCX File into memory\n");
  77.  
  78.    /* generate image sequence p2ch10i1 - Various Convolutions */
  79.    if (ReadPCXFileToBuf (InFileName1,&TheInImage) != NoError)
  80.       exit(1);
  81.  
  82.    DisplayImageInBuf(TheInImage,INITVGALOADPALETTE,NOWAITFORKEY);
  83.  
  84.    if (RealConvolution(TheInImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  85.            LP1,3,3,0,FALSE,&TheOutImage) == NoError)
  86.    {
  87.       DisplayImageInBuf(TheOutImage,NOVGAINIT,WAITFORKEY);
  88.       if (GenPCXFiles)
  89.      WritePCXFile("p2c10i1b",8,320,200,1,320);
  90.       farfree((BYTE far *)TheOutImage);
  91.    }
  92.  
  93.    DisplayImageInBuf(TheInImage,NOVGAINIT,NOWAITFORKEY);
  94.    if (Convolution(TheInImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  95.            HP1,3,3,0,FALSE,&TheOutImage) == NoError)
  96.    {
  97.       DisplayImageInBuf(TheOutImage,NOVGAINIT,WAITFORKEY);
  98.       if (GenPCXFiles)
  99.      WritePCXFile("p2c10i1c",8,320,200,1,320);
  100.       farfree((BYTE far *)TheOutImage);
  101.    }
  102.  
  103.    DisplayImageInBuf(TheInImage,NOVGAINIT,NOWAITFORKEY);
  104.    if (Convolution(TheInImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  105.            LAP2,3,3,0,FALSE,&TheOutImage) == NoError)
  106.    {
  107.       DisplayImageInBuf(TheOutImage,NOVGAINIT,WAITFORKEY);
  108.       if (GenPCXFiles)
  109.      WritePCXFile("p2c10i1d",8,320,200,1,320);
  110.       farfree((BYTE far *)TheOutImage);
  111.    }
  112.  
  113.    DisplayImageInBuf(TheInImage,NOVGAINIT,NOWAITFORKEY);
  114.    if (Convolution(TheInImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  115.            GN,3,3,0,FALSE,&TheOutImage) == NoError)
  116.    {
  117.       DisplayImageInBuf(TheOutImage,NOVGAINIT,WAITFORKEY);
  118.       if (GenPCXFiles)
  119.      WritePCXFile("p2c10i1e",8,320,200,1,320);
  120.       farfree((BYTE far *)TheOutImage);
  121.    }
  122.  
  123.    DisplayImageInBuf(TheInImage,NOVGAINIT,NOWAITFORKEY);
  124.    if (Convolution(TheInImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  125.            GE,3,3,0,FALSE,&TheOutImage) == NoError)
  126.    {
  127.       DisplayImageInBuf(TheOutImage,NOVGAINIT,WAITFORKEY);
  128.       if (GenPCXFiles)
  129.      WritePCXFile("p2c10i1f",8,320,200,1,320);
  130.       farfree((BYTE far *)TheOutImage);
  131.    }
  132.  
  133.    DisplayImageInBuf(TheInImage,NOVGAINIT,NOWAITFORKEY);
  134.    if (Convolution(TheInImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  135.            BLUR,5,5,4,FALSE,&TheOutImage) == NoError)
  136.    {
  137.       DisplayImageInBuf(TheOutImage,NOVGAINIT,WAITFORKEY);
  138.       if (GenPCXFiles)
  139.      WritePCXFile("p2c10i1g",8,320,200,1,320);
  140.       farfree((BYTE far *)TheOutImage);
  141.    }
  142.  
  143.    /* generate image sequence p2ch10i2 - Sobel Edge Detection */
  144.    if (ReadPCXFileToBuf (InFileName2,&TheInImage) != NoError)
  145.       exit(1);
  146.  
  147.    DisplayImageInBuf(TheInImage,NOVGAINIT,NOWAITFORKEY);
  148.    if (SobelEdgeDet(TheInImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  149.             10,FALSE,&TheOutImage) == NoError)
  150.    {
  151.       DisplayImageInBuf(TheOutImage,NOVGAINIT,WAITFORKEY);
  152.       if (GenPCXFiles)
  153.      WritePCXFile("p2c10i2b",8,320,200,1,320);
  154.       farfree((BYTE far *)TheOutImage);
  155.    }
  156.    /* Do detection again this time with overlaying */
  157.    DisplayImageInBuf(TheInImage,NOVGAINIT,NOWAITFORKEY);
  158.    if (SobelEdgeDet(TheInImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  159.             10,TRUE,&TheOutImage) == NoError)
  160.    {
  161.       DisplayImageInBuf(TheOutImage,NOVGAINIT,WAITFORKEY);
  162.       if (GenPCXFiles)
  163.      WritePCXFile("p2c10i2c",8,320,200,1,320);
  164.       farfree((BYTE far *)TheOutImage);
  165.    }
  166.  
  167.    /* generate image sequence p2ch10i3 - Median Filtering */
  168.    if (ReadPCXFileToBuf (InFileName3,&TheInImage) != NoError)
  169.       exit(1);
  170.  
  171.    DisplayImageInBuf(TheInImage,NOVGAINIT,NOWAITFORKEY);
  172.    if (MedianFilter(TheInImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  173.             3,3,&TheOutImage) == NoError)
  174.    {
  175.       DisplayImageInBuf(TheOutImage,NOVGAINIT,WAITFORKEY);
  176.       if (GenPCXFiles)
  177.      WritePCXFile("p2c10i3b",8,320,200,1,320);
  178.       CopyImage(TheOutImage,TheInImage);
  179.       farfree((BYTE far *)TheOutImage);
  180.    }
  181.  
  182.    /* apply filtering twice for effect */
  183.    if (MedianFilter(TheInImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
  184.             3,3,&TheOutImage) == NoError)
  185.    {
  186.       DisplayImageInBuf(TheOutImage,NOVGAINIT,WAITFORKEY);
  187.       if (GenPCXFiles)
  188.      WritePCXFile("p2c10i3c",8,320,200,1,320);
  189.       CopyImage(TheOutImage,TheInImage);
  190.       farfree((BYTE far *)TheOutImage);
  191.    }
  192.  
  193.    farfree((BYTE far *)TheInImage);
  194.    restorecrtmode();
  195.    closegraph();
  196. }
  197.