%% Reduce Volume Data Set
% This example uses a data set that is a collection of MRI slices of a human skull. This data is processed in a variety of ways:
% The 4-D array is squeezed (squeeze) into three dimensions and then reduced (reducevolume) so that what remains is every fourth element in the x and y directions and every element in the z direction.
% The reduced data is smoothed (smooth3).
% The outline of the skull is an isosurface generated as a patch (p1) whose vertex normals are recalculated to improve the appearance when lighting is applied (patch, isosurface, isonormals).
% A second patch (p2) with an interpolated face color draws the end caps (FaceColor) isocaps).
% The view of the object is set (view, axis, daspect).
% A 100-element grayscale colormap provides coloring for the end caps (colormap).
% Adding a light to the right of the camera illuminates the object (camlight, lighting).

load mri
D = squeeze(D);
[x,y,z,D] = reducevolume(D,[4,4,1]);
D = smooth3(D);
p1 = patch(isosurface(x,y,z,D,5),...
    'FaceColor','red','EdgeColor','none');
isonormals(x,y,z,D,p1)
p2 = patch(isocaps(x,y,z,D,5),...
    'FaceColor','interp','EdgeColor','none');
view(3) 
axis tight
daspect([1,1,.4])
colormap(gray(100))
camlight
lighting gouraud

% Copyright 2015 The MathWorks, Inc.