SI 486L Lab 3: Color My World

advertisement
SI 486L
Lab 3: Color My World
This lab is due in just under one week – by 11:59 pm on the day before the next lab day. All the files
should be zipped or tar'd into a single file and e-mailed (subject should contain the phrase “lab 3”) as
an attachment to the instructor. One of the files should be a makefile with a default target that builds an
executable called “colorIt”. A README file is always a welcome addition, especially to explain the
contents of the collection of files and to explain any procedures for their use.
Introduction
An important part of HPC is the visualization of results. With HPC there is often a huge amount of
data produced. One of the easiest ways to comprehend large quantities of data is with pictures. (“One
picture is worth a thousand words” seems to be really rather an understatement.) A large collection of
numbers may be the most accurate result from some HPC calculations, but it can be hard to understand
what those numbers are telling you without seeing a picture. Often those pictures don't have an actual
physical visibility; rather we color the display based on the numeric values in a pseudo-coloring. You
likely have seen such pseudo-colorings in radar and satellite weather data. The NOAA website
(http://www.goes.noaa.gov/ECIR4.html) tells us:
Meteorologists use color enhanced imagery as an aid in satellite interpretation. The colors enable them to
easily and quickly see features which are of special interest. Usually they look for high clouds or areas
with a large amount of water vapor.
In an infrared (IR) image cold clouds are high clouds, so the colors typically highlight the colder regions.
The bar on the right side of the image indicates the pixel brightness values for the corresponding color.
The intensity value represents emitted infrared radiation. The intensity of a pixel is recorded as a digital
number (for example, in these images the numbers range from 0 to 255.)
Tasks
Your objective is to write a pseudo-coloring program. Your input will be two .csv files (csv = Comma
Separated Values) specified on the command line and your output should be an image displayed to the
screen. The first input file will be the color map. It will map a data point value to an RGB triplet. The
second file will be the datafile to be colored and converted to an image. An example invocation might
look like this:
python ./colorIt.py redMap.csv HotWater.csv
Design
Here's a simple design (in pseudo code) for the main() function:
main
load the colormap
open/create an image
open the input file
for each line of the input file
for each value, convert it to an RGB triplet
assign the corresponding pixel that RGB value
display the image
One way to implement this is with the python “Image” package.
Here's an example of a simple pixel assignment:
# based on:
# http://en.wikibooks.org/wiki/Python_Imaging_Library/Editing_Pixels
import Image
img = Image.new( 'RGB', (300,300), "black") # create a 300x300 image
pixels = img.load()
# create the pixel map
for i in range(img.size[0]):
# for every pixel:
for j in range(img.size[1]):
pixels[i,j] = (i, j, 100) # set a made-up color (R, G, B)
img.show()
# to display the image
img.save('myimg.bmp') # to save the image in a file
You should try this out to see that it works.
Now you should write your own version that will color any given input data. You might use a similar
approach, but the color value won't be based on the row and column indices of the image, but on a
colormap provided as the first argument.
You'll have to hunt down or invent a good colormap or two. One map should be for the range of input
values from 0.0 to 1.0 that produces colors linearly from “cool” at 0.0 to “hot” at 1.0, so possibly a blue
to red range of colors. Any image data (2nd file) could be scaled to this range (0-1) and values
assigned accordingly. You may need to add an argument to describe the max value, for scaling.
Another map should be a non-linear gradation, from 0 to 100, one that is more weighted or detailed at
the “cool” end, with distinct colors for many values below 1 and between 1 and 10, then between 10
and 100. (Hint: does this sound logarithmic?) It may be easier to make this integer mapper different
from the floating point (previous) mapper.
Once you have your colorizer(s) working, try it out on this dataset:
http://zee.cs.usna.edu/~albing/mystery1.data
which you can download with wget or curl. For example:
$ wget 'http://zee.cs.usna.edu/~albing/mystery1.data'
Why
Why are we doing this? First, as an exercise in visualization, to demonstrate the concept of pseudocoloring, and to understand how artificial, though important, the coloring is. This is also a support tool
that will be useful for future labs when we generate data that we will want to visualize.
Clean Code Counts
These projects will be graded on two criteria: 1) does it work? and 2) is it well written? That means
clean, readable code, well structured and well commented/documented.
Download