-1

I have to extract a pgm image. All I have is a size of the whole PGM image which is 505 I tried to extract the number of row and number of column from that image. int size = 505;

At the beginning, I think Number of column should be int col = 505/8// size of 1 byte int row = col *8

I don't know if this is correct? Please advise

SunnyTrinh
  • 67
  • 2
  • 10
  • http://netpbm.sourceforge.net/doc/pgm.html – Weather Vane Dec 03 '14 at 19:25
  • The width and the height in the [netpbm file](http://en.wikipedia.org/wiki/Netpbm_format) is whatever unit you want it to be when rendering it, but in the file it's the "pixels" of the image. – Some programmer dude Dec 03 '14 at 19:26
  • Sorry I didn't make my question clear enough. I am trying to extract a pgm image. All I have is its total size. My task is figuring out how to get those two numbers. Thanks – SunnyTrinh Dec 03 '14 at 19:37
  • Just to avoid more confusion and misunderstandings, you have an image *in memory*, and you want to get the dimensions of that? *How* did you load that image into memory? What format is it (RGB? RGBA? Indexed? Number of bits per pixel?)? If you loaded it into memory you should already have the dimensions? – Some programmer dude Dec 04 '14 at 08:08

1 Answers1

1

PGM images can have arbitrary whitespace at-least 1 byte per pixel, plus a header consisting of 3 ascii mumbers and 6 other bytes with optional padding, so given a size of 505 it'd be at-most 495 pixels in any rectangular arrangement, more than that can't be said from size alone, if you can read the first three lines of he image all will be revealed.

The file size is useful - it's gives a buffer size that will be sufficient to store the pixels, but it does not tell you how they are to be arranged.

Jasen
  • 11,837
  • 2
  • 30
  • 48