home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright 1990 by John Wiley & Sons, Inc.
- All Rights Reserved.
- */
- /****************************************/
- /* Image Processing Code */
- /* Point Process Functions */
- /* written in Turbo C 2.0 */
- /* by */
- /* Craig A. Lindley */
- /* */
- /* Vers: 1.0 Last Update: 12/26/89 */
- /****************************************/
-
- #include <stdio.h>
- #include <alloc.h>
- #include <process.h>
- #include <graphics.h>
- #include "misc.h"
- #include "pcx.h"
- #include "vga.h"
- #include "imagesup.h"
- #include "ptprocess.h"
-
- /* main point process program */
-
- void main(void)
- {
- char *InFileName1 = "p2ch9i1a";
- char *InFileName2 = "p2ch9i2a";
- char *InFileName3 = "p2ch9i3a";
- char *InFileName4a = "p2ch9i4a";
- char *InFileName4b = "p2ch9i4c";
- char *InFileName4c = "p2ch9i4e";
- char *InFileName5 = "p2ch9i5a";
- char *InFileName6 = "p2ch9i6a";
-
- BYTE huge *TheImage;
- unsigned GenPCXFiles = FALSE; /* controls generation of output files */
- BYTE PseudoColorLUT[MAXQUANTLEVELS];
-
- InitGraphics();
-
- printf("Point Transform Example Program\n\n");
- printf("Reading the Image PCX File into memory\n");
-
- /* generate image sequence p2ch9i1 - Image brightening */
- /* load the PCX file into memory */
- if (ReadPCXFileToBuf (InFileName1,&TheImage) != NoError)
- exit(1);
-
- /* display the image pointed at by TheImage */
- DisplayImageInBuf(TheImage,INITVGALOADPALETTE,WAITFORKEY);
- DisplayHist(TheImage,MINCOLNUM,MINROWNUM,130,MAXROWS);
- if (GenPCXFiles)
- WritePCXFile("p2ch9i1b",8,320,200,1,320);
- AdjImageBrightness(TheImage,+17,MINCOLNUM,MINROWNUM,130,MAXROWS);
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2ch9i1c",8,320,200,1,320);
- DisplayHist(TheImage,MINCOLNUM,MINROWNUM,130,MAXROWS);
- if (GenPCXFiles)
- WritePCXFile("p2ch9i1d",8,320,200,1,320);
-
- farfree((BYTE far *)TheImage);
-
-
- /* generate image sequence p2ch9i2 - Image negation */
- /* load the PCX file into memory */
- if (ReadPCXFileToBuf (InFileName2,&TheImage) != NoError)
- exit(1);
-
- /* display the image pointed at by TheImage */
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
- NegateImage(TheImage,0,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2ch9i2b",8,320,200,1,320);
-
- farfree((BYTE far *)TheImage);
-
- /* reload the PCX file into memory */
- if (ReadPCXFileToBuf (InFileName2,&TheImage) != NoError)
- exit(1);
-
- /* display the image pointed at by TheImage */
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
- NegateImage(TheImage,50,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2ch9i2c",8,320,200,1,320);
-
- farfree((BYTE far *)TheImage);
-
-
- /* generate image sequence p2ch9i3 - Image thresholding */
- /* load the PCX file into memory */
- if (ReadPCXFileToBuf (InFileName3,&TheImage) != NoError)
- exit(1);
-
- /* display the image pointed at by TheImage */
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
- ThresholdImage(TheImage,35,110,50,105,105);
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2ch9i3b",8,320,200,1,320);
-
- farfree((BYTE far *)TheImage);
-
- /* generate image sequence p2ch9i4 - A Study of Contrasts */
- /* load the PCX file into memory */
- if (ReadPCXFileToBuf (InFileName4a,&TheImage) != NoError)
- exit(1);
-
- /* display the image pointed at by TheImage */
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
- DisplayHist(TheImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
- if (GenPCXFiles)
- WritePCXFile("p2ch9i4b",8,320,200,1,320);
-
- farfree((BYTE far *)TheImage);
-
- /* load the PCX file into memory */
- if (ReadPCXFileToBuf (InFileName4b,&TheImage) != NoError)
- exit(1);
-
- /* display the image pointed at by TheImage */
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
- DisplayHist(TheImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
- if (GenPCXFiles)
- WritePCXFile("p2ch9i4d",8,320,200,1,320);
-
- farfree((BYTE far *)TheImage);
-
- /* load the PCX file into memory */
- if (ReadPCXFileToBuf (InFileName4c,&TheImage) != NoError)
- exit(1);
-
- /* display the image pointed at by TheImage */
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
- DisplayHist(TheImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
- if (GenPCXFiles)
- WritePCXFile("p2ch9i4f",8,320,200,1,320);
-
- farfree((BYTE far *)TheImage);
-
- /* generate image sequence p2ch9i5 - Contrast Stretching */
- /* load the PCX file into memory */
- if (ReadPCXFileToBuf (InFileName5,&TheImage) != NoError)
- exit(1);
-
- /* display the image pointed at by TheImage */
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
- DisplayHist(TheImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
- if (GenPCXFiles)
- WritePCXFile("p2ch9i5b",8,320,200,1,320);
- StretchImageContrast(TheImage,Histogram,475,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2ch9i5c",8,320,200,1,320);
- DisplayHist(TheImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS);
- if (GenPCXFiles)
- WritePCXFile("p2ch9i5d",8,320,200,1,320);
- farfree((BYTE far *)TheImage);
-
- /* generate image sequence p2ch9i6 - Pseudo Coloring */
- /* load the PCX file into memory */
- if (ReadPCXFileToBuf (InFileName6,&TheImage) != NoError)
- exit(1);
-
- /* display the image pointed at by TheImage */
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
-
- /* Set color reg 64 to red, 65 to green and 66 to blue */
- SetAColorReg(64,63,0,0);
- SetAColorReg(65,0,63,0);
- SetAColorReg(66,0,0,63);
-
- /*
- Calling InitializeLUT establishes straight through
- mapping for the LUT. Only the values that need to
- be changed from their default will be changed.
- */
- InitializeLUT(PseudoColorLUT);
- /*
- Assign color register 64 to pixel values
- 60 - 63
- */
- PseudoColorLUT[63] = 64;
- PseudoColorLUT[62] = 64;
- PseudoColorLUT[61] = 64;
- PseudoColorLUT[60] = 64;
- /*
- Assign color register 65 to pixel values
- 56 - 59
- */
- PseudoColorLUT[59] = 65;
- PseudoColorLUT[58] = 65;
- PseudoColorLUT[57] = 65;
- PseudoColorLUT[56] = 65;
- /*
- Assign color register 66 to pixel values
- 52 - 55
- */
- PseudoColorLUT[55] = 66;
- PseudoColorLUT[54] = 66;
- PseudoColorLUT[53] = 66;
- PseudoColorLUT[52] = 66;
- /*
- At this point the LUT is initialized
- completely. Next, apply the transform to
- the image data.
- */
- PtTransform(TheImage,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,PseudoColorLUT);
-
- /* display the pseudo colored image */
- DisplayImageInBuf(TheImage,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2ch9i6b",8,320,200,1,320);
- farfree((BYTE far *)TheImage);
-
- restorecrtmode();
- closegraph();
- }