% Statistical and Computational Methods in Brain Image Analysis
% Chapter 09. Heat Kernel Smoothing
%
% (C) Moo K. Chung 
% University of Wisconsin-Madison
% mkchung@wisc.edu

%-----------------------------------------
% SMOOTHING CORTICAL THICKNESS
% cortical thickness from the first autism subject
load AUTISM.coordinates.mat

surf.vertices=squeeze(autism_coord(1,:,:))';
surf.faces=tri;
thick_au=squeeze(sqrt(sum((autism_coord-autism_coordw).^2,2)));
figure;figure_trimesh(surf,thick_au(1,:)')
view([0 90]); caxis([2 6]); colormap('hot')

% heat kernel smoothing
smoothed=hk_smooth(thick_au(1,:),surf,1,50);
figure ;figure_trimesh(surf,smoothed);
view([0 90]); caxis([2 6]); colormap('hot')

% histogram comparison
figure;  hist(thick_au(1,:), 100)
figure ; hist(smoothed, 100)


%-----------------------------------------------
% SMOOTHING MANDIBLE SURFACE

load mandible77subjects.mat   
template.faces=faces;
template.vertices=voxelsize(44)*mean(vertices,3);
figure; figure_patch(template,[0.74 0.71 0.61],0.7);
view([90 60]); camlight;

ss= template;
figure; subplot(2,2,1); figure_patch(ss,[0.74 0.71 0.61],0.7);
view([90 60]); camlight;
title('Template')

sigma=1;
n_smooth=10;
ss.vertices=hk_smooth2(ss.vertices,ss, sigma,n_smooth);
subplot(2,2,2); figure_patch( ss,[0.74 0.71 0.61],0.7);
view([90 60]); camlight;
title('Smoothed Template with sigma=1, n=10')

n_smooth=40;
ss.vertices=hk_smooth2(ss.vertices,ss,sigma,n_smooth);
subplot(2,2,3); figure_patch( ss,[0.74 0.71 0.61],0.7);
view([90 60]); camlight;
title('Smoothed Template with sigma=1, n=50')

n_smooth=150;
ss.vertices=hk_smooth2(ss.vertices,ss,sigma,n_smooth);
subplot(2,2,4); figure_patch( ss,[0.74 0.71 0.61],0.7);
view([90 60]); camlight;
title('Smoothed Template with sigma=1, n=200')
