how to reduce resolution of a .pgm file?

Hi

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?

any help/explanation would be great

thanks
-mithila
There are a million ways to do this. One very fast approach would be to use OpenGL: http://old.nabble.com/Using-OpenGL-for-image-transformations-td19524502.html
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.

Hope this helps.
Topic archived. No new replies allowed.