How does it happen

i read the raw data of a pgm image file and got the following output
P5
# created by ilidss
512 512
255
162
160
161
165
65533
164
162
165
But 65533 is impossible because the max value of a pixel is 255. the following is the rough code:
bufferredreader in = ...... //bufferedreader read data from lena.pgm
for (int i=0; i<4;i++) system.out.println(in.readLine());
//read four-line header
for (int i=0; i<8;i++) system.out.println(in.read());
//read raw data which is binary value according to magic line indicating "P5"
Could anyone tell me what's going on!

thank you indeed!
the PGM image format is composed of tow parts: header and data
header includes three lines at least 3 lines
1.magic line: can be P5 OR P2.P5 means the data is binary representation. P2 indicates the image data is ascii text format.
2.dimension: eg. 8 8 means 8*8 totally 64 pixels
3.max pixel value: every pixel value should be less than it
4.comment starting with #, it is optional and can be everywhere. it cannot more than 70 charactors.
data is the raw image data
an example
P2 # ascii text format rather than binary
8 4 # 32 pixel
15
0 0 0 0 0 0 15 15
15 15 0 0 0 0 0 0
0 0 11 11 0 0 0 0
0 0 0 0 13 13 0 0
thank you very much. in my case, i am reading a P5 image which contains binary data

Similar Messages

Maybe you are looking for