main-p1commands

In all cases, it is important that your program is robust in the face of bad inputs. It should never crash.

Some operations are required of all programs. Other operations are optional, but doing more optional parts is what gets you a better grade.

The point values will be given later.

It is important to describe all optional things that you’ve done in your documentation!

Basic Operations

These provide the basic mechanics for working with images. All are required.

read V filename

(Required) Read filename into variable V. Filename must end in .tga.Warning: spaces in filenames don’t work (since we break words at spaces)!

write V filename

(Required) Write filename from variable V. Filename must in in .tga.Warning: spaces in filenames don’t work (since we break words at spaces)!

blank V w h

(Required) Create a blank image of size w (width) by h (height) pixels (w and h are integers). The image should be black with alpha value of 255 (100%). The new image is stored in variable V.

fill V x1 y1 x2 y2 r g b a

(Required) x1,y1,x2,y2,r,g,b,a are all integers.Fills a rectangular region of the image in variable V with the color (r,g,b,a).

(x1,y1) (x2,y2) specifies a rectangular image INCLUSIVE of the values. so the command:

@@fill 10 10 20 20 0 0 0 255

does change the pixel (20,20).

copy V U

(Required) Make a copy of the image in variable V and place it into variable U.

crop V x1 y1 x2 y2

(Required) Crop image V (cut out a rectangle) to the rectangle given by (x1,y1) (x2,y2) INCLUSIVE.

Single Image Adjustments

These are simple commands that adjust the values of a pixel in the image. They should be easy to implement. All are required.

dissolve V a

(Required) Multiply the alpha value of each pixel by a (where a is a floating point number). If you are storing images in premultiplied form, you may need to be careful!

opaque V

(Required) Set the alpha of the image to be 255 (100%) everywhere. If your images are premultiplied, you need to “un-premultiply” them. You can assume that transparent parts of the image are black.

darken V a

(Required) Multiply the colors of V by floating point number a.

desaturate V a

(Required) Desaturate the colors of image V by the amount floating point number a between 0 and 1. Desaturating by 1 (100%) means totally removing the color (it should give a grayscale image). Desaturating by 0 doesn’t change the image. .5 (50%) is halfway inbetween. In desaturation, the luminance (or brightness) of each pixel should remain (approximately) the same.

You should use some reasonable approximation for determining the luminance from RGB (not just equal weighting).

Image filtering functions

blur V k

(required) Blur image V using a B-Spline kernel of size k, e.g. if k=3, the kernel is (1/16 [1 2 1; 2 4 2; 1 2 1]). It is only required for your program to support k = 3 and 5. Supporting other values for k is optional.

sharpen V (params)

(optional) Shapen image V using some sharpening method that you learned about on the web (we’re not really going to teach you about it in class). Since we don’t know what method you’ll implement, we don’t know what parameters your command will tke. Be sure to explain what you did in your documentation.

One well-known sharpening method is unsharp mask.

Image resampling functions

A basic resize operation is required. The other operations are optional, as is fancier versions of resize.

resize V sa sb

(Required) Resizes image V by scale factor sa/sb (where sa and sb are integers). We express the scaling as a ratio of integers to allow you to exactly specify things like 1/3.

You can vary the difficulty (and get optional points) by implementing better sampling and reconstruction.

The basic version of this would implement point sampling (pixel replication for upscaling, dropping every Nth pixel for down sampling) for integer scale factors.

In your documentation you must describe the sampling and reconstruction methods that you use.

stretch V xa xb ya yb

Do a resize where the image is scaled by xa/xb in the X direction and ya/yb in the Y direction.

This command is optional, and you get more points for implementing better sampling and reconstruction.

rotate V t

Rotate image V by angle t around the center of the image, where t is a floating point number giving a number of degrees to rotate counter-clockwise. Your program should not change the size of the image (so some parts of the image may get chopped off, and other parts of the result may be empty - you should fill them with black).

![](https://graphics.cs.wisc.edu/Courses/559-f2007/pics/pub_projectpics_redchecks.png) ![](https://graphics.cs.wisc.edu/Courses/559-f2007/pics/pub_projectpics_redchecks-rot.png)

The basic version of this command can rotate by 90 degree increments. More advanced versions of the command can rotate by arbitrary amounts. The best implementations will use good sampling to avoid aliasing.

Non-linear warping

(Required) You are required to implement (at least) two different non-linear warping functions. You can pick any warps that you want - swirls, ripples, fisheye effects, etc.

Optional points can be earned by implementing better resampling methods, and for creating more complex types of warps (such as ones where you specify how a grid of points move).

Because every kind of warp may need different parameters, the exact syntax of your command is up to you. You’ll get to show off your warps when you demo your program.

You should make sure that your warps show off your sampling methods. If you do some form of adaptive sampling, you should make sure that your warp compresses the image in some places and stretches it in others.

Your documentation should make clear what the warping functions are and what sampling methods that you have done.

Impressionist Painting

Your program must implement two command that transform an image into an impressionist painting.

A discussion of impressionist painting transformation is here.

paint V

(Required) Turn image V into an impressionist painting, using default parameters. This command probably is just shorthand for the painter command (it would call painter with specific values for the parameters).

painter V (params)

Turn image V into an impressionist painting, allowing parameters to be specified as part of the command. Since we don’t know the method you use, we don’t know what the parameters will be. If your method doesn’t take any parameters, then this command is exactly the same as paint.

Compositing

Your program must implement a compositing command.

composite A over B x y

(required) Where A and B are image variables and x and y are integers, giving a position in image B. This command updates image B by compositing image A “over” it (using the “over” compositing operator) positioned such that the upper left corner of A is at x,y. That is, pixel (0,0) of A is composited over pixel (x,y) of B (and (1,0) is over (x+1,y), etc).

(optional) Implement other compositing operations by allowing different words to be substituted for over. (under, atop, …). See the comment at the top of the 2001 Project for suggestions.

chromakey V r g b

(required) Change the alpha values in an image V such that any pixel with its color equal to (r,g,b) gets its alpha value set to zero.

Note that this is a very simple way to make a mask - you’ll only encounter exactly perfect colors in images that you make by hand. If you want to try to do something fancier…

matte V (params)

(optional) Do something that tries to compute the matte (alpha values) from the given image V. Doing this well is really hard. Its suprising how hard it is!

Other Things

(Optional) While there are a lot of commands here, they are only a small subset of the things that are possible. (Have a look at the menus in Photoshop).

If there’s something you want to try implementing, go ahead! We’ll probably give you some points for doing it, and you’ll learn something. In general, you’ll get more points (for the same amount of effort) doing the things described in the assignment. But if your goal is to do cool stuff and learn…

Fell free to send a note to the instructor about something you want to try. I’ll be able to give you some ideas as to how hard it will be, where to start, and how much it might be worth towards your grade.

But remember: do the required parts first. They are most important for your grade.

Page last modified on September 12, 2007, at 02:35 PM