• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 237
  • Last Modified:

Image processing

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!!!!!!!!!!!!!
  • 3
1 Solution
Karl Heinz KremerCommented:
I am not familiar with the pgmor format. Do you mean PGM format?
learncppAuthor Commented:
Yes I meant PGM format.
Karl Heinz KremerCommented:
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"

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]);

    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.


You can also implement the read function yourself by implementing this format spec:
Karl Heinz KremerCommented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now