For some applications in image processing, it is desirable to have a certain texture fill an arbitrary amount of space. Given a photo of the desired texture, we can accomplish this naïvely by tiling the image (or portions of the image) such that they fill the whole space; this, has the major drawback that the seams between edges of the texture sample will be easily visible, and hence not true to the original pattern. However, if we can select portions of the original image to tile according to how well they match surrounding tiles in the algorithm's output, we'll get a lot closer to a seamless image, and if we can tailor the overlap between these intelligently selected tiles such that it cuts through the path of least difference between a given tile and it's neighbors, our output will look even better. If we add the further restraint that each tile of an output texture image must bear some similarity to a similarly positioned tile of a second non-texture input image, we can reproduce the texture with some overlying structure defined by the second input image.
n*n
rectangular patches (or tiles) to be filled by near-seamless texture. For each desired tile:
(n+b)*(n+b)
square which could be taken from the original pattern image, and overlaps by some pre-set amount b
with the (already generated) tiles to the left and above of this tile. (The algorithm can be sped up, though the results degraded, by only selecting from a limited number of randomly chosen segments of the pattern image.)This is similar to the algorithm above, but we incorporate a slightly altered cost weighting for each candidate patch. Instead of just choosing the best overlap with previously chosen tiles, also added into the comparison is the degree of similarity (image distance by SSD) between a candidate tile and a corresponding segment of a second input image. By choosing tiles that match at least somewhat to the colors present in, for example, an image of Abraham Lincoln, we can procure a relatively seamless image of toast (or whatever other texture) that also bears the impression of Lincoln's face.
As suggested in the paper, this process can also be applied in iteration, with smaller and smaller patch sizes. During this process, in addition to the error of correspondence between a candidate patch and the source image, the error of previously calculated pattern sections (upon which this next iteration will overlay) must also be incorporated; given a weighting α
, the formula
error = α * (overlap_error + previous_error) + (1 - α) * correspondence_error
Following are the results of my program as applied to the test images, as well as some additional images of my choosing.