Solved

Image processing

Posted on 2004-04-10
6
220 Views
Last Modified: 2010-04-17
How do I  read image which is stored in the pgmor binary file?  Complete code is requested such as file operations and call from main() function!!!!!!!!!!!!!
0
Comment
Question by:learncpp
  • 3
6 Comments
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10802187
I am not familiar with the pgmor format. Do you mean PGM format?
0
 

Author Comment

by:learncpp
ID: 10802228
Yes I meant PGM format.
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 100 total points
ID: 10802571
You need the netpbm package for this (you can find this compiled for a number of architectures at http://netpbm.sourceforge.net/). Once you have this installed, you can use code like this:

#include "pgm.h"

int
main(int argc, char *argv[])
{
    int format;
    int rows, cols;
    gray maxval;
    int row;
    gray* grayrow;
    FILE * input;

    pgm_init(&argc, argv);

    if (argc != 2)
        pm_error("Usage:\n%s <pgm file>\n\n", argv[0]);

    input = fopen(argv[1], "r");
    if (input == NULL)
    {
        pm_error("Cannot open file %s\n", argv[1]);
        exit(-1);
    }

    pgm_readpgminit(input, &cols, &rows, &maxval, &format);
    grayrow = pgm_allocrow(cols);
    for (row = 0; row < rows; row++)
    {
        pgm_readpgmrow(input, grayrow, cols, maxval, format);
        // do something with the data in grayrow, the next read operation will overwrite this again.
    }
    pgm_freerow(grayrow);
    pm_close(input);

    exit(0);
}

You can also implement the read function yourself by implementing this format spec:
http://netpbm.sourceforge.net/doc/pgm.html
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
ID: 10941275
Can you please explain the "C" grade. The provided sample program did either answer your question, or it did not. In the latter case, you should have asked for more information. If the sample did answer your question I don't understand your grading.
Please make yourself familiar with the EE grading guidelines at http://www.experts-exchange.com/Programming/help.jsp#hi73
I'll request a review of this grade.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Looking for example pivot year code used in Y2K 4 62
tidtcpserver connection lost handle 2 71
Java Loop 6 50
"Black Box" Testing of Control System Software 2 26
I know it’s not a new topic to discuss and it has lots of online contents already available over the net. But Then I thought it would be useful to this site’s visitors and can have online repository on vim most commonly used commands. This post h…
A short article about problems I had with the new location API and permissions in Marshmallow
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now