Texture Synthesis

Input Textures



1. Random Patch Selection

To make the synthesized tile of input texture, as a naive method, patches are selected randomly and put together to make the result image. It goes without saying that the result in not what we are looking for.





2. Overlapping Blocks

To improve the result, by calculating SSD between overlapping regions of current block and all possible blocks in the source image, we can find the best matching patch that is the one with minimum SSD. However the minimum value is not always the best result so it is better to put a threshold (error tolerance) to have a set of patches that mostly match the overlap and randomly choose one from that set.


Patchsize: 45px
Overlap: 10px
Patchsize: 61px
Overlap: 10px
Patchsize: 45px
Overlap: 10px
Patchsize: 55px
Overlap: 10px
Patchsize: 61px
Overlap: 10px
Patchsize: 55px
Overlap: 10px
Patchsize: 55px
Overlap: 10px
Patchsize: 45px
Overlap: 10px
Patchsize: 55px
Overlap: 10px
Patchsize: 65px
Overlap: 10px

My Textures

Patchsize: 51px
Overlap: 10px
Patchsize: 45px
Overlap: 10px


3. Minimum Cost Cut

To remove the discontinuity, we can find the path with the minimum cost in SSD of overlap region. This can be done by computing the cumulative error from the first row to the last. Minimum value in the last row indicates the minimal path and it can be retrieved by tracing back from bottom to top(for vertical overlaps). Now that the minimal path is known, we should make a mask and warp the two overlapping regions to have a seamless output image.


Patchsize: 45px
Overlap: 10px
Patchsize: 61px
Overlap: 10px
Patchsize: 45px
Overlap: 10px
Patchsize: 55px
Overlap: 10px
Patchsize: 61px
Overlap: 10px
Patchsize: 55px
Overlap: 10px
Patchsize: 55px
Overlap: 10px
Patchsize: 45px
Overlap: 10px
Patchsize: 55px
Overlap: 10px
Patchsize: 65px
Overlap: 10px
Patchsize: 51px
Overlap: 10px
Patchsize: 45px
Overlap: 10px


Texture Transfer

Texture transfer is done with the same process but with one more constraint. Since there is a target image, the intesity of current region of target that is being transfered should also match current patch in the tile. To do so, in addition to SSD result of overlap with all possible patches, there will be another SSD result defining the difference between target and possible patches. To take both into account, we should find the minimum SSD(best match) using their weighted average. The weight I used in my code was 0.2 for overlap SSD and 0.8 for target SSD. When choosing the patch size for texture transfer, we should be careful to choose it small enough to avoid having a large varianvce in intensity values of target image in the region.





Blending

The texture transfered image can be used as the foreground to be blended on a background image using a mask. With laplacian stack of both background and foreground images and gaussian stack of the mask, we can make a blended image.







Sources

Stone Wall - Tree - Sponge - Blue Sponge - Crumpled Paper - Glassy Stone - Leaves - Pool - Whale