Go to Post FIRST is not about robots or which roller coaster we get to ride... it is about people. - Andy Baker [more]
Home
Go Back   Chief Delphi > Technical > Programming
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 08-10-2007, 08:22
tommy_chai tommy_chai is offline
Registered User
no team
 
Join Date: Oct 2007
Location: Msia
Posts: 12
tommy_chai is an unknown quantity at this point
How to write image data to binary PGM file format(P5)?

Hi all,
I fail to write the image data to binary PGM format (P5).
Let's say i have to write a image data into PGM P5 format.
I have the information for width, height, Y_min, Y_max, XL, XR and the TEMPLATE1 (data matrix) ==>A region of interest from an image.
Y_min & Y_max = minimum and maximum of the height value.
XL & XR = min and max of the width value for the image.

First, i call the subroutine,
write_data_grey_binary(width1,height1,XL1,XR1,Y_mi n1,Y_max1,filename99[total],TEMPLATE1);

void write_data_grey_binary(width,height,XL,XR,Y_min,Y_ max,filename,output)
int width,height,XL,XR,Y_min,Y_max;
char *filename;
unsigned char** output;
{
int i,j,nread;
FILE *fp;
unsigned char* temp;

if((fp = fopen(filename,"w")) == NULL){
printf("File 333 output data can not open\n");
exit(1);
}

fprintf(fp,"P5\n%d %d\n%d\n",width,height,(GRYSCL-1));

temp = (unsigned char*)calloc(height*width, sizeof(unsigned char));

for(i=Y_min;i<=Y_max;i++){
for(j=XL;j<=XR;j++){
temp[(i*width)+j]= (unsigned char)output[i][j];
}
}
nread = fwrite((void*)temp, sizeof(unsigned char), (height*width), fp);
free(temp);
fclose(fp);
return(0);
}

However , i have an error at the line " temp[(i*width)+j]= (unsigned char)output[i][j]; ".
However, this coding can be ran when i want to write the full image like:
write_data_grey_binary(width,height,0,width-1,0,height-1,filename99[total],inpgrey);
Closed Thread


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Scouting Data Interchange Format proegssilb Scouting 7 06-06-2007 19:29
Reading binary data from a file and writing it in VB complete Programming 1 02-01-2006 21:21
File Format Conversion Solidworks to Inventor coreyjon Inventor 2 21-01-2005 20:11
Standardized Scouting System/File Format phrontist General Forum 15 18-04-2004 17:05
Autodesk Inventor -> 3ds Max (File Format) Adrian Wong Inventor 1 22-01-2002 23:06


All times are GMT -5. The time now is 09:33.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi