hopefully u can help us out this is our source code we can display it
but we need to process it we believe we can process it using some of
that code but we not sure cause we can display the new image
thanks
#include <cstdlib>
#include <iostream>
#include <stdio.h>
#include <malloc.h>
#include <process.h>
#include <signal.h>
#include <unistd.h>
#include "graymorf.h"
using namespace std;
//Allocate memory for file
unsigned char **imalloc(int numlines, int numbytes)
{
unsigned char **iptr;
short i;
iptr=(unsigned char **)malloc(numlines * sizeof(unsigned
char *));
if(iptr==NULL)
{
fprintf(stderr, "Memory allocation failed: Aborting");
exit(255);
}
iptr[0]=(unsigned char *)malloc(numlines*numbytes*sizeof
(unsigned char));
if(iptr[0]==NULL)
{
fprintf(stderr, "Memory allocation failed: Aborting");
exit(255);
}
for(i=1; i<numlines; i++)
iptr[i]=iptr[i-1]+numbytes;
return iptr;
}
//This function will display the image in irfanview
int irfanviewDisp(char *file, int pos)
{
char cmdLine[100], buf[2];
strcpy(cmdLine, "C:\\Program Files\\Irfanview\\i_view32.exe");
char position[100], value[30];
strcpy(position, "/pos=(");
sprintf(value, "%d", pos);
strcat(position, value);
strcat(position, ",");
strcat(position, value);
strcat(position, ")");
cout << position << endl;
return spawnl(_P_NOWAIT, cmdLine, "iv.exe", file, position, NULL);
}
//Bitmap File Header
typedef struct tagBITMAPFILEHEADER
{
unsigned short int bfType; //specifies the file
type
unsigned int bfSize; //Specifies the size
in bytes of the bitmap file
unsigned short int bfReserved1, bfReserved2; //reserved,
both must be zero
unsigned int bfOffset; //specifies the
offset in bytes from BMFH to bmp bits
} BITMAPFILEHEADER;
//Bitmap Info Header
typedef struct tagBITMAPINFOHEADER
{
unsigned int biSize; //specifies the number of bytes
required byby the struct
int biWidth, biHeight; //sepcifies the width and height in
pixels
unsigned short int biPlanes; //specifies the number of color
planes, must be 1
unsigned short int biBits; //specifies the number of bits
per pixel
unsigned int biCompression; //specifies the type of
compression
unsigned int biImagesize; //size of image in bytes
int biXResolution, biYResolution; //number of pixels per
meter in xand y axis
unsigned int binColors; //number of colors used
by the bitmap
unsigned int biImportantcolors; //number of colors that
are important
}BITMAPINFOHEADER;
unsigned char *DisplayProcessedBitmap(char *filename,
BITMAPINFOHEADER *bitmapInfoHeader)
{
FILE *fp;
BITMAPFILEHEADER bitmapFileHeader;
unsigned char *bitmapImage;
int imageIdx=0;
unsigned char tempRGB;
fp=fopen(filename, "rb");
if(fp==NULL)
return NULL;
fread(&bitmapFileHeader, sizeof(BITMAPFILEHEADER),1,fp);
if(bitmapFileHeader.bfType!=0x4d42)
{
fclose(fp);
return NULL;
}
fread(bitmapInfoHeader, sizeof(bitmapInfoHeader),1,fp);
fseek(fp, bitmapFileHeader.bfOffset, SEEK_SET);
bitmapImage=(unsigned char*)malloc(bitmapInfoHeader-
>biImagesize);
if(!bitmapImage)
{
free(bitmapImage);
fclose(fp);
return NULL;
}
// fread(bitmapImage, bitmapInfoHeader->biImagesize, fp)
//if(bitmapImage==NULL)
{
fclose(fp);
return NULL;
}
for(imageIdx=0; imageIdx<bitmapInfoHeader->biImagesize;
imageIdx+3)
{
tempRGB=bitmapImage[imageIdx];
bitmapImage[imageIdx]=bitmapImage
[imageIdx+2];
bitmapImage[imageIdx+2]=tempRGB;
}
//Process the pixels in the BMP
image r,g,b;
image *newFile;
image &d=*newFile;
for(int i=0; i<r.numLines; i++)
{
for(int j=0; j<r.numPix; j++)
{
(int)d.buf[i][j]=(((int)r.buf[i][j])-((int)g.buf[i]
[j]+(int)b.buf[i][j])/2)+128;
}
}
fclose(fp);
return bitmapImage;
}
/*//d=new image being created
//r=red pixels
//g=green pixels
//b=blue pixels
image enhanceRed(char *filename, image &d, image r, image g, image b)
{
image out=createImage(d);
for(int i=0; i<r.numLines; i++)
{
for(int j=0; j<r.numPix; j++)
{
(int)d.buf[i][j]=(((int)r.buf[i][j])-((int)g.buf[i]
[j]+(int)b.buf[i][j])/2)+128;
}
}
return out;
}*/
int main(int argc, char *argv[])
{
BITMAPINFOHEADER bitmapInfoHeader;
DisplayProcessedBitmap("image.bmp", &bitmapInfoHeader);// image
is our file name
irfanviewDisp("image.bmp",200);
system("PAUSE");
return EXIT_SUCCESS;
}
//Grayscale Morphology Header File
// this is graymorf.h
#define max(a,b) (((a)>(b))?(a):(b))
#define min(a,b) (((a)<(b))?(a):(b))
#define DILATE_VALUE 0
#define ERODE_VALUE 255
struct image {
unsigned char ** buf;
int numLines, numPix;
};
struct intImage {
int ** buf;
int numLines, numPix;
};
struct floatImage {
float ** buf;
int numLines, numPix;
};
unsigned char **imalloc(int numlines, int numbytes);
//Free 2-D memory arrays
void free_image(unsigned char **im_buf);
void free_image(int **im_buf);
void free_image(float **im_buf);
image createImage(image source);
int createImage(int numLines, int numPix); //Overloading
image createIntImage(int numLines, int numPix);
image createFloatImage(int numLines, int numPix);
image createImage(int numLines, int numPix, unsigned char **buf);
void deleteImage(image &img);
void kim(image &im1, image &im2, image &im3, image &im4, image &im5);
void kim(image &im1, image &im2, image &im3, image &im4);
void kim(image &im1, image &im2, image &im3);
void kim(image &im1, image &im2);
void kim(image &im1); //Overload for 1 arg
bool swapImBufs(image &one, image &two);
image copybuf(image source);
void fix_border(image in, image out);
void dilateV(image in, image out);
void dilateH(image in, image out);
void dilateS1(image in, image out);
void dilateS2(image in, image out);
void erodeV(image in, image out);
void erodeH(image in, image out);
void erodeS1(image in, image out);
void erodeS2(image in, image out);
image sqDilate(image in, int iter);
image sqErode(image in, int iter);
image imSubtract(image image1, image image2);
image octErode(image in, int iter);
image octDilate(image in, int iter);
image octCLose(image in, int iter);
image octOpen(image in, int iter);
//Save an image buffer to a PGM fiel
int writePGM(char *fname, image save);
//Create image buffer and load with data from PGM file
image readPGM(char *fname);
image rectDilate(image in, int hiter, int viter);
image rectErode(image in, int hiter, int viter);
image rectOpen(image in, int hiter, int viter);
image rectClose(image in, int hiter, int viter);
image imAnd(image image1, image image2);
int otsu(image img, int border);
image imThresh(image in, int thresh);