main-practice2

1.@ Programming Practice Assignment

The main objective of this assignment is to make sure that you can read and write images using the TargaImage library. What your program does with these images doesn’t need to be that interesting.

Due Wednesday 11/3. (but really not due until Sunday, 10/7)

2.@ What your program must do

Your program must take a set of command line arguments (explained below), read in a TGA image, do something to it (desaturate it and add a green box), and write it back out.

You should use the libtarga library created for this class. We strongly recommend using the TargaImage wrapper for LibTarga. As far as we’re concerned in this class, the definition of a targa file is “the files that can be read and written using libtarga.” We won’t test your program with targa files that libtarga cannot handle.

Your program should take the following arguments (to make sure that you can handle command line arguments):

    main INFILE OUTFILE SAT X Y

Where

  • INFILE is the input file name (e.g. picture.tga)
  • OUTFILE is the output file name (e.g. output.tga)
  • SAT is a floating point number specifying the amount of desaturation (so 0 is no desaturation, 1 is fully desaturated)
  • X Y are integers specifying where the center of a green box should go.

Your program will read in the image, desaturate it some amount, draw a green box, and write it back out.

Desaturation means removing color - so if SAT=1, the image will be grayscale (R=G=B). If you really can’t figure it out, there’s a note on saturation below.

We don’t really care how big the green box is - but make is big enough that we can see.

Your program should be robust against bad inputs.

Here is an example of running the program on this input image, with the parameters

    practice1 input.tga outfile.tga .75 120 100
input.tgaoutfile.tga

3.@ Getting LibTarga

You can download the header and c file for libtarga from http://www.cs.wisc.edu/graphics/Gallery/LibTarga/

You can download a C++ wrapped for libtarga (recommended to make things easier to use) from http://www.cs.wisc.edu/graphics/Courses/559-f2008/Main/LibTargaWrapperDocumentation

Note: these pages are from old versions of the course web. Beware.

You should simply place the 4 files (TargaImage.cpp, TargaImage.h, libtarga.c libtarga.h) in your project.

Libtarga was written back in the old days, before visual studio complained about using the standard C library. If you compile it, you will get warnings like:

1>c:\users\gleicher\559\practice1\libtarga.c(272) : warning C4996: 'fopen': This function or variable may be unsafe. Consider using fopen_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details.
1>        c:\program files\microsoft visual studio 9.0\vc\include\stdio.h(237) : see declaration of 'fopen'

Good programming practice is to make your programs compile with no errors and no warnings, so you should probably get rid of these warnings. The easiest way to do that is to put the macro _CRT_SECURE_NO_WARNINGS into the project settings (under “Configuration Properties” “C/C++” “Preprocessor” - add _CRT_SECURE_NO_WARNINGS to the end of the list.

4.@ A few hints

If you need a way to convert between some image format you have (jpg, png) and tga, you can use IrfanView - a free program that is installed on the CSL computers, or one of many other programs.

In the future, you might want to create test images with specific content, so learning about Photoshop, GIMP, or some other image editing program might be a good idea.

For testing your program, you will need to set the command line options within visual studio (e.g. what command line options are passed to the program when you hit “run” or “run with debugger”). Being able to run your program from the command line is nice, but sometimes you’ll want the debugger.

If you’re really stuck, you can download a sample solution (here). But make sure you figure things out yourself.

4.1@ A note on De-Saturation

To make an image grayscale, set the color channels to be equal.

    R = G = B = L

Of course, there’s a choice in how to compute L. For the purpose of this assignment, the simplest thing is OK:

    L = (R+G+B)/3

Because our eyes are more sensitive to green, an equally bright green, blue, and red will not appear equally bright. This means that if you are converting between color and grayscale, the color red (255,0,0) should not turn into the same brightness as the color green (0,255,0).

The exact ratios vary. One simple one is to say that green is twice as sensitive as red is twice as sensitive as blue, which gives the rations for R,G,B as 2/7, 4/7, 1/7, or .28, .57, .14. I have also seen systems that use r = 0.212671, g = 0.715160, b = 0.072169.

The closest thing to an “official” standard is what is used in NTSC (the North American video standard) to compute brightness from colors. That’s: Y = 0.30R + 0.59G + 0.11B.

Once you have L, you compute can compute desaturation by interpolating between the original color (SAT=0) and the gray value (SAT=1).

4.2@ Specific for this Assignment

While writing a readme.txt file and giving sample I/O files may seem like overkill for the practice assignment, its meant to make sure everyone can do the mechanics.

You should include an input/output pair of what your program 1 does. Call these input.tga and output.tga. Input.tga should be no bigger than 200 pixels on a side (TGA files are not compressed, so they get to be quite big).

4.3@ Handin Instructions

For this programming assignment, you must turn in the following:

  1. A “readme.txt” file explaining what you are turning in, what features your program has, any thing we should know about how to build it, any attributions for code that you have taken from somewhere, etc.
  2. All of the files required to build the program. This includes a Visual Studio “.sln” and “.vcproj” file, and all source and header files. Any code that you are using (like the targa library files) needs to be included, but the libraries (FlTk and OpenGL - for future assignments) do not.
  3. Any required sample input/output pairs.

Important: do not turn in any “binaries” - executables, object files, debugger files, etc. These get pretty big.

To test to make sure things work out OK, you should copy the directory onto the local disk, double click on the solution file, and hit F7 (which is “compile” in visual studio).

For the programming practice, I would expect a directory to have the following files: a readme.txt file, a .sln file, a .vcproj file, your program file (probably just one for the practice assignment), the libtarga files (two source files and two header files), and two targa files (the input/output pair).

Please put all these files into the “Practice2” subdirectory in your handin directory.

4.4@ When is it due?

Technically, this is due on November 3rd. But, since the assignment is going out late, we will not penalize assignments that are handed in within one week of the assignment being made.

Projects turned in before Monday, November 8th, will not be penalized. (That is, the assignment is due on Sunday, November 7th).

5.@ How will this be graded

We will give you a simple check/no check for completing this assignment. We will probably only look to see if things seem reasonable - we may not test your program extensively. However, the point of this assignment is to make sure you’re ready for the programming project.

6.@ A note about TGA

Since I am sure you’re wondering…
We use TGA files because its a file format for which we have a simple-to-deploy library that can be used in class.

TGA isn’t the greatest file format. It is not compressed, so the files tend to be big. And you don’t usually encounter TGA files, so you almost always need to convert things.

The reason we chose TGA was back when we did it, we needed to create our own library for some uncompressed (or losslessly compressed) file format. That was the only way to get something simple enough to deploy in class. TGA was chosen since it was easy to implement a library for it, and it handled alpha channels in a consistent way (this was important in prior years).

While I’d prefer to switch to a different format, I am still not sure there’s an easy to deploy and use library for any of the candidates.

Page last modified on October 31, 2010, at 01:24 PM