Solved

Image processing

Posted on 2004-04-10
6
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…
Introduction to Processes

624 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