Solved

Image processing

Posted on 2004-04-10
6
219 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
Comment Utility
I am not familiar with the pgmor format. Do you mean PGM format?
0
 

Author Comment

by:learncpp
Comment Utility
Yes I meant PGM format.
0
 
LVL 44

Accepted Solution

by:
Karl Heinz Kremer earned 100 total points
Comment Utility
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
Comment Utility
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

10 Experts available now in Live!

Get 1:1 Help Now