Semi Causal Nonparametric Markov Random Field Texture Synthesis on a Gaussian Pyramid with K Nearest Search

My Home Page

Original Version

Fast Version

This texture synthesis algorithm is basically a 2D implementation of Synthesis of Bidirectional Texture Functions on Arbitrary Surfaces by Tong, Zhang, Liu, Wang and Guo. The algorithm still retains the underlying structure of the previous fast version, however in this version the multiresolution is implemented via a Gaussian pyramid of the input image (instead of a decimated quadtree as in the fast version). The neighbourhood search algorithm has also been modified. In this version a k nearest neighbour lookup table is used, as in Synthesis of Bidirectional Texture Functions on Arbitrary Surfaces by Tong, Zhang, Liu, Wang and Guo. There is one slight difference though in this implementation, when the k nearest neighbour lookup table is constructed, a smaller starting set is used from which the k nearest neighbours are found. This was done to save memory and computational time. Consult the code and their paper for more information.

This version of the Semi Causal Nonparametric Markov Random Field Texture Synthesis is not as fast as the fast version, but it does offer some advantages. For one, there does appear to be a reduction in the speckle noise that was apparent in the images synthesised by the fast version. Also, due to the nearest neighbour search algorithm, better blending is achieved between different phases of the synthetic texture. However, there is a loss in texture detail also due to the nearest neighbour search algorithm. One possible solution was presented by Hertzman etal. Image Analogies: A General Texture Transfer Framework, in which the two nearest neighbour search techniques were used. Depending on a closeness of fit criteria, the result was taken from either one or the other search techniques. However the closeness of fit criteria depended on a slightly arbitrary input parameter.

In summary, this version works well for general textures and does better on synthetic textures than the fast version. However, for natural textures, I would recommend the fast version, as it retains more detail in the synthetic texture. Or even the fast version on a Gaussian pyramid, which is the fast version implemented on a Gaussian pyramid, but with Ashikhmin's search instead of K nearest search. For a list of other nonparametric texture synthesis techniques see the texture links page.

However the basis of the algorithm first appeared in:

Source Code

Download Source Code Copyright (C) 2002, by Rupert Paget, all rights reserved.

The source code requires ImageMagick to be preinstalled. To compile the code, run gmake in the parent directory. There are two makefiles, one in parent directory, and in the src directory. If the code does not compile, both makefiles will need to be edited. I have written one for a sun (default) and one for an sgi machine, but I give no guarantees that they will work.

The program is executed with the following command

nonparaMRF_gaussian_k [-l levels] [-n neighOrder] [-s] [-t treeMax] [-k kNearest] [-c] [-x cols] [-y rows] [-m maskfile] [-h] texturefile


levels =
number of gray levels the image will be compacted to. Reducing the number from 255, will probably not improve the synthesis, and will most likely increase the run time.
neighOrder =
number to signify neighbourhood size. See neighbourhoods for schematics of the neighbourhoods used in the texture synthesis algorithm.
s =
if set, the neighbourhood becomes a square neighbourhood.
treeMax =
maximum quadtree height. The algorithm will not allow the quadtree height to be set to a value that will allow either the input image or output image to be reduced to less than a 2x2 pixel image.
kNearest =
number of nearest neighbours used in pixel sampling search algorithm.
c =
if set, the output image is defined to be toroidal (ie cyclic) where each border matches with its opposite border.
cols =
number of columns in the output image. If undefined, number columns in the output image will equal number columns in the input image.
rows =
number of rows in the output image. If undefined, number rows in the output image will equal number rows in the input image.
maskfile =
is a mask image that must be the same size as the input texture image. Only where the mask image is non zero is the input image used.
h =
if set, will mean that just usage and default values will be displayed. This will also occur if no input values are given.
texturefile =
is the input texture image that is to be synthesised.

Default values are : levels = 256, neighOrder = 1, square = false, treeMax = 6, kNearest = 20, cyclic = false

Schematic of the neighbourhoods used in the texture synthesis algorithmSchematic of the neighbourhoods used in the texture synthesis algorithm

Synthesis run times for various input parameters

These times were compiled on a distributed system of mainly SunBlades 100: 500 MHz, 256 MBytes RAM. The input textures were 128x128 pixel images, and the output synthesised textures were 256x256 pixel images. The run times are basically dependent on output image size and the type of input texture. This is due to the nearest neighbour search algorithm used in the code. If the input texture is fairly uniform in colour, then the search algorithm will be more of an exhaustive search, and therefore more dependent on input image size. Time stamps are in "Days Hours:Minutes:Seconds".

Neighbourhood# of TestsMin Run TimeMax Run TimeMean Run TimeStdev Run Time
1 1650 0:04:050 0:12:240 0:04:420 0:01:06
1 -c 1650 0:04:050 0:12:210 0:04:380 0:01:09
1 -s 1650 0:04:300 0:13:480 0:05:110 0:01:17
1 -s -c1650 0:04:330 0:14:190 0:05:110 0:01:24
2 1650 0:05:180 0:16:280 0:06:170 0:01:25
2 -c 1650 0:05:280 0:09:500 0:06:220 0:01:10
2 -s 1650 0:11:000 0:21:100 0:13:170 0:02:05
2 -s -c1650 0:11:210 0:23:090 0:13:540 0:02:39
3 1650 0:06:300 0:20:280 0:07:360 0:01:32
3 -c 1650 0:06:360 0:21:230 0:08:030 0:02:08
3 -s 1650 0:34:250 1:56:030 0:44:450 0:09:46
3 -s -c1650 0:36:110 1:56:120 0:46:510 0:09:41
4 1650 0:07:300 0:15:110 0:08:520 0:01:33
4 -c 1650 0:07:360 0:26:030 0:09:210 0:02:24
4 -s 1650 1:34:300 5:37:250 2:08:300 0:32:01
4 -s -c1650 1:43:160 5:48:460 2:17:230 0:30:42

Additional Information

For More Information

Email Rupert Paget at:

Valid HTML 4.01!

This site was proofread by
English Editing Experts.