CS 426 Assignment 2
An Image Enhancer
Due 11:59 PM, Friday, October 18, 1996
Some results of the 1995 Graphics Class.
Introduction
This assignment will allow you to explore a variety of image
enhancement, image processing and ``artistic'' ideas. The program
will allow you to select a transformation type and then let you
explore transformations along the selected axis. There will be two
types of transforms,
continuous (e.g., gamma), and
enumerated (e.g., dithering types). You will have to fill in some
code to define each of these filters.
For example, gamma will give you nine selections of various
gamma settings to choose from. The
original image will be
shown at the top of the screen. When you select an
image, it will move to the center and nine new choices will be presented.
The choices to the left and right of the current choice will be only
slightly different from the current one with the top and bottom rows
moving more quickly away from the original one. Thus repeated choices
should allow you to fully explore the space of possible transforms.
This can continue until a new transformation type is selected.
Setting up
Create a directory to hold this assignment's files. Then copy all
files from /u/cs426/Examples/TkEnhance
to that directory.
You can already see a fully working version of the program
by running
tkenhance rex.ppm
from your directory.
When you start programming, change the first line of the
tkenhance script to make it point
to your "imgwish".
How it works
Each filter is implemented as a separate Unix program.
Most of the .c files
contain empty filter routines which you will fill in,
except imgNoise.c
, which
contains a complete working filter, as an example.
Your job will
be to fill in the various image processing functions, throughout
the .c files. Whenever you see the string WORK HERE, you
will have some work to do.
When you type make, you'll be building a program called
imgwish, which contains all the usual Tcl/Tk stuff plus
extensions for your image filters. tkenhance is a wish
script for imgwish.
Each time a new transformation type is selected an entry will
be made in a list of transformations. An image script of the chosen
transforms and parameters can be written, which can actually be used
later to apply your group of filters to a number of images from the
command line.
You should try to make the code as
efficient as you can. Think about operations that are used repeatedly,
etc. For example, consider bitwise operations for the quantization, etc.
You will also have to submit 5 image scripts (.imgsh). These
will be used to see how your filters can work together to produce your
final artwork.
What to implement
The transformations must include the following list plus at
least two creative ones of your own making. Note that the noise
function is already done for you as an example.
- Add Noise (Continuous): Add noise to image.
File: imgNoise.c
- Quantize (Enumerated):
This one should produce a quantized image from 1 bit
per channel to 8 bits.
File: imgQuantize.c
- Dither (Enumerated):
- 1 bit, B&W, 0.5 threshold.
- 1 bit, B&W, random dither.
- 1 bit, B&W, Bayer's 4x4 pattern dither.
- 1 bit, B&W, Floyd-Steinberg error diffusion.
- 3 bit, RGB, 0.5 threshold.
- 3 bit, RGB, random dither.
- 3 bit, RGB, Bayer's 4x4 pattern dither.
- 3 bit, RGB, Floyd-Steinberg error diffusion.
File: imgDither.c
- Gamma (Continuous):
Adjust Gamma from 0 to less than 1 for darkening, 1 does nothing,
and greater than 1 to 4 for brightening.
out = in ^ 1/gamma
File: imgGamma.c
The remaining filters are based on the web page
Image Processing
By Interpolation and Extrapolation.
There's some code for this in
imgNoise.c
which you may want to borrow for the these
filters.
- Brightness (Continuous):
Adjust brightness from 0 (black) to 1 (original image). Values
greater than one brighten the image.
File: imgBrightness.c
- Contrast (Continuous):
In the Img_ContrastFrom()
function, you should compute
the average luminance of your input picture.
Then, interpolate/extrapolate from that to your original image.
When the value is zero, you should get a constant grey.
When it's one, you get the original image.
Compare your Gamma, Brightness, and Contrast
filters. Can you see the difference? What does it mean in
each case when the filter's value is less than zero or greater
than one? Note: Write the answer to these questions in
your README file.
File: imgContrast.c
- Saturation and Sharpening (Continuous):
Extend what you've done in the previous example to do saturation and
sharpening of images. The saturation filter needs to pre-compute
a luminance image from the original picture and interpolate between
that and the original image. The sharpen filter needs to pre-compute
a blurry image from the original picture. You may want to experiment
with different convolution kernels for different ways of blurring
the original image.
Files: imgSaturation.c
and
imgSharpen.c
- Fun 1 through Fun 4:
You're required to implement two fun filters which can
do anything you want. You should probably experiment with making
the resulting pixel a function of more than just the original pixel
at the same coordinate. Try different warping functions. Also,
as you implement your filters, you'll occasionally get some
spectacularly wrong results. You may wish to save those and submit
them as ``fun'' filters. If it looks visually interesting, it can't
be all bad.
Files: imgFun1.c
through imgFun4.c
File formats
Tkenhance can only read the ppm format. You can convert an
rgb image to ppm like so:
toppm me.rgb me.ppm
You can convert a ppm to a gif file like so:
ppmquant 256 me.ppm | ppmtogif -interlace > me.gif
You can convert a ppm to a jpeg image like so:
cjpeg me.ppm > me.jpg
If your system doesn't have cjpeg, you can also view your picture with
xv and save as a jpeg.
What to submit
Initially, you should probably use your 160x120 images, so the image
processing algorithms go faster. When you find a filter combination
that you really like, you should generate an image script for
the filter and run that image script on your larger image.
When you're all done, you
should have five image scripts and some number of favourite warped,
distorted, and disfigured images.
Choose two (or more) you like best, put them on a web page,
and mention the URL for them in a README
file which you submit with your assignment. We'll put our favourites
on the class Web page.
Please submit:
- All .c and .h files
- makefile
- tkenhance
- a README file with the answers to the
questions asked above,
a description of your fun filters, and URLs pointing to
some of your favourite pictures
- five .imgsh scripts generated by File -> Write Script...
Please don't submit binaries, images, or core files.
More
documentation on TkEnhance.
CS 426 (Computer Graphics), CS Department, Princeton University
Last modified: Mon Oct 7 15:48:53 1996