Purchase Solution

Code for reading Raster Data

Not what you're looking for?

Ask Custom Question

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

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>

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

/*-------PROTOTYPES---------*/
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);
}
}

fclose(bmpInput);
fclose(rasterOutput);

}

/*----------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))));
}
return(value);

} /* end of getImageInfo */

Purchase this Solution

Solution Preview

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

Solution provided by:
Education
  • BSc (Hons), University of Colombo - Sri Lanka
  • MEngSc, University of Melbourne
  • Certificate IV in Training & Assessment , Australian Business Council
Recent Feedback
  • "Thank you!"
  • "Thank you."
  • "Thanks a lot for you help and support"
  • "Sorry about the late payment but the assignment was sufficient and appreciated. Good work"
  • "Great description! Thank you for your quick response."
Purchase this Solution


Free BrainMass Quizzes
Excel Introductory Quiz

This quiz tests your knowledge of basics of MS-Excel.

Basic Networking Questions

This quiz consists of some basic networking questions.

C++ Operators

This quiz tests a student's knowledge about C++ operators.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.

C# variables and classes

This quiz contains questions about C# classes and variables.