How to use this plugin?
1.Extract the newseg_plugin directory into .../spm8/toolbox/Seg 

2.Compile the Reg_Term.cpp mexfile. 
(If your system is 64 bit Redhat, this step can skip since there is a compiled Reg_Term.mexa64.)
First, please make sure the gcc-g++ complier was installed correctly in your computer.
Then open Matlab, and change the current directory to 
../spm8/toolbox/Seg/newseg_plugin. Type the following command in the Matlab command window to compile the mexfile Reg_Term.cpp:
mex Reg_Term.cpp -O

3.Open spm_preproc_run.m in the ../spm8/toolbox/Seg directory.
Finding the spm_preproc_write8 function. (In about line 110.)
Then add the following codes before spm_preproc_write8:
spm_preproc_smoothness(res,tmp1,tmp2,tmp3); 


Just like:
...
        if iter==nit,
            % Final iteration, so write out the required data.
            tmp1 = [cat(1,job.tissue(:).native) cat(1,job.tissue(:).warped)];
            tmp2 =  cat(1,job.channel(:).write);
            tmp3 = job.warp.write;
            spm_preproc_smoothness(res,tmp1,tmp2,tmp3);
            spm_preproc_write8(res,tmp1,tmp2,tmp3);
            
else
...
 
4. Set Matlab path. Open file->Set Path->Add Folder, 
and add the new path /spm8/toolbox/Seg/newseg_plugin. 

5. Then you can open spm to run newsegment and get the results.

The .nii files with the first letter "c" is the default results by newsegment.
The improved smoothness results were saved in the .nii files whose names began with letters 'sc'.


Note: One can change the parameters 'beta' and 'wsize' in spm_preproc_smoothness function to get some results with different regularization. Generally speaking, larger 'beta' and 'wsize would produce smoother results. If beta=0 or wsize<1, the results would degrade to the default of newsegment.  

Reference:
Jun Liu, Haili Zhang, Image Segmentation Using a Local GMM in a Variational
Framework, submitting to J. Math Imaging Vis. 
