00001 00002 /* 00003 * THIS IS A GENERATED FILE; DO NOT EDIT. 00004 * 00005 * Declarations for calling `mrf_segment_wts' a.k.a. `msw' as a C library. 00006 * 00007 * Made by intermediate binary `mrf_segment_wts.out' on: 00008 * Mon Jun 7 15:37:56 2010 00009 * 00010 * Code for include-generation driver `../Gen-include.c' last modified on: 00011 * Mon Jun 7 15:11:28 2010 00012 * 00013 */ 00014 00015 // Original documentation block 00016 /* 00017 * mrf_segment_wts: segment with a discrete Markov random field 00018 * 00019 * [yp,post] = mrf_segment_wts(iter,T,beta,alpha,dist,y,lprob1,...,lprobK) 00020 * * Performs iter full sweeps (using temperature schedule T) of 00021 * Gibbs sampling on an input labeling y, with entries in 1..K, to produce 00022 * an output labeling yp. Posterior probability is optionally returned. 00023 * Posterior is actually an energy function, which is correct with respect 00024 * to changes in y, but does not have the correct scale factors which 00025 * vary with beta, alpha, and dist. 00026 * * Conditional distributions of pixel data x given class y are 00027 * calculated externally, and given by lprob1...lprobK, as log- 00028 * probabilities. 00029 * * Per-class biases are given by alpha, which can be empty, indicating 00030 * no bias. Otherwise, the interpretation is alpha(k) is the prior 00031 * log-probability of seeing class k. 00032 * * The smoothness parameter of the MRF (Potts model) is beta. If beta 00033 * is a matrix, beta(k,l) is the smoothness "reward" given to a site of 00034 * class k for having a neighbor of class l. The scalar beta thus 00035 * corresponds to a diagonal matrix with repeated beta entries. 00036 * (beta and alpha agree with definitions in the Besag paper below.) 00037 * * Pixel-pixel distances are given by dist, where dist(nu,m,n) gives 00038 * the distance between pixel (i,j) and its neighbor number nu, looking 00039 * up or left. For the 3x3 neighborhood, pixel s=(m,n) has 8 neighbors s', 00040 * and distances to 4 of them, where s'<s, at offsets: 00041 * (-1,-1),(0,-1),(1,-1),(-1,0), 00042 * are given in that order, in dist(i,j,:). The other neighbors 00043 * have s'>s, and the corresponding distances are listed in the 00044 * symmetric entries of dist. If dist=[], it is taken to be 00045 * everywhere 1, thus removing the direction-sensitive smoothing 00046 * (but still smoothing). 00047 * * Classes are 1..K, but labels NaN and 0 are not updated or counted 00048 * as neighbors. Any NaN in a log-probability forces a NaN in the 00049 * output class. 00050 * * A `clock' at each pixel may speed computation. This recognizes that, 00051 * if the neighbors of a pixel do not change, the Gibbs sampler is rolling 00052 * a stationary die once per iteration to determine the pixel label. 00053 * The waiting time until another label change is then geometric, 00054 * and this waiting time can be sampled once to short-circuit a series 00055 * of die rolls. See Ripley, below. 00056 * * The speedup of this method is greatest when few labels change. If 00057 * supplied, iter(2) is the threshold (in [0,1]) of #changed/#labels 00058 * for a switchover from the ordinary method to the clock method. 00059 * (Only one switch is permitted in the iteration sequence.) 00060 * If iter(2) = 0, the ordinary coin-flip method is used throughout; 00061 * if =1, the clock method is used throughout. 00062 * * Annealing is permitted through the `temperature' parameter T. 00063 * Initial temperature is T(1), reduced by a factor of T(2) at each 00064 * iteration. The default T(2) = 1 suppresses annealing. 00065 * Clocks are reset whenever the cumulative drop in temperature 00066 * reaches a factor of T(3). (Roughly, then, clocks are reset every 00067 * log(T(3))/log(T(2)) iterations.) If T(4) is present and equals 00068 * zero, additional iterations are done at zero temperature, at the 00069 * end of the normal annealing schedule, until the labels reach a 00070 * fixed point. (This is equivalent to Besag's ICM.) 00071 * * If iter[1] has a fractional part, that part is multiplied by 2**31 00072 * and rounded to set the desired random number seed; if not, a 00073 * pseudorandom seed is generated. This is provided to allow repeatability. 00074 * * This is implemented as a MEX file. 00075 * 00076 * Inputs: 00077 * int iter[1] or [2] = [0 0.05]; 00078 * real T[0] or [1] or [2] or [3] or [4] = [1 1 0.8 0]; 00079 * real beta[1] or [K,K]; 00080 * real alpha[K] or [0] = []; 00081 * real dist[nbr,m,n] or [0]; 00082 * int y[m,n]; -- 1 <= y <= K, or 0 or NaN 00083 * real lprob1[m,n]; 00084 * ... 00085 * real lprobK[m,n]; 00086 * 00087 * Outputs: 00088 * int yp[m,n]; -- 1 <= y <= K, or 0 or NaN 00089 * opt real post; 00090 * 00091 * See Also: mrf_segment, makemrfdiscwts 00092 * Geman and Geman, Stochastic relaxation, Gibbs distributions, and 00093 * the Bayesian restoration of images, IEEE PAMI Nov. 1984 00094 * J. Besag, On the statistical analysis of dirty pictures, JRSSB, 1986 00095 * B. D. Ripley, Statistical Inference for Spatial Processes, 00096 * Cambridge U., 1988, p. 99 00097 * 00098 * turmon sep/oct 2006, weighted distance 00099 * turmon 5 march 1999, modified to streamline for batch operations 00100 * MJT 18 Mar 1996 00101 * 00102 * 00103 */ 00104 00105 #ifndef _mexfn_mrf_segment_wts_h_ 00106 #define _mexfn_mrf_segment_wts_h_ 00107 00108 // function entry point 00109 mexfn_lib_t main_mrf_segment_wts; 00110 00111 // argument counts 00112 #define MXT_msw_NARGIN_MIN 7 00113 #define MXT_msw_NARGIN_MAX 14 00114 #define MXT_msw_NARGOUT_MIN 0 00115 #define MXT_msw_NARGOUT_MAX 2 00116 00117 // input argument numbers 00118 #define MXT_msw_ARG_iters 0 00119 #define MXT_msw_ARG_T 1 00120 #define MXT_msw_ARG_beta 2 00121 #define MXT_msw_ARG_alpha 3 00122 #define MXT_msw_ARG_dist 4 00123 #define MXT_msw_ARG_y 5 00124 #define MXT_msw_ARG_lprob1 6 00125 #define MXT_msw_ARG_lprob2 7 00126 #define MXT_msw_ARG_lprob3 8 00127 #define MXT_msw_ARG_lprob4 9 00128 #define MXT_msw_ARG_lprob5 10 00129 #define MXT_msw_ARG_lprob6 11 00130 #define MXT_msw_ARG_lprob7 12 00131 #define MXT_msw_ARG_lprob8 13 00132 00133 // output argument numbers 00134 #define MXT_msw_ARG_yp 0 00135 #define MXT_msw_ARG_post 1 00136 00137 00138 #endif // _mexfn_mrf_segment_wts_h_ 00139 00140 // (file ends)