Faster Semi Causal Nonparametric Markov Random Field Texture Synthesis
My Home Page
This algorithm is a cut down version of the algorithm published in IEEE Transactions on Image Processing 1998. In this version, it has been rewritten for a single cpu machine. To maintain speed of synthesis, the update function pUpdateFn() has been set to return the maximum value. If this was modified to return a portion of the maximum value, then the synthesis would take longer, but there would be a gain in quality. If you do decide to modify the code, be careful, as I have not put in any safeguard checks. Best to fully understand the whole code, before modifying it.
This faster version implements a modification based on Ashikhmin's Synthesizing Natural Textures. As noted in his work, the L2 norm may not be the best measure to test for perceptual similarity between two neighbourhoods. Instead, we may note that if we are only taking pixels from the input image (and not sampling from a larger distribution), then when we iterate a respective pixel, we can be assured that each of its defined neighbours occur within the input image. Speed can be gained if, instead of doing a exhaustive search, we only sample from those pixels which have the same neighbour. In this algorithm I have modified Ashikhmin's approach by using my previous algorithm, and sampling from all pixels which have at least one of its neighbours the same colour as its respective neighbour of the pixel being iterated.
Recently there has been quite an influx of nonparametric sampling techniques for texture synthesis (,here is a brief list). This is because it has been the nonparametric models that have had the greatest success at synthesising arbitrary textures. This technique uses a multiscale approach, which has the advantage that only a small neighbourhood is required.
However the basis of the algorithm first appeared in:
- R. Paget and I. D. Longstaff, ``A nonparametric multiscale Markov random
field model for synthesising natural textures,'' in Fourth International
Symposium on Signal Processing and its Applications, vol. 2, (Gold
Coast, Australia), pp. 744-747, ISSPA 96, August 1996.
- R. Paget and I. D. Longstaff, ``Texture synthesis via a nonparametric
Markov random field,'' in Proceedings of DICTA-95, Digital Image Computing:
Techniques and Applications (A. Maeder and B. Lovell, eds.), vol. 1,
(Brisbane, Australia), pp. 547-552, Australian Pattern Recognition Society,
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_faster [-l levels] [-n neighOrder] [-s] [-t treeMax] [-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.
- 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, cyclic = false
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 Tests||Fastest Run Time||Slowest Run Time||Mean Run Time||Stdev Run Time|
|1 -s ||165||0 0:02:12||0 0:06:28||0 0:02:48||0 0:00:31|
|1 -s -c||165||0 0:02:12||0 0:05:54||0 0:02:53||0 0:00:34|
|2 -s ||165||0 0:02:12||0 0:05:56||0 0:02:50||0 0:00:28|
|2 -s -c||165||0 0:02:15||0 0:07:55||0 0:02:55||0 0:00:35|
|3 -s ||165||0 0:02:16||0 0:06:48||0 0:02:55||0 0:00:35|
|3 -s -c||165||0 0:02:23||0 0:08:14||0 0:03:02||0 0:00:37|
|4 -s ||165||0 0:02:19||0 0:06:01||0 0:03:01||0 0:00:32|
|4 -s -c||165||0 0:02:11||0 0:05:42||0 0:02:47||0 0:00:23|
- This algorithm works well for natural textures which have a pixelwise
noise distribution. However unwanted noise appears in textures
that don't have a substantial pixel noise distribution (like
artificial textures). The noise seems to appear at pixel points
that have been synthesised at the higher grid levels (lower
resolution). There are various reasons for this, but it results
from modifying the update function pUpdateFn() in order to speed
up the algorithm.
- In this version, the Manhatten distance is used to find the
nearest neighbourhood. From personal observation, the
Manhatten distance produced more detail in the synthetic
texture compared to using the Euclidean norm.
- This faster version uses a combination of 3 different sampling
methods. The methods are used in a consecutive order until a
sample is found. They are as follows:
- Ashikhmin's sampling method.
- My modified version of Ashikhmin's sampling method.
- Exhaustive search.
- To compare this algorithm with other algorithms, it is necessary to
use the same neighbourhood for each.
For More Information
Email Rupert Paget at: firstname.lastname@example.org
This site was proofread by
English Editing Experts.