Working on some basic image processing and I need to manipulate a P2 .prg image. If there are no comments then in line two there should be a width and height value. If we take the FEEP example from this website https://people.sc.fsu.edu/~jburkardt/data/pgma/pgma.html then we can see the value given is 24 and the array later in the file is 24 wide. Perfect! However whenever I go to read in any other file from the same website, the width measurement is say 512, but the text data inside the file is only 17 digits wide? Am I looking at this file wrong? How can I parse out this file into a multidimensional array if the width of the lines don't match the width from the header?
Asked
Active
Viewed 35 times
0
-
1_"...separated by whitespace..."_ end-of-line is white space and has no special meaning. For the 1st file in the examples apollonian_gasket.ascii.pgm the 1st 600 numbers sequentially are the 1st row, etc – Richard Critten May 17 '22 at 20:23
-
The ASCII formats (P1, P2 & P3) normally store around 72..76 characters per line, but that's not a hard requirement. You should deal with however many you find. – Mark Setchell May 17 '22 at 20:36
1 Answers
1
In the .pgm formats, one line of text does not correspond to one line of the image.
The first width
numbers are the first row of the image. Then the next width
numbers are the second row of the image and so on. How many numbers are on one line of text is inconsequential.
That means when reading the file, you should ignore newlines and treat them like any other whitespace.

anton-tchekov
- 1,028
- 8
- 20
-
Thanks for this! I guess my confusion was the FEEP example i see all over is 24 7 and the matrix is also 24 7. Assumed one row of digits was one row of pixels. Thanks again! – Wumbo May 18 '22 at 11:39