Program 4 Guide

[ Assignment Writeup | Summary | Details | Prerequisites ]
[ PPM Format | PGM Format | Solution ]

Summary and Goal

Students are to read in a two (2) PPM format image files. The first file specifies the colors to be applied to the second file. The students are to apply to colors from the first file to the second file and output it. (Assignment writeup)

Details

  • The program will take two file names as command-line arguments.
    • The first file is the color scheme file.
    • The second is the image to apply the color scheme to.
  • The students need to store the RGB values for the target image and the reference image in an array. (most likely a 1D array to be compatible with fread.)
  • Students will then follow the algorithm for color transfer provided in "Color Transfer Between Images" by Erik Reinhard, et al. For both images the students must do the following:
    1. Convert the RGB values to LMS values. (Each pixel will now have an L, M, and S value instead of an R, G, and B value.) The conversion matrices are in the paper.
    2. Find the log of each L, M, and S value.
    3. Convert the log of L, M, and S to L, A, and B. The conversion matrices are in the paper.
    4. Find the mean for L, A, and B: find the average L value, the average A value, and the average B value.
    5. Find the standard deviation for L, A, and B: find the standard deviation for the L values, the standard deviation for the A values, the standard deviation for the B values.
  • Scale the target image to have the same mean and standard deviation for its LAB values:
    1. Subtract the average L value in the target image from each pixel's L value.
    2. Multiply each L value by the standard deviation of L for the reference image over the standard deviation of L for the target image.
    3. Add the average L value from the reference image to each pixel's L value.
    4. Do the same procedure for A and B.
  • For each pixel in the target image, convert LAB to LMS. The conversion matrices are in the paper.
  • Compute 10 to the power of L, M, and S for each pixel.
  • Convert the log of L, M, and S to R, G, and B. The conversion matrices are in the paper.
  • The recolored image is to be sent to either standard out or a file (instructor's choice).

Prerequisites for completing assignment

In addition to the skills required for assignment 3, students need the following:
  • Competence with arrays and pointers.
  • Competence with malloc and free.
  • An ability to read and write files.
  • Knowledge of how and when to use stderr (for error messages relating to incorrect command-line arguments).
  • Competence with structs.
  • A means to do matrix multiplication (can be handed out or covered in lab).

Solution

  • Sample input (in png format)

  • Sample output (in png format)



[ Assignment Writeup | Summary | Details | Prerequisites ]
[ PPM Format | PGM Format | Solution ]