% Supplemental Item 1 for Spagna, J.C. et al., "PHYLOGENY, SCALING, AND THE GENERATION OF % EXTREME FORCES IN TRAP-JAW ANTS" % Code written by: Antonis Vakis % Tracing rotating appendages in MATLAB % Revision #5 - Comments edited by J. Spagna % 11/28/2007 clear all; close all; clc; % Zooming in at 150% of the original image size and showing axes iptsetpref('ImshowInitialMagnification',150) iptsetpref('ImshowAxesVisible','on') % Specifying the name of the image set (same as the folder name); % Note: the individual images should have an extension of TIF, not TIFF filename = input('Input the folder name (case-sensitive): ','s'); % Specifying number of frames per second fps = input('Frames per second: '); % Specifying the width of the video width = input('Width of the video (pixels): '); % Specifying the height of the video height = input('Height of the video (pixels): '); % Specifying the dpi of the images dpi = input('Input the image resolution (dpi): '); % Specifying/ creating image directory % Note: Change the name of the directory shown between quotation marks to % correspond to the path where captured images are saved! dir1 = ['C:\Documents and Settings\Antonis Vakis\My Documents\Biomechanics Research\Work\Velocities & Accelerations\Revision 5\Images\']; dir2 = [dir1,filename,'\']; addpath(dir1,dir2) % Adding paths % Specifying & displaying frames of interest % i.e. the frames where the strike is occuring disp('Please examine the images to determine the first and last frames of interest!') first = input('First frame of interest: '); last = input('Last frame of interest: '); NEWframenum = last - first + 1; % Number of frames of interest % Specify whether to trace both mandibles, only the left or only the right which = input('Select 0 to trace both mandibles; 1 to trace the left only; 2 trace the right only: '); if (which == 1) % Left mandible only % Identifying & recording mandible tip coordinates coords = zeros(NEWframenum,4); % Mandible coordinates base = zeros(2,2); % Mandible BASE coordinates figure(2) % Mandible base if (first <= 9) imshow([filename,'00',num2str(first),'.tif']) elseif (first <= 99) imshow([filename,'0',num2str(first),'.tif']) elseif (first <= 999) imshow([filename,num2str(first),'.tif']) end title('Select the approximate location of the mandible BASE') disp('Select the approximate location of the mandible BASE') [base(1,1),base(1,2)] = ginput(1); % Right mandible title('Select the RIGHT mandible tip') disp('Select the RIGHT mandible tip') dummycoords = zeros(1,2); [dummycoords(1,3),dummycoords(1,4)] = ginput(1); for k = 1:NEWframenum coords(k,3) = dummycoords(1,3); coords(k,4) = dummycoords(1,4); end % Left mandible for j = 1:NEWframenum figure(j + 2) % Displaying frames of interest if ((first - 1 + j) <= 9) imshow([filename,'00',num2str(first - 1 + j),'.tif']) elseif ((first - 1 + j) <= 99) imshow([filename,'0',num2str(first - 1 + j),'.tif']) elseif ((first - 1 + j) <= 999) imshow([filename,num2str(first - 1 + j),'.tif']) end title('Select the LEFT mandible tip') disp('Select the LEFT mandible tip') if (j > 1) hold on plot(coords(j - 1,1),coords(j - 1,2),'b*') plot(coords(j - 1,3),coords(j - 1,4),'r*') hold off end [coords(j,1),coords(j,2)] = ginput(1); end % Mandible base figure(NEWframenum + 3) if (last <= 9) imshow([filename,'00',num2str(last),'.tif']) elseif (last <= 99) imshow([filename,'0',num2str(last),'.tif']) elseif (last <= 999) imshow([filename,num2str(last),'.tif']) end title('Select the approximate location of the mandible BASE') [base(2,1),base(2,2)] = ginput(1); elseif (which == 2) % Right mandible only % Identifying & recording mandible tip coordinates coords = zeros(NEWframenum,4); % Mandible coordinates base = zeros(2,2); % Mandible BASE coordinates figure(2) % Mandible base if (first <= 9) imshow([filename,'00',num2str(first),'.tif']) elseif (first <= 99) imshow([filename,'0',num2str(first),'.tif']) elseif (first <= 999) imshow([filename,num2str(first),'.tif']) end title('Select the approximate location of the mandible BASE') disp('Select the approximate location of the mandible BASE') [base(1,1),base(1,2)] = ginput(1); % Left mandible title('Select the LEFT mandible tip') disp('Select the LEFT mandible tip') dummycoords = zeros(1,2); [dummycoords(1,1),dummycoords(1,2)] = ginput(1); for k = 1:NEWframenum coords(k,1) = dummycoords(1,1); coords(k,2) = dummycoords(1,2); end % Right mandible for j = 1:NEWframenum figure(j + 2) % Displaying frames of interest if ((first - 1 + j) <= 9) imshow([filename,'00',num2str(first - 1 + j),'.tif']) elseif ((first - 1 + j) <= 99) imshow([filename,'0',num2str(first - 1 + j),'.tif']) elseif ((first - 1 + j) <= 999) imshow([filename,num2str(first - 1 + j),'.tif']) end title('Select the RIGHT mandible tip') disp('Select the RIGHT mandible tip') if (j > 1) hold on plot(coords(j - 1,1),coords(j - 1,2),'b*') plot(coords(j - 1,3),coords(j - 1,4),'r*') hold off end [coords(j,3),coords(j,4)] = ginput(1); end % Mandible base figure(NEWframenum + 3) if (last <= 9) imshow([filename,'00',num2str(last),'.tif']) elseif (last <= 99) imshow([filename,'0',num2str(last),'.tif']) elseif (last <= 999) imshow([filename,num2str(last),'.tif']) end title('Select the approximate location of the mandible BASE') [base(2,1),base(2,2)] = ginput(1); else % Both mandibles % Identifying & recording mandible tip coordinates coords = zeros(NEWframenum,4); % Mandible coordinates base = zeros(2,2); % Mandible BASE coordinates figure(2) % Mandible base if (first <= 9) imshow([filename,'00',num2str(first),'.tif']) elseif (first <= 99) imshow([filename,'0',num2str(first),'.tif']) elseif (first <= 999) imshow([filename,num2str(first),'.tif']) end title('Select the approximate location of the mandible BASE') disp('Select the approximate location of the mandible BASE') [base(1,1),base(1,2)] = ginput(1); % Mandible tips for j = 1:NEWframenum figure(j + 2) % Displaying frames of interest if ((first - 1 + j) <= 9) imshow([filename,'00',num2str(first - 1 + j),'.tif']) elseif ((first - 1 + j) <= 99) imshow([filename,'0',num2str(first - 1 + j),'.tif']) elseif ((first - 1 + j) <= 999) imshow([filename,num2str(first - 1 + j),'.tif']) end title('Select the LEFT and RIGHT mandible tips') if (j > 1) hold on plot(coords(j - 1,1),coords(j - 1,2),'b*') plot(coords(j - 1,3),coords(j - 1,4),'r*') hold off end disp('Select the LEFT mandible tip') [coords(j,1),coords(j,2)] = ginput(1); disp('Select the RIGHT mandible tip') [coords(j,3),coords(j,4)] = ginput(1); end % Mandible base figure(NEWframenum + 3) if (last <= 9) imshow([filename,'00',num2str(last),'.tif']) elseif (last <= 99) imshow([filename,'0',num2str(last),'.tif']) elseif (last <= 999) imshow([filename,num2str(last),'.tif']) end title('Select the approximate location of the mandible BASE') [base(2,1),base(2,2)] = ginput(1); end % Averaging mandible base location base_coords = [((base(1,1) + base(2,1))/2) ((base(1,2) + base(2,2))/2)]; % Correcting the coordinates in terms of the origin (i.e. setting the % origin to be at the lower left instead of the upper left coords_new(:,1) = coords(:,1); coords_new(:,2) = height - coords(:,2); coords_new(:,3) = coords(:,3); coords_new(:,4) = height - coords(:,4); base_coords_new(:,1) = base_coords(:,1); base_coords_new(:,2) = height - base_coords(:,2); % Specifying the image magnification mag = input('Select 0 to use a magnification of 10x; 1 to specify other value: '); if (mag == 0) zoom = 10; else know = input('Select 0 if you know the value of the magnification; 1 if not: '); if (know == 0) zoom = input('Input the image magnification: '); else % Default image to be loaded manddefault = input('Specify the frame to be used for the calculation: '); % Mandible length from known data mandlength = input('Input the pre-measured mandible length: '); % Measuring the mandible size from the image figure(1) if (manddefault <= 9) imshow([filename,'00',num2str(manddefault),'.tif']) elseif (manddefault <= 99) imshow([filename,'0',num2str(manddefault),'.tif']) elseif (manddefault <= 999) imshow([filename,num2str(manddefault),'.tif']) end title('Select the start and end points of the mandible') disp('Select the start and end points of the mandible') % Calculating the magnification from the known and measured mandible % sizes mandcoords = zeros(2,2); [mandcoords(:,1),mandcoords(:,2)] = ginput(2); mandsize = sqrt((mandcoords(2,2) - mandcoords(1,2))^2 +... (mandcoords(2,1) - mandcoords(1,1))^2); zoom = (mandsize*0.0254)/dpi/mandlength; % Displaying the mangification factor disp('The magnification factor was calculated to be: '); zoom end end % Exporting the data necessary for the solution save([filename,'_data'],... 'NEWframenum','base_coords_new','coords_new','dir1','dir2',... 'dpi','first','fps','last','which','zoom');