if i have a .pgm file which has width and height of 1024x1024
now how do i write a program to read only the alternate pixels and reduce the resolution by 2 that is make it 512x512?
It would be just as easy to write your own pgm reader. The only "tricky" thing would be to watch out for comments. (Read everything as a string, then if it begins with a '#', just toss the string and f.ignore(1000,'\n');, otherwise convert to an integer for all values except the first.) http://netpbm.sourceforge.net/doc/pgm.html
After that, it is very easy to reduce your array/matrix by half, and write out a new pgm file.