how to extract the number of column and the number of row from size of an image

139 Views Asked by At

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

1

There are 1 best solutions below

0
Jasen On

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.