Contents

Area 2D

back to top
function[Area] = area_2D(polys,X)
      A = zeros(size(polys,1),1); %preallocate matrix
      for k = 1:size(polys,1)
      polytemp = polys(k,:); %extract a single triangle and assign to temp variable
      a = polytemp(1); %get coordinates for 1 of 3 triangle
      a = X(a,:);
      b = polytemp(2); %get coordinates for 1 of 3 triangle
      b = X(b,:);
      c = polytemp(3); %get coordinates for 1 of 3 triangle
      c = X(c,:);
      A(k) = 1/2 * abs( det( [ 1 1 1; b-a; c-a ]) ); %compute area of one triangle
      end
      Area = sum(A); %sum all areas
      

Load Image Data

back to top
function[] = loadmyimages()
mycd = cd; %get current path
mydir = dir([mycd,'/images']); %create variable for directory to images folder


icount = 1; %initialize counter
for k = 1:length(mydir);
    tempname = lower(mydir(k).name);
    if ~isempty(strfind(tempname,'.tif')) %create a name for all files with tif extension
        Itemp = imread(mydir(k).name); %get images
        if size(Itemp,3) == 3
            I(:,:,icount) = rgb2gray(Itemp); %store first channel of image into  variable
        else
            I(:,:,icount) = Itemp;
        end
        icount = icount + 1; %increment matrix I index
    elseif ~isempty(strfind(tempname,'.lsm'))
        myLSM = mydir(k).name; %store the .lsm file name
    else
        continue; %do not increment matrix I index
    end
end
Myfile = mydir(k).name;
assignin('base','Myfile',Myfile);

%check for image type .tiff or .lsm
%if .tiff, will need to manually or extrack microscope settings
%if .lsm can extract microscope settings
if exist('I','var') && ~isempty(I)
    MyI = I; %use MyI as active data set
    assignin('base','MyI',MyI);
    assignin('base','I',I);
    %get pixel dimension of cube volume
    assignin('base','DimensionX',size(I(:,:,1),1));
    assignin('base','DimensionY',size(I(:,:,1),2));
    assignin('base','DimensionZ',size(I(:,:,1),3));
    %get unit length dimensions of cube volume
    tempfile = lower(mydir(k).name);
    [Imag Izoom] = strtok(lower(tempfile),'x');

    Imag = Imag(end-1:end); %objective lense magnitude
    for k = 1:length(Izoom)
        if ~isnan(str2double(Izoom(k)))
            Izoom = Izoom(k); %zoom
            break
        end
    end


    if str2double(Imag) == 63 && str2double(Izoom) == 5 %FIX %FIX
        VoxelSizeX = 3.9000e-08;%lense = 63x, zoom = 5
        VoxelSizeY = 3.9000e-08;
        VoxelSizeZ = 5.0000e-07;
    elseif str2double(Imag) == 63 && str2double(Izoom) == 4
        VoxelSizeX = 6.9754e-08;%lense = 63x, zoom = 4
        VoxelSizeY = 6.9754e-08;
        VoxelSizeZ = 5.0000e-07;
    elseif str2double(Imag) == 63 && str2double(Izoom) == 3
        VoxelSizeX = 9.3006e-08;%lense = 63x, zoom = 3
        VoxelSizeY = 9.3006e-08;
        VoxelSizeZ = 5.0000e-07;
    elseif str2double(Imag) == 63 && str2double(Izoom) == 2 %FIX %FIX
        %lense = 63x, zoom = 2
    else
        %set to lense = 63x && zoom = 4
    end
    assignin('base','VoxelSizeX',VoxelSizeX);
    assignin('base','VoxelSizeY',VoxelSizeY);
    assignin('base','VoxelSizeZ',VoxelSizeZ);

elseif exist('myLSM','var') && ~isempty(myLSM)
    f = fullfile([cd,'\images\',myLSM]);
    myStack = tiffread32(f);
    for k = 1:length(myStack)
        I(:,:,k) = myStack(k).data{1};
    end
    MyI = I; %use MyI as active data set
    assignin('base','MyI',MyI);
    assignin('base','I',I);
    %get pixel dimension of cube volume
    assignin('base','DimensionX',myStack(1,1).lsm.DimensionX);
    assignin('base','DimensionY',myStack(1,1).lsm.DimensionY);
    assignin('base','DimensionZ',myStack(1,1).lsm.DimensionZ);
    %get unit length dimension of cube volume
    assignin('base','VoxelSizeX',myStack(1,1).lsm.VoxelSizeX);
    assignin('base','VoxelSizeY',myStack(1,1).lsm.VoxelSizeY);
    assignin('base','VoxelSizeZ',myStack(1,1).lsm.VoxelSizeZ);

else
    disp('No Images (.tiff) or (.lsm) found in images folder'); %if no files found notify user
end
function[MyIfilt] = myfilter(myImages)

Filters

back to top
%Pass the images to the GUI, filter and draw
%MyI = evalin('base','MyI');
MyI = myImages;

I = double(MyI(:,:,1));

%set up Gaussian filter works for square images
sizeU = length(I)/8;
u = -sizeU/2+1:sizeU/2;
v = u; sigma = .6; clear Hgauss;
for n = 1:size(u,2)
    for m = 1:size(v,2)
    Hgauss(n,m) = exp(-2*(pi*sigma)^2*((u(m)/sizeU)^2+(v(n)/sizeU)^2));
    end
end

%set up frequency template
H_LP = zeros(size(I,1),size(I,2)); %make filter to size of image
xstart = size(H_LP,1)/2 - sizeU/2 + 1; %correct for inclusive incrementation
xend = size(H_LP,1)/2 + sizeU/2;
ystart = size(H_LP,2)/2 - sizeU/2 + 1;
yend = size(H_LP,2)/2 + sizeU/2;
H_LP(xstart:xend,ystart:yend) = Hgauss;

MyIfilt = double(MyI);
for k = 1:size(MyI,3)
    J = fft2(MyI(:,:,k)); %make temp image
    Jshift = fftshift(J); %get frequency image
    %Apply Filter to freqency space of image
    Jshift_H_LP = Jshift.*H_LP;
    J_H_LP = fftshift(Jshift_H_LP);
    I_H_LP = ifft2(J_H_LP,'symmetric');%need to use symmetric inverseve due to roundoff errors
    %scale I
    tempI = double(I_H_LP);
    A = min(tempI(:));
    B = max(tempI(:));
    tempI = 255*( (tempI-A) / (B-A) ); %scale 0-255
    MyIfilt(:,:,k) = tempI; %reassign working I
end

h      = [ 0  0  0  1  0;... %filter
           0  1  0  1  0;...
           0 -2  0  2  0;...
           0  1  0  1  0;...
           0  0  0  1  0];

hup = h'; %rotate filter -90


%Process all Images in this loop
disp('Filtering Images...');
for n = 1:size(MyIfilt,3)

    I = MyIfilt(:,:,n);
    Ifliplr = fliplr(I);
    Iflipud = flipud(I);

    %Filter Left & Right
    PrewitHl = (imfilter(I,h,'replicate')); %left to rigth filter
    PrewitHr = (imfilter(Ifliplr,h,'replicate')); %right to left filter flipped
    PrewitHr = fliplr(PrewitHr); %right to left filter reoriented

    %Filter Top and Bottom
    PrewitVu = (imfilter(I,hup,'replicate')); %up down filter
    PrewitVd = (imfilter(Iflipud,hup,'replicate')); %down up filter flipped
    PrewitVd = flipud(PrewitVd); %down up filter reoriented

    %oragnize data into structure
    Prewitcellmat = {PrewitHl PrewitHr PrewitVu PrewitVd}; %make cell of all Prewit matrices
    Prewitcellstr = {'PrewitHl' 'PrewitHr' 'PrewitVu' 'PrewitVd'}; %make cell of all Prewit matrices
    Prewitstruct = struct('name', Prewitcellstr, 'data', Prewitcellmat); %make structure

    %scale data
    for k = 1:length(Prewitstruct); %iterate through the structure and scale data
        A = min(Prewitstruct(k).data(:));
        B = max(Prewitstruct(k).data(:));
        Prewitstruct(k).data = 255*((Prewitstruct(k).data)-A)/(B-A); %scale 0-255
        eval([Prewitstruct(k).name ' = Prewitstruct(k).data;']); %reassign scaled values
    end

    %multiply the horizontal and vertical filter results
    PrewitHmul = PrewitHl.*PrewitHr;
    PrewitVmul = PrewitVu.*PrewitVd;

    %oragnize data into structure
    Prewitmulcellmat = {PrewitHmul PrewitVmul};
    Prewitmulcellstr = {'PrewitHmul' 'PrewitVmul'};
    Prewitmulstruct = struct('name', Prewitmulcellstr, 'data', Prewitmulcellmat);

    %scale data
    for k = 1:length(Prewitmulstruct); %iterate through the structure and scale data
        A = min(Prewitmulstruct(k).data(:));
        B = max(Prewitmulstruct(k).data(:));
        Prewitmulstruct(k).data = 255*((Prewitmulstruct(k).data)-A)/(B-A); %scale 0-255
        eval([Prewitmulstruct(k).name ' = Prewitmulstruct(k).data;']); %reassign scaled values
    end

    PrewitmulHVsum = PrewitHmul + PrewitVmul;
    MyIfilt(:,:,n) = PrewitmulHVsum;
    %IaddPrewitmulHVsum = I + PrewitmulHVsum; %add the PrewitmulHVsum to the
    %filtered image before Prewit computation
end
disp('...Images Filtered')

Construct Mesh

back to top
function[V,SA,h] = myIConstruct(I)
%INPUT
%pass the interpolated image stack
%
%OUTPUT
%Volume (units cubed)
%Area (units squared)
%h, handle to figure with the surface are representation of volume


%setup parameters for volume fill with tetrahedra

%find if #objects > 1
%code not optimized for >1 objects, rather uses only largest object if >1
%objects. update later, can pass regions into vol2mesh
%CC = bwconncomp(MyIBw,18);
%(CC.NumObjects>1); %if more than one object compute stats for each object
%individually
%use vol2mesh ... xsize, ysize, zsize, to specify volumes

xsize = 1:size(I,1); %use entire x volume
ysize = 1:size(I,2); %use entire y volume
zsize = 1:size(I,3); %use entire z volume
levelset = 10; %[10 10 10]; %the isovalue
opt = 3; %struct('radbound',{3 3 3}, 'distbound', {.5});
dofix = 1; %perform volume filtering/smoothing
maxvol = 15; %maximum volume assigned to a single tetrahedron
%vol2mesh(img,ix,iy,iz,opt,maxvol,dofix,method,isovalues)
[node,elem,face] = vol2mesh(I,xsize,ysize,zsize,opt,maxvol,dofix,'cgalsurf',levelset);
disp('Calculating...')

assignin('base','node',node); %write to workspace
assignin('base','elem',elem); %write to workspace
assignin('base','face',face); %write to workspace

trep = TriRep(elem(:,1:4),node(:,1:3)); %get triangulation representation
% tetramesh(trep,'FaceColor','r','FaceAlpha',0.4) %plot tetrahedra
% whitebg('w'); %set background color

V = volume_3D(elem(:,1:4),node(:,1:3)); %compute volume of object

[tri xf] = freeBoundary(trep); %use the trinagulation representation to get surface of volume

SA = area_2D(tri,xf); %compute surface area of object

unit conversion

back to top
VoxelSizeX = evalin('base','VoxelSizeX'); %pass the voxelsizeX

VoxelXchar = num2str(VoxelSizeX); %the units are meters

[Xdec] = strtok(VoxelXchar,'e'); %get the fraction
[empty, Xexp] = strtok(VoxelXchar,'-'); %get the exponential

Xdec = str2double(Xdec); %fraction
Xexp = str2double(Xexp); %number of decimal places + or -

%get the micrometer representation
Xexpum = Xexp + 6; %10^6 um = 1m

%fix the fraction by Xexpum, the decimal places remainder after um conversion
Xdec = Xdec * 10^(Xexpum); %um units of perfect cube length

V = V*Xdec^3; %convert voxels to um^3
assignin('base','V',V)

disp(['Volume = ',num2str(V), ' um^3']); %display volume

SA = SA*Xdec^2; %convert faces to um^2
disp(['Surface Area = ', num2str(SA), ' um^2']); %display surface area

assignin('base','SA',SA)

Myfile = evalin('base','Myfile'); %get Myfile from base
Myfile = strtok(lower(Myfile),'x'); %parse
Myfile = Myfile(1:end-2); %parse

disp('Saving variables...')
%save variables to file
evalin('base', 'save(''MyData'', ''SA'', ''V'', ''VoxelSizeX'', ''Iinterp'', ''elem'', ''node'', ''face'', ''ThreshLevelinterp'', ''Myfile'');') %save variables to directory
disp('...variables saved')

disp('Drawing Surface...')

%create strings for title/legend
A = Myfile;
B = ['Surface Area = ', num2str(SA), ' um^2'];
C = ['Volume = ', num2str(V), ' um^3'];
D = ['Voxel Unit Volume = ' num2str(Xdec), ' um^3'];

%create char matrix with label strings
maxlength = max([length(A) length(B) length(C) length(D)]); %find longest string
E = nan(4,maxlength); %create numeric array that will fit largest string
E = num2str(E); %convert to char
E(:) = ' '; %fill with spaces (space bar)
E(1,1:length(A)) = A; %fill with string A
E(2,1:length(B)) = B; %fill with string B
E(3,1:length(C)) = C; %fill with string C
E(4,1:length(D)) = D; %fill with string D

%draw surface reconstruction
h = figure; trisurf(tri, xf(:,1), xf(:,2),...
    xf(:,3), 'FaceColor', 'r', 'FaceAlpha', 1); %plot the surface representation
set(gca,'projection','perspective') %set perspective
box off %turn off grid box
% light('position',[1,1,1]) %set lighting top
% light('position',[-1,-1,-1]) %set lighting bottom
daspect([1,1,1]) %set aspect ratio
axis on %leave axis on
axis vis3d %set the axis so that rotating is smooth/non distorted
view(-120,45) %set the view
set(gca,'color',[1,1,1]) %set background color
gca; %activate current figure
legend(E,'Location','NorthOutside'); %place and position the legend
myscreensize = get(0,'ScreenSize'); %get the screen size of monitor
set(h,'Position',myscreensize); %set the figure to full screen
zoom(1.5) %magnify the image
% xlabel(['pixels(1pixel = ', num2str(VoxelSizeX), ' m)']) %set x-axis title
% ylabel(['pixels(1pixel = ', num2str(VoxelSizeX), ' m)']) %set y-axis title
% zlabel(['pixels(1pixel = ', num2str(VoxelSizeX), ' m)']) %set z-axis title

hgsave(h,'Myreconstruction') %save drawing
disp('...drawing complete')

Resample by Interpolation

back to top
function[Iinterp] = myIinterp(I,ThreshLevel)
%%Interpolate Image on zaxis
%INPUT
%load MyIcropsc, the filtered, cropped, and scaled image stack
%
%OUTPUT
%interpolated image with interpolated binary mask applied
%
% %%Normalize images to 0 - 255, for optimal image processing with built in
% %%functions, like im2bw, which use uint8 signature
% for k = 1:size(I,3)
%     Itemp = I(:,:,k);
%     A = min(Itemp(:));
%     B = max(Itemp(:));
%     Itemp = 255*( (Itemp-A) / (B-A) ); %scale 0-255
%     I(:,:,k) = Itemp; %reassign I
% end

Volume Interpolation

back to top
%Depends on objective lens, zoom setting, z thickness
%Interpolate on the z axis.
%1:(1/a):n, where array length,(P) = an-(a-1), & n = #slices
%To solve for a:
%P = an - (a-1), where P = number of points & n = # slices
%P = an - a + 1
%P-1 = a(n-1)
%a = (P-1)/(n-1)
%To solve for j, where j = # of points between slices:
%j = 3; %integer number of slides to interpolate between consecutive slides
%the # of slices, P, depends on the size in distance of the x and y axis,
%for an image that measures 70 nm (x) by 70 nm (y) by 0.5um (z) per voxel,
%an interpolation correction to make a perfect cube would require adjusting
%the total number of slides in the z direction
%   pixels (z) = 0.5 um * 1/0.07um
%              = 7.1439 pixels
%   check answer: 0.5 um / 7.1439 pixels
%                 = 0.07 um
%   Now we have a perfect cube volume where x,y,z = 0.07um
%   Upon interpolating, for every z slice, there should be 7.1439 slices
%   to make the 'perfect cube' correction. An interpolated image stack would have
%   7.1439*slices(z)
%
%   To final error is always +/- 1 pixel or +/- , because of rounding to whole
%   integer.

%get voxel size from base workspace
VoxelSizeZ = evalin('base','VoxelSizeZ');
VoxelSizeX = evalin('base','VoxelSizeX');

correctionZ = VoxelSizeZ/VoxelSizeX; %compute the interpolation correction for perfect cube
% correctionZ = 7.1439;
n = size(I,3); %number of images in stack
P = ceil(correctionZ*n); %round interpolation integer number of slides
%j = P/n - 1;
%P = n*(j+1); %number of total images after interp
a = (P-1)/(n-1); %divisor
z = 1:(1/a):n; %interpolated axis

x = evalin('base','DimensionX'); %get the width
x = 1:x;
y = evalin('base','DimensionY'); %get the height
y = 1:y;
% x = 1:1:512; %size of image width = height
% y = x; %the x and y axis are both same size as canvas, so there is no interpolation
disp('Making Meshgrid...');
[xi yi zi] = meshgrid(x, y, z); %create meshgrid
disp('...Meshgrid Created');
disp('Interpolating...');
Iinterp = interp3(double(I),xi, yi, zi); %interpolate into xi yi zi space vi = interpolated MyIBw
disp('...Interpolated');
disp('Making binary Mask...');
%interpolate the threshold values
ThreshLevelinterp = interp1(1:length(ThreshLevel),ThreshLevel,z);
assignin('base','ThreshLevelinterp',ThreshLevelinterp); %save to workspace

%iterate through the interpolated images and apply ThreshLevelinterp
Bwinterp = logical(I);
se = strel('disk',3); %filter disk

for k = 1:length(z)
    Bwinterptemp = im2bw(uint8(Iinterp(:,:,k)),ThreshLevelinterp(k)); %get binary image, use uint8 for im2bw operation
    Bwinterptemp = bwareaopen(Bwinterptemp,200); %delete small objects
    Bwinterp(:,:,k) = imclose(Bwinterptemp,se); %get rid of samll holes in objects
end
disp('...Binary Mask Made');
Iinterp = Iinterp.*Bwinterp; %output the masked interpolated image

Make Graphs

back to top
% Execute in Stored Images folder directory

cd([cd, '\Stored Images']) %get current directory
addpath(genpath(cd)); %add all subfolders in directory
mydir = dir; %get list of all files and folders in directory

twicount = 1; %set counter
wtcount = 1; %set counter

for k = 1:length(mydir) %make loop that will go through all files and folders in directory
    tempstr = mydir(k).name; %make temporary string name
    twi = strfind(lower(tempstr),'twi'); %find 'twi' match, cast all characters to lower case, b/c case sensitive
    wt = strfind(lower(tempstr),'wt'); %find 'wt' match, cast all characters to lower case, b/c case sensitive

    if ~isempty(twi) %perform if found 'twi'
        Atemp = load([cd,'\',mydir(k).name,'\','MyData.mat'],'-mat', 'Myfile', 'SA','V'); %load data and store name, volume, and surface area to workspace
        TWIdataS(twicount,1) = Atemp; %save variables into cell
        twicount = twicount+1; %increment counter after variables entered into cell

    elseif ~isempty(wt) %perform if found 'wt'
        Atemp = load([cd,'\',mydir(k).name,'\','MyData.mat'],'-mat', 'Myfile', 'SA','V'); %load data and store name, volume, and surface area to workspace
        WTdataS(wtcount,1) = Atemp; %save variables into cell
        wtcount = wtcount+1; %increment counter after variables entered into cell

    else
        continue %continue loop if neither found

    end
end

% loop throuch cells and extract surface area and volume data
for k = 1:length(TWIdataS)
    TWISA(k,1) = TWIdataS(k,1).SA; %place all surface data into single variable
    TWIV(k,1) = TWIdataS(k,1).V; %place all volume data into single variable
end

% loop throuch cells and extract surface area and volume data
for k = 1:length(WTdataS)
    WTSA(k,1) = WTdataS(k,1).SA; %place all surface data into single variable
    WTV(k,1) = WTdataS(k,1).V; %place all volume data into single variable
end

%rearrange variables and place into a single array
Gmax = max(length(TWIdataS),length(WTdataS)); %find variable with greatest entries
Data = nan(Gmax,4); %create empty variable with respect to largest
Data(1:length(TWISA),1:2) = [TWISA TWIV]; %enter 'twi' data into first two columns
% TWISA = Data(1,:);
% TWIV = Data(2,:);
Data(1:length(WTSA),3:4) = [WTSA WTV]; %enter 'wt' data into first two rows
% WTSA = Data(3,:);
% WTV = Data(4,:);
Data = cat(1,Data(:,1:2),Data(:,3:4)); %rearrange variable

A = cell(Gmax,1); %create cell aray with respect to largest data set
A(:) = {'Twitcher'}; %enter names into cells
B = cell(Gmax,1); %create cell aray with respect to largest data set
B(:) = {'Wild Type'}; %enter names into cells
Groups = cat(1,A,B); %concatenante cells
Groups = nominal(Groups); %use built in functions, see matlab help


% Data = [TWISA TWIV;...
%                 WTSA WTV;];

%[order,number,group_median,group_iqr] = grpstats(Data,Groups2,{'gname','numel',@median,@iqr})

% Raw Data Values
%create parameters for data sets
NumObs = size(Data,1); %#of observations
NameObs = strcat({'Obs'},num2str((1:NumObs)','%d'));
iris = dataset({Groups,'Strain'}, {Data,'SA','V'}, 'ObsNames', NameObs);

% Stats
[m,s] = grpstats(Data,Groups,{'mean','sem'}); %mean standard error of the mean

[h,p] = ttest2([TWISA TWIV],[WTSA WTV]); %ttest

figure;
axis([0,20,0,20]);
text(9.54,10,{'TTest, P Statistic';...
    ['Area (um^2) ', num2str(p(1))];...
    ['Volume (um^3) ', num2str(p(2))]},...
    'horizontalalignment', 'center','fontweight', 'bold',...
    'backgroundcolor', 'w', 'verticalalignment', 'middle',...
    'fontsize', 24);
set(gca,'XTickLabel',[])
set(gca,'XTick',[])
set(gca,'YTickLabel',[])
set(gca,'YTick',[])
box off

% Scatter Plot
subset = ismember(Groups,{'Twitcher','Wild Type'});
scattergroup = Groups(subset);
figure;
gscatter(iris.SA(subset), iris.V(subset), scattergroup,'k','.o',[8 10])
xlabel('Surface Area um^2')
ylabel('Volume um^3')
title({'NMJ Morphology Scatter Plot';'Pre Synaptic Axon'})
legend('Location','best')

% Box Plots
figure;
subplot(1,2,1);
boxplot(Data(:,1),Groups,'Colors','k','whisker',inf);
ylabel('Surface Area um^2');
title({'NMJ Morphology Box Plot';'Pre Synaptic Axon'})
box off
subplot(1,2,2);
boxplot(Data(:,2),Groups','Colors','k','whisker',inf);
ylabel('Volume um^3');
title({'NMJ Morphology Box Plot';'Pre Synaptic Axon'})
box off
% Bar Plot
figure;
subplot(1,2,1)
bar(1,m(1,1),'FaceColor','w')
hold on
bar(2,m(2,1),'k')
legend('Twitcher','Wild Type','Location','best')
errorbar([1;2],m(:,1),[0;0],s(:,1),'lineStyle','none','Color','k')
hold off
set(gca,'XTickLabel',[])
ylabel('Surface Area um^2')
title({'NMJ Morphology Bar Plot & SEM';'Pre Synaptic Axon'})
box off
subplot(1,2,2)
bar(1,m(1,2),'FaceColor','w')
hold on
bar(2,m(2,2),'k')
legend('Twitcher','Wild Type','Location','best')
errorbar([1;2],m(:,2),[0;0],s(:,2),'lineStyle','none','Color','k')
hold off
set(gca,'XTickLabel',[])
ylabel('Volume um^3')
title({'NMJ Morphology Bar Plot & SEM';'Pre Synaptic Axon'})
box off

Make Movie

back to top
%Open video object and append frames from Image stack
aviobj = VideoWriter([Myfile,'.avi']); %make file name
aviobj.FrameRate = 30; %frames per second
aviobj.Quality = 100; %percent quality
open(aviobj); %open an object file

currentAZ = -120;
currentEL = 45;

h = figure('renderer','zbuffer');
%a1 = subplot(1,2,1);
%subplot(1,1,1);
trisurf(tri, xf(:,1), xf(:,2),...
    xf(:,3), 'FaceColor', 'r', 'FaceAlpha', 1); %plot the surface representation
a1 = gca;
set(gca,'projection','perspective') %set perspective
set(gca,'NextPlot','replacechildren')
box off %turn off grid box
% light('position',[1,1,1]) %set lighting top
% light('position',[-1,-1,-1]) %set lighting bottom
daspect([1,1,1]) %set aspect ratio
axis vis3d %
axis off %leave axis on
set(gca,'color',[1,1,1]) %set background color
gca; %activate current figure
legend(E,'Location','NorthOutside');
view(currentAZ,currentEL);

% a2 = subplot(1,2,2);
% trisurf(tri, xf(:,1), xf(:,2),...
%     xf(:,3), 'FaceColor', 'r', 'FaceAlpha', 1); %plot the surface representation
% set(gca,'projection','perspective') %set perspective
% box off %turn off grid box
% % light('position',[1,1,1]) %set lighting top
% % light('position',[-1,-1,-1]) %set lighting bottom
% daspect([1,1,1]) %set aspect ratio
% axis vis3d %
% axis off %leave axis on
% set(gca,'color',[1,1,1]) %set background color
% gca; %activate current figure
% view(currentAZ,currentEL);
a1;
zoom(a1,1.75);
% a2;
% zoom(a2,1.75);

% myscreensize = get(0,'ScreenSize');
% set(h,'Position',myscreensize);
set(h,'Position',[50 50 800 600]);

flip = 0;
for k = 1:4:360
    view(a1,currentAZ+k, currentEL);
%     view(a2,currentAZ, currentEL+k);
    %pause(0.01);
    F = getframe(h); %get current figure handle
    writeVideo(aviobj,F); %write current frame to aviobj
end

close(gcf);
close(aviobj);

iso2mesh

back to top
%iso2mesh - a compact, powerful yet simple-to-use 3D mesh generator
% The author of "iso2mesh" toolbox is Qianqian Fang. Qianqian
% is currently an Assistant Professor at Massachusetts General Hospital,
% Harvard Medical School.
%
% Address: Martinos Center for Biomedical Imaging,
%          Massachusetts General Hospital,
%          Harvard Medical School
%          Bldg 149, 13th St, Charlestown, MA 02129, USA
% URL: http://nmr.mgh.harvard.edu/~fangq/
% Email: <fangq at nmr.mgh.harvard.edu> or <fangqq at gmail.com>
%
%
% Other people had also contributed to this toolbox, they include
%
% - Aslak Grinsted <ag at glaciology.net>
% - Hang Si <si at wias-berlin.de>
% - Pierre Alliez <pierre.alliez at sophia.inria.fr>
% - Laurent Rineau <laurent.rineau__CGAL at normalesup.org>
% - Donghyeon Kim <danielkim at gist.ac.kr>
% - Blake Johnson <bjohnso at bbn.com>
% - Niclas Borlin <Niclas.Borlin at cs.umu.se>

% 		    GNU GENERAL PUBLIC LICENSE
% 		       Version 2, June 1991
%
%  Copyright (C) 1989, 1991 Free Software Foundation, Inc.
%                        51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
%  Everyone is permitted to copy and distribute verbatim copies
%  of this license document, but changing it is not allowed.