Project 4: Image Quilting for Texture Synthesis and Transfer
Synthesizing images by stitching together small patches.
Due Date: 11:59pm on Wednesday, October 24th, 2012
- This handout: /course/cs129/asgn/proj4/handout/
- Stencil code: /course/cs129/asgn/proj4/stencil/
- Data: /course/cs129/asgn/proj4/data/
- Handin: cs129_handin proj4
- Required files: README, code/, html/, html/index.html
MATLAB stencil code is available in /course/cs129/asgn/proj4/stencil/. You're free to do this project in whatever language you want, but the TAs are only offering support in MATLAB.
In this project you will implement Image Quilting for Texture Synthesis and Transfer, a SIGGRAPH 2001 paper by Alexei A. Efros and William T. Freeman. The paper presents a simple image-based method to do texture synthesis and texture transfer. Texture synthesis is the process of creating an image of arbitrary size from a small sample (grass sample above). Texture Transfer means re-redering an image in the style of another one (Abraham Lincoln above).
You are required to implement the texture synthesis and texture transfer method explained in the paper. You should run both algorithms on at least 3 of your own images in addition to the test cases we provide.
The general idea of the presented texture synthesis method is to sample patches from the input texture and compose them in an overlapping way. The simplest solution would be to just randomly select a patch from the input texture each time. And actually this is what the stencil code does. With this solution the overlapping regions are not likely to match and this will result in noticeable edges in the result. A better approach, which you will need to implement, is to find a patch in the input texture that has some agreement with the pixels in the overlapping region (e.g. small SSD error). This will already produce pretty good results but still has some unwanted edge artifacts. To get rid of those, your final implementation will try to find a minimum error cut for the overlapping region.
Figure 2 of the paper illustrates those 3 different methods:
The stencil code produces images as shown in (a). Your job will be to fill out the parts of get_patch_to_insert_synthesis.m that will produce results like in (b) and (c) in the above figure. You can run proj4_synthesis.m.
We can augment the texture synthesis approach above to get a texture transfer algorithm. That is
re-rendering an image with the texture samples of a different image. Each sample patch that we add to our synthesized image
must now respect two different constraints: (a) it should have some agreement with the already
synthesized parts (this is the constraint we used in texture synthesis), and (b) it should have some correspondance
with the image we want re-render. We will use a parameter α to determine the tradeoff between these to constraints.
To come up with a term for part (b) we need some measurement of how much a patch agrees with the underlying image.
We can do this by calculating the SSD of a patch and the image on some corresponding quantity. One such quantity could
be image intensity or the blurred image intensity.
The paper suggest to run multiple iterations of this while decreasing the tile size and adjusting α each time to get the best results. The stencil does that for you. If we run multiple iterations we will need to incorporate the agreement of a patch with the already synthesized image and not just with the overlap region. So the error term will end up being something like this
error = (α) * (overlap_error + previous_synthezised_error) + (1 - α) * correspondence_error
Note that previous_synthezised_error will be 0 for the first iteration. Your code for this will go into get_matching_patch_transfer.m. You can run proj4_transfer.m.
- Read the paper if you get stuck. It is pretty easy to understand and reveals a lot of the details.
Just taking the "best" patch according to SSD could result in repeating patterns in the result. To get a
more stochastic result you can sample a patch within some tolerance of the minimum error (make sure you special case if
minimum_error = 0, especially if you do exhaustive search):
[y, x] = find(errors_of_all_patches <= minimum_error * (tolerance))
Another approach would be to sort all the patches according to their error and then randomly sample from the best N patches.
- There are different ways you can sample the input texture for a patch. You can do an exhaustive search over every possible patch or you could search over a fixed number of randomly drawn samples.
- Minimum error cut sounds a lot like the last project you say? Well yeah, it is. You should be able to reuse your code to calculate a cut path in the overlapping region of a new block. Note that you will have to calculate two cuts for most patches (for the left and the above overlap region).
For this project, and all other projects, you must do a project report in HTML. In the report you will describe your algorithm and any decisions you made to write your algorithm a particular way. Then you will show and discuss the results of your algorithm. Also discuss any extra credit you did. Feel free to add any other information you feel is relevant.
Include the given images and at least three images from an outside source for both algorithms.
The baseline will work reasonably well for many images, but for certain types of images there are very noticable failures. In particular humans are very sensitive to distortions in faces and distortions in straight lines. Images with large areas of high-frequency texture also tend to behave oddly with simple energy functions.
Here are some ideas, but we will give credit for other clever ideas:
- If you want to speed things up, you can calculate the SSD between a region and the entire input image (texture) efficiently by using filtering operations.
- There are other strategies to find a good cut in the overlapping regions. E.g., Graphcut. Take a look at Project 3 of CS129's last offering for some explanation.
- For some textures it can make sense to take samples at different scales and orientations. Also, varying the tile size can potentially help to get better results.
- The tile size and the overlap size can have a big influence on the result. Run experiments with varying values for those parameters an report your results.
- Experiment with different correspondance quantities for texture transfer and report your findings.
- Use Poisson blending to make things more seamless.
- Implement a patch-based "image analogies"
For all extra credit, be sure to demonstrate on your web page cases where your extra credit has improved image quality.
To get graduate credit on this project you must do one form of extra credit of sufficient difficulty. Any of the suggested extra credit satisfies this requirement.
This is very important as you will lose points if you do not follow instructions. Every time after the first that you do not follow instructions, you will lose 5 points. The folder you hand in must contain the following at the root:
- README - text file containing anything about the project that you want to tell the TAs
- code/ - directory containing all your code for this assignment
- html/ - directory containing all your html report for this assignment (including images). Your web page should only display compressed images of moderate size (e.g. jpg or png or gif if you want to animate something, no more than 1000px on a side).
- html/index.html - home page for your results
Then run: cs129_handin proj4
If it is not in your path, you can run it directly: /course/cs129/bin/cs129_handin proj4
- +30 pts: Texture Synthesis: Best SSD match
- +30 pts: Texture Synthesis: Best SSD match + Minimum error path
- +20 pts: Texture Transfer
- +10 pts: Used your own images
- +10 pts: Write up
- +10 pts: Extra credit (up to ten points)
- -5*n pts: Lose 5 points for every time (after the first) you do not follow the instructions for the hand in format
Project derived from Image Quilting for Texture Synthesis and Transfer. Description and setup inspired by CS498 at University of Illinois at Urbana-Champaign. Some code taken from other projects of Brown CS129 or Brown CS143.