Solved

Image processing

Posted on 2004-04-10
6
227 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
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…
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…

762 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