Raster Graphics
I can't improve on what is stated in the Wikipedia: Raster Graphics. You should also understand the distinction between raster graphics and vector graphics, for the latter we again refer to the Wikipedia: Vector Graphics.
Here we will write programs to output raster images in the simple PPM format. The PPM is one format in a group of three formats: PBM for black/white, PGM for gray and PPM for color. These formats are collectively known as either PNM or NetPPM. A fine introduction for making and using PPM is contained within that article.
Eric Weeks' site is a popular site to learn about PPM.
Making PPM files with Python
Here we will use the Python programming language to write the RGB triplets to a file.
Try this:
python makeppm.py
Alternatively, make makeppm.py executable with chmod u+x makeppm.py. Then run the program by typing the program name, e. g.:
makeppm.py
If that does not work, perhaps your current directory is not "in your path" (more on that later). Try:
./makeppm.py
If the last line in makeppm.py did not show you your colors.ppm, try it from the command line:
display colors.ppm
On Linux eog can be substituted for display. On Windows, you can use imdisplay, or (of course) a menu in an image viewer such as XnView.
You should see something like:
Use head colors.ppm or tail colors.ppm to see some of the text that makeppm.py made. Have a look inside makeppm.py using a text editor and try to understand the syntax. Feel free to play with it; blend red and blue, for example. One thing you should realize about the python language is that the indentations define the scope of loops and nests, and the indentations must be consistent. I use one tab character, others prefer four spaces.
Compressing raster graphics
Use ls -l colors.ppm to see the size. When written in ascii, the file is quite large. You may want to try editting makeppm.py to use the "P6" binary format (see the comments in the code). Now look at the file size. Then
convert colors.ppm colors.png convert colors.ppm colors.jpg
Use display colors.png of display colors.jpg to view what you made. Either one should look almost exactly like colors.ppm. Use ls -l colors.* to see the size of the files:
-rw-r--r-- 1 yourname tux 2705 Dec 31 15:14 colors.jpg -rw-r--r-- 1 yourname tux 907 Dec 31 15:14 colors.png -rw-r--r-- 1 yourname tux 599055 Dec 31 11:34 colors.ppm
.png is the winner, which surprises me, because usually for smoothly varying colors the .jpg will be smaller. Not only that, but .jpg is a lossy compression as this exercise demonstrates:
convert colors.ppm c.ppm convert c.ppm colors.jpg convert colors.jpg d.ppm diff c.ppm d.ppm
Try the above exercise with .png, instead of .jpg, and you should see the .png is a reversible compression, the diff command returns nothing.
But if you download typical.jpg:
Then
convert typical.jpg typical.png
The displayed typical.png is identical:
But you will find the .png is 74 kilobytes and the .jpg is 9 kilobytes.
convert a very useful command-line utility.
Here is a short tutorial for convert.
Here is the official online documentation for convert, listing all of the command line options.
Your Task in raster graphics is: Raster Graphics for Radar Data