Explore BrainMass

Code for reading Raster Data

'A project on Number plates; I have successfully implemented a
method for character localisation, character segmentation and character

Main problem at the moment is to find a method capable of reading
raster data and print it to file. Have segmented characters into a 10x10
pixels, 8-bit(Bitmap) black and white.
It has been suggested that i should use a code developed by Bill Green
(www.pages.drexel.edu/~weg22/colorBMP.html ) click on tutorial and raster
data tutorial (8-bit).
Have downloaded the code, made a few changes but could not
unfortunately get the right answer.
Have actually got some answers but when a compare for example the
values for letter E from the program and the values of letter E with Photo
shop, the result is not the same.

If you could help, please let me know.

Below is the code with little modification made.

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

typedef struct {int rows; int cols; unsigned char* data;} sImage;

long getImageInfo(FILE*, long, int);
long copyImageInfo(FILE*, FILE*, int);
long copyColorTable(FILE*, FILE*);

int main(int argc, char* argvUnknown Variable:)
FILE *bmpInput, *rasterOutput;
sImage originalImage;
unsigned char someChar;
unsigned char* pChar;
int nColors;
long fileSize;
int vectorSize, r, c;

/* initialize pointer */
someChar = '0';
pChar = &someChar;

// if(argc < 2)
// {
// printf("Usage: %s bmpInput.bmpn", argvUnknown Variable:0);
// exit(0);

argvUnknown Variable:1="LetterE.bmp";
printf("Reading filename %sn", argvUnknown Variable:1);

/*--------READ INPUT FILE------------*/
bmpInput = fopen(argvUnknown Variable:1, "rb");
fseek(bmpInput, 0L, SEEK_END);
rasterOutput = fopen("LetterE.txt", "w");

/*--------GET BMP DATA---------------*/
originalImage.cols = (int)getImageInfo(bmpInput, 18, 4);
originalImage.rows = (int)getImageInfo(bmpInput, 22, 4);
fileSize = getImageInfo(bmpInput, 2, 4);
nColors = getImageInfo(bmpInput, 46, 4);
vectorSize = fileSize - (14 + 40 + 4*256);

/*-------PRINT TO SCREEN-------------*/
printf("Width: %dn", originalImage.cols);
printf("Height: %dn", originalImage.rows);
printf("File size: %ldn", fileSize);
printf("# Colors: %dn", nColors);
printf("Vector size: %dn", vectorSize);

/*----------READ RASTER DATA---------*/
fseek(bmpInput, (54 + 4*nColors), SEEK_SET);

for(r=0; r<=originalImage.rows - 1; r++)
for(c=0; c<=originalImage.cols - 1; c++)
fread(pChar, sizeof(char), 1, bmpInput);
fprintf(rasterOutput, "(%d, %d) = %dn", r, c, *pChar);



/*----------GET IMAGE INFO SUBPROGRAM--------------*/
long getImageInfo(FILE* inputFile, long offset, int numberOfChars)
unsigned char *ptrC;
long value = 0L;
unsigned char dummy;
int i;

dummy = '0';
ptrC = &dummy;

fseek(inputFile, offset, SEEK_SET);

for(i=1; i<=numberOfChars; i++)
fread(ptrC, sizeof(char), 1, inputFile);
/* calculate value based on adding bytes */
value = (long)(value + (*ptrC)*(pow(256, (i-1))));

} /* end of getImageInfo */


Solution Preview

Dear student,
As you have mentioned problem to be reading a raster file and printing data. I have attached the run C ...