Computational Photography

Exercise #3: Editing in Gradient Domain

Due Thursday 22.01.09

General:

Implement "copy / paste" in the gradient domain using conjugate gradient minimization.

Method:

Write a matlab script that implements the following:

1.  Allow the user to define 2 images: the source image and the target image.

2.  The user chooses a polygonal area in the source image using mouse clicks. This area will be copied into the target image.

3.  Ask the user to define the position in the target image where the polygon from the source image will be copied. Note that in this case only a single mouse click is sufficient to define the location.

4.  The program will copy the defined polygon from the source image into the target using gradient domain "cut / paste" as taught in class.

5.  The program displays the results.

Comment:

·  The function choose_image_areas.m is given to you, and you can use it in your program. This function applies tasks 1-3 above. You have to implement only task 4-5.

·  The circumscribing rectangle around the target polygon is the only processed area (and not the entire image). The gradients in the target polygon are copied from the source polygon. The pixels in the target rectangle but outside the polygon serve as boundary constraints.

·  Use the conjugate gradient minimization scheme using the matlab function CGS(..). Do not build the matrix A (for Ax=b) but implement it "on the fly" using convolutions (by supplying the function CGS a function implementing Ax).

·  Allow in your program two alternative set of filters (user's choice):

  1. Two derivative filters: and which are the x and y derivatives.
  2. Four derivatives which are composed of two diagonal derivatives and in addition to the above two derivatives.

·  Check your results in each one of the cases.

·  Use the slides given in class for the mathematical derivation, in particular slide #65 which elaborates the algorithm in detail.

·  Bonus 10 points: Implement transparent "copy / paste" as taught in class.

·  Make sure that your program is efficient. Conserve convolution operations when possible.

·  Choose your own images and be creative in generating cool results. Include source and resulting images with your program files. (Additional bonus for originality/creativity).

Useful Matlab functions:

·  rot90(ker,2) – applies 180 rotation of a kernel which is equal to 2 2D flips (along x and then along y). This is needed for the transpose operations.

·  conv2(im,ker,'same') – applies 2D convolution. Use the 'same' option to get the same image size.

·  find () – returns all matrix indices whose values are true.

·  imread(imgetfile) – a useful GUI to choose image files.

Submission:

·  Submit your matlab functions in a single zipped file. The main program should be written in a file named script.m.

·  You can work in pairs.

·  Don't forget to write your names and ID in the submitted files.

·  Submit your exercise by Thursday 22.01.09 to