Due Date: 11 May 2011
Here is a simple example of how to write a command line tool: gamma-correct#!/usr/bin/python
import sys,os,optparse import scipy.misc from pylab import *
parser = optparse.OptionParser(usage=""" %prog [options] input.png output.png
Perform gamma corection
""") parser.add_option("-g","--gamma",help="gamma value",type=float,default=1.6)
(options,args) = parser.parse_args()
image = imread(args[0]) image = image**options.gamma scipy.misc.imsave(args[1],image)
If you put this into a file and make it executable, you can then say: ./gamma-correct -g 0.3 input.png output.png
Color Space Conversion Functions (20 points)
Write a command line program that takes as input a PNG file and converts the file to XYZ, L*a*b, and HSV formats and back.
csconvert -t rgb2xyz input.png output.png
where the argument to -t is one of rgb2xyz, rgb2lab, rgb2hsv, hsv2rgb, lab2rgb, or xyz2rgb
Quantization vs Digitization (20 points)
Write a command line program that takes
an input
image, a target image size and a target number of quantization levels
and rescales the image to that given target size and quantizes it to
the given number of levels. For rescaling, use the 'resize' function in
the 'Image' object - Python Imaging Library (PIL); you need to figure
out the correct
parameters to give it in order to obtain reasonable rescaling
results. qdimage -t 500x300 -q 16 input.png output.png
Compression Ratio (20 points)
Write
a Python script that, given a set of image files and an image
compression format (and quality, in the case of JPEG), loads each image
in turn, compresses it into the given format, and computes the total
compression ratio, both from the raw 8 bit per channel image size and
the image size of the original input images (which may already be
compressed in some format). To solve this problem, you probably need to
use the Python Imaging Library (PIL) rather than the imread/imsave
functions.
|