home *** CD-ROM | disk | FTP | other *** search
- /*
- Copyright 1990 by John Wiley & Sons, Inc.
- All Rights Reserved.
- */
- /****************************************/
- /* Image Processing Code */
- /* Frame Process Functions */
- /* Demo Program */
- /* written in Turbo C 2.0 */
- /* by */
- /* Craig A. Lindley */
- /* */
- /* Vers: 1.0 Last Update: 12/26/89 */
- /****************************************/
-
- #include <stdio.h>
- #include <conio.h>
- #include <dos.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"
- #include "frprocess.h"
-
- /* main frame process demonstration program */
-
- void main(void)
- {
- char *InFileName1 = "p2c11i1a";
- char *InFileName2 = "p2c11i1b";
- char *InFileName3 = "p2c11i2a";
- char *InFileName4 = "p2c11i2b";
- char *InFileName5 = "p2c11i3a";
- char *InFileName6 = "p2c11i4a";
- char *InFileName7 = "p2c11i4b";
- char *InFileName8 = "p2c11i5a";
-
- BYTE huge *InImage1;
- BYTE huge *InImage2;
- BYTE huge *Buffer;
-
- unsigned GenPCXFiles = FALSE; /* controls output file generation */
- BYTE LUT[MAXQUANTLEVELS];
- unsigned Index;
-
-
- /* Initialize graphic subsystem */
- InitGraphics();
-
- printf("Frame Transform Example Program Program\n\n");
- printf("Reading the Image PCX Files into memory\n");
-
- /*
- Allocate enough memory to save destination image
- as it will be written over during each transform.
- */
-
- Buffer = (BYTE huge *) farcalloc(RASTERSIZE,sizeof(BYTE));
- if (Buffer == NULL)
- {
- printf("FRTEST Error: No memory for buffer\n");
- exit(ENoMemory);
- }
-
- /*
- Image Sequence One - Background substraction
- */
-
- /*
- Read source and destination images into memory. The
- image read into InImage2 is considered the destination
- image.
- */
- if (ReadPCXFileToBuf (InFileName1,&InImage1) != NoError)
- exit(1);
- DisplayImageInBuf(InImage1,INITVGALOADPALETTE,WAITFORKEY);
-
- if (ReadPCXFileToBuf (InFileName2,&InImage2) != NoError)
- exit(1);
- DisplayImageInBuf(InImage2,NOVGAINIT,WAITFORKEY);
- /*
- Combine source image with destination image by the subtraction
- process. The destination image is overwritten.
- */
- CombineImages(InImage2,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
- InImage1,MINCOLNUM,MINROWNUM,Sub,0);
-
- /*
- Display image with background removed
- */
- DisplayImageInBuf(InImage1,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2c11i1c",8,320,200,1,320);
- /*
- Return memory taken up by the image buffers
- */
- farfree((BYTE far *) InImage1);
- farfree((BYTE far *) InImage2);
-
- /*
- Image Sequence Two - Circuit board inspection
- */
-
- /*
- Read source and destination images into memory. The
- image read into InImage2 is considered the destination
- image.
- */
- if (ReadPCXFileToBuf (InFileName3,&InImage1) != NoError)
- exit(1);
- DisplayImageInBuf(InImage1,NOVGAINIT,WAITFORKEY);
-
- if (ReadPCXFileToBuf (InFileName4,&InImage2) != NoError)
- exit(1);
- DisplayImageInBuf(InImage2,NOVGAINIT,WAITFORKEY);
-
- /*
- Combine source image with destination image by the subtraction
- process. The destination image is overwritten.
- */
- CombineImages(InImage2,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
- InImage1,MINCOLNUM,MINROWNUM,Sub,0);
-
- /*
- Display the differences between the circuit board images
- */
- DisplayImageInBuf(InImage1,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2c11i2c",8,320,200,1,320);
-
- /*
- Image Sequence Three - Image Masking
- */
-
- /* Read in the image to be masked */
- if (ReadPCXFileToBuf (InFileName5,&InImage1) != NoError)
- exit(1);
- DisplayImageInBuf(InImage1,NOVGAINIT,WAITFORKEY);
-
- /* Prepare the image mask */
- ClearImageArea(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,WHITE);
- ClearImageArea(Buffer,200,10,80,180,BLACK);
-
- /* Display mask */
- DisplayImageInBuf(Buffer,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2c11i3b",8,320,200,1,320);
-
- /* Preform masking operation */
- CombineImages(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
- InImage1,MINCOLNUM,MINROWNUM,And,0);
- DisplayImageInBuf(InImage1,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2c11i3c",8,320,200,1,320);
-
- /*
- Return memory taken up by the image buffers
- */
- farfree((BYTE far *) InImage1);
- farfree((BYTE far *) InImage2);
-
- /*
- Image Sequence Four - Various frame processes
- */
-
- /*
- Read source and destination images into memory. The
- image read into InImage2 is considered the destination
- image.
- */
-
- if (ReadPCXFileToBuf (InFileName6,&InImage1) != NoError)
- exit(1);
- DisplayImageInBuf(InImage1,NOVGAINIT,WAITFORKEY);
-
- if (ReadPCXFileToBuf (InFileName7,&InImage2) != NoError)
- exit(1);
- DisplayImageInBuf(InImage2,NOVGAINIT,WAITFORKEY);
-
- /*
- Make a copy of the destination image so it can be
- restored after each frame process without having
- to reload it from disk.
- */
- CopyImage(InImage2,Buffer);
-
- /*
- Combine source image with destination image by addition
- process. The destination image is overwritten.
- */
- CombineImages(InImage1,32,20,256,160,
- InImage2,32,20,Add,1);
-
- DisplayImageInBuf(InImage2,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2c11i4c",8,320,200,1,320);
-
- /*
- Restore InImage2 the destination buffer for use with the
- next frame process transformation. Now we are back in our
- original state with the source image in InImage1 and the
- destination image in InImage2.
- */
- CopyImage(Buffer,InImage2);
-
- /*
- Combine source image with destination image by bitwise OR
- process. The destination image is overwritten.
- */
- CombineImages(InImage1,32,20,256,160,
- InImage2,32,20,Or,0);
-
- DisplayImageInBuf(InImage2,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2c11i4d",8,320,200,1,320);
-
- CopyImage(Buffer,InImage2);
-
- /*
- Combine source image with destination image by average
- process. The destination image is overwritten.
- */
- CombineImages(InImage1,32,20,256,160,
- InImage2,32,20,Ave,0);
-
- DisplayImageInBuf(InImage2,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2c11i4e",8,320,200,1,320);
-
- CopyImage(Buffer,InImage2);
-
- /*
- Combine source image with destination image by maximum
- process. The destination image is overwritten.
- */
- CombineImages(InImage1,32,20,256,160,
- InImage2,32,20,Max,0);
-
- DisplayImageInBuf(InImage2,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2c11i4f",8,320,200,1,320);
-
- CopyImage(Buffer,InImage2);
-
- /*
- Combine source image with destination image by minimum
- process. The destination image is overwritten.
- */
- CombineImages(InImage1,32,20,256,160,
- InImage2,32,20,Min,0);
-
- DisplayImageInBuf(InImage2,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2c11i4g",8,320,200,1,320);
-
- CopyImage(Buffer,InImage2);
- /*
- Return memory taken up by the image buffers
- */
- farfree((BYTE far *) InImage1);
- farfree((BYTE far *) InImage2);
-
- /*
- Image Sequence Five - Determining Image Pixel Intensities
- */
- if (ReadPCXFileToBuf (InFileName8,&InImage1) != NoError)
- exit(1);
- DisplayImageInBuf(InImage1,NOVGAINIT,WAITFORKEY);
- /*
- Set all bytes of InImage2 buffer to a value of 32
- */
- ClearImageArea(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,32);
- DisplayImageInBuf(Buffer,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2c11i5b",8,320,200,1,320);
-
- /*
- Combine source image with destination image using the Xor
- process. The destination image is overwritten.
- */
- CombineImages(InImage1,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,
- Buffer,MINCOLNUM,MINROWNUM,Xor,0);
-
- /*
- After Xor operation all pixels which had the value of 32 black
- and all other pixels are some other color. We will now use a
- point process to convert black pixels to white and all others
- to black.
- */
- for (Index=0; Index < MAXQUANTLEVELS; Index++)
- LUT[Index] = 0;
-
- LUT[0] = MAXSAMPLEVAL;
-
- PtTransform(Buffer,MINCOLNUM,MINROWNUM,MAXCOLS,MAXROWS,LUT);
- DisplayImageInBuf(Buffer,NOVGAINIT,WAITFORKEY);
- if (GenPCXFiles)
- WritePCXFile("p2c11i5c",8,320,200,1,320);
-
- /*
- Free all allocated memory
- */
- farfree((BYTE far *) InImage1);
- farfree((BYTE far *) Buffer);
-
- restorecrtmode();
- closegraph();
- }