00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 static const char docstring[] =
00011 "mrf_segment_wts: segment with a discrete Markov random field\n"
00012 "\n"
00013 " [yp,post] = mrf_segment_wts(iter,T,beta,alpha,dist,y,lprob1,...,lprobK)\n"
00014 " * Performs iter full sweeps (using temperature schedule T) of\n"
00015 " Gibbs sampling on an input labeling y, with entries in 1..K, to produce\n"
00016 " an output labeling yp. Posterior probability is optionally returned.\n"
00017 " Posterior is actually an energy function, which is correct with respect\n"
00018 " to changes in y, but does not have the correct scale factors which\n"
00019 " vary with beta, alpha, and dist.\n"
00020 " * Conditional distributions of pixel data x given class y are\n"
00021 " calculated externally, and given by lprob1...lprobK, as log-\n"
00022 " probabilities.\n"
00023 " * Per-class biases are given by alpha, which can be empty, indicating\n"
00024 " no bias. Otherwise, the interpretation is alpha(k) is the prior\n"
00025 " log-probability of seeing class k.\n"
00026 " * The smoothness parameter of the MRF (Potts model) is beta. If beta\n"
00027 " is a matrix, beta(k,l) is the smoothness \"reward\" given to a site of\n"
00028 " class k for having a neighbor of class l. The scalar beta thus\n"
00029 " corresponds to a diagonal matrix with repeated beta entries.\n"
00030 " (beta and alpha agree with definitions in the Besag paper below.)\n"
00031 " * Pixel-pixel distances are given by dist, where dist(nu,m,n) gives\n"
00032 " the distance between pixel (i,j) and its neighbor number nu, looking\n"
00033 " up or left. For the 3x3 neighborhood, pixel s=(m,n) has 8 neighbors s',\n"
00034 " and distances to 4 of them, where s'<s, at offsets:\n"
00035 " (-1,-1),(0,-1),(1,-1),(-1,0),\n"
00036 " are given in that order, in dist(i,j,:). The other neighbors\n"
00037 " have s'>s, and the corresponding distances are listed in the\n"
00038 " symmetric entries of dist. If dist=[], it is taken to be\n"
00039 " everywhere 1, thus removing the direction-sensitive smoothing\n"
00040 " (but still smoothing).\n"
00041 " * Classes are 1..K, but labels NaN and 0 are not updated or counted\n"
00042 " as neighbors. Any NaN in a log-probability forces a NaN in the\n"
00043 " output class.\n"
00044 " * A `clock' at each pixel may speed computation. This recognizes that,\n"
00045 " if the neighbors of a pixel do not change, the Gibbs sampler is rolling\n"
00046 " a stationary die once per iteration to determine the pixel label.\n"
00047 " The waiting time until another label change is then geometric,\n"
00048 " and this waiting time can be sampled once to short-circuit a series\n"
00049 " of die rolls. See Ripley, below.\n"
00050 " * The speedup of this method is greatest when few labels change. If\n"
00051 " supplied, iter(2) is the threshold (in [0,1]) of #changed/#labels\n"
00052 " for a switchover from the ordinary method to the clock method.\n"
00053 " (Only one switch is permitted in the iteration sequence.)\n"
00054 " If iter(2) = 0, the ordinary coin-flip method is used throughout;\n"
00055 " if =1, the clock method is used throughout.\n"
00056 " * Annealing is permitted through the `temperature' parameter T.\n"
00057 " Initial temperature is T(1), reduced by a factor of T(2) at each\n"
00058 " iteration. The default T(2) = 1 suppresses annealing.\n"
00059 " Clocks are reset whenever the cumulative drop in temperature\n"
00060 " reaches a factor of T(3). (Roughly, then, clocks are reset every\n"
00061 " log(T(3))/log(T(2)) iterations.) If T(4) is present and equals\n"
00062 " zero, additional iterations are done at zero temperature, at the\n"
00063 " end of the normal annealing schedule, until the labels reach a\n"
00064 " fixed point. (This is equivalent to Besag's ICM.)\n"
00065 " * If iter[1] has a fractional part, that part is multiplied by 2**31\n"
00066 " and rounded to set the desired random number seed; if not, a\n"
00067 " pseudorandom seed is generated. This is provided to allow repeatability.\n"
00068 " * This is implemented as a MEX file.\n"
00069 "\n"
00070 " Inputs:\n"
00071 " int iter[1] or [2] = [0 0.05];\n"
00072 " real T[0] or [1] or [2] or [3] or [4] = [1 1 0.8 0];\n"
00073 " real beta[1] or [K,K];\n"
00074 " real alpha[K] or [0] = [];\n"
00075 " real dist[nbr,m,n] or [0];\n"
00076 " int y[m,n]; -- 1 <= y <= K, or 0 or NaN\n"
00077 " real lprob1[m,n];\n"
00078 " ...\n"
00079 " real lprobK[m,n];\n"
00080 "\n"
00081 " Outputs:\n"
00082 " int yp[m,n]; -- 1 <= y <= K, or 0 or NaN\n"
00083 " opt real post;\n"
00084 "\n"
00085 " See Also: mrf_segment, makemrfdiscwts\n"
00086 " Geman and Geman, Stochastic relaxation, Gibbs distributions, and\n"
00087 " the Bayesian restoration of images, IEEE PAMI Nov. 1984\n"
00088 " J. Besag, On the statistical analysis of dirty pictures, JRSSB, 1986\n"
00089 " B. D. Ripley, Statistical Inference for Spatial Processes,\n"
00090 " Cambridge U., 1988, p. 99\n"
00091 "\n"
00092 " turmon sep/oct 2006, weighted distance\n"
00093 " turmon 5 march 1999, modified to streamline for batch operations\n"
00094 " MJT 18 Mar 1996\n"
00095 "\n"
00096 "";
00097
00098
00099