Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 8th, 2007, 8:07 AM   #1
tommy_chai
Newbie
 
Join Date: Oct 2007
Posts: 1
Rep Power: 0 tommy_chai is on a distinguished road
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_min1,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);
tommy_chai is offline   Reply With Quote
Old Oct 8th, 2007, 9:18 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
You should read the sticky "How to Post" thread; particularly with regard to the use of code tags. These are HTML pages; they eat whitespace. Your formatting goes bye-bye. Your code is thus ugly and difficult to read. Code tags prevent that.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB 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
OnlineTextEditor.Com! Sane Show Off Your Open Source Projects 43 Jun 16th, 2006 8:55 AM
Help in QBASIC (I think it's similar to VB) phoenix987 Visual Basic 3 May 9th, 2005 12:33 PM
Help with a QBASIC program phoenix987 Other Programming Languages 4 May 5th, 2005 12:27 PM
After execution - Error cannot locate /Skin File? wchar Visual Basic 1 Mar 5th, 2005 9:04 PM
airport Log program using 3D linked List : problem reading from file gemini_shooter C++ 0 Mar 2nd, 2005 4:12 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 6:49 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC