CMSC 23710/33710 Project 2 Help

"Aspect Ratio"

Two of the images (elev-myst.pnt, ct-feet.png) for the assignment have pixels with something other than 1:1 aspect ratio. That is: when correctly drawn in physical space, the pixels are not square, or, the horizontal spacing between samples is different than vertical spacing. In the case of ct-feet.png, the spacing between samples on the horizontal (fast) axis is 0.722 times the spacing between samples on the vertical (slow) axis. In the case of elev-myst.pnt, you will have to figure out what the correct aspect ratio is, by looking at a world map once you see what the country depicted is.

If we had convenient ways of displaying images with non-square pixels, this would not be a problem. But this is not part of how PNG images are normally displayed: web browsers will assume 1:1 aspect ratio, which causes the images to look distorted.

To counter-act this, you can create a new image, which resamples the information represented by the old image, on a grid that does have 1:1 aspect ratio. The new image can be readily displayed with a web browser or whatever else you're using to look at images. "Fast and Slow axes in PNG" One thing that should have been included in the Project 2 assignment was a statement of which axes in PNG images are fast and slow. Here is a small 16-bit grayscale image (just like the image datasets) that may be useful for experimenting with:

There are 30 samples on the fast axis, and 20 samples on the slow axis. Some people might say this is a "30 by 20 image", or, a "20 by 30 matrix". The values in the images are 1000, 2000, 3000, 4000, 5000, and 6000, in 10x10 pixel blocks. In a normal display of the image (see Web browsers as image viewers), [slow/fast typo fixed Oct 14] the slow fast axis is drawn from left to right horizontally, and the fast slow axis is drawn from top to bottom vertically:

Web browsers as image viewers

The project description refers to how the PNG images are displayed in a web browser. This does not mean that you have to do anything with HTML or XML in order to create or display the images! You're welcome to prepare your write-up as a web page, but the way you look at the images your program creates does not need to involved any HTML or XML.

Web browsers can be trusted to display PNG images in a consistent way (see Fast vs Slow above), so they make a sensible reference for the "correct" way they are displayed. They are also a ubiquitous and convenient way of viewing images. Most other image-viewing programs, and things like Gimp and Photoshop, will also display the images in this orientation, though they may be less convenient to view an image that is being repeatedly updated as you debug your program (in the browser, you can just hit refresh).

If you are using something like Matlab or Pylab to complete the assingment, you may find that the easiest way of displaying images within those programs doesn't match the way that web browsers do. This is a wrinkle that will be up to you to work around. The images as they appear in your write-up must be in the correct orientation.

Example Python/Numpy/PIL code

You may find it convenient to use Python for this assignment, because of its associated Numpy and PIL libraries. Here are some simple programs that may help with your getting index-able arrays from and into PNG images.

These may require an upgraded version of PIL; the examples here work with version 1.1.6. You can learn the version by doing this in python:

>>> import Image
>>> Image.VERSION
'1.1.6'
where "1.1.6" is the output of the second statement.

Linear Interpolation of RGB control points

The assignment asks you to create and apply colormaps that are saved as text files, and to map values through RGB colors by linear interpolation between control points. Here's an illustration of linearly interplating an output value from y0 to y1 as in input value changes from x0 to x1:
For example, taking the example colormap from the assignment,
0      0   0   0
32767  255 0   0
43690  255 255 0
65535  255 255 255
interpolating between the second and third control point would involve x0=32767 to x1=43690, and (for the green channel) y0=0 to y1=255. The red and blue channels would be interpolated similarly.