Code covered by the BSD License  

Highlights from
Digital Image Correlation Two Threads

Digital Image Correlation Two Threads

by

 

30 Dec 2006 (Updated )

Starts two instances of matlab divides the grid and merges validx and validy, Needs Digital Image Co

[validx,validy]=automate_image_threads(grid_x,grid_y,filenamelist);
function [validx,validy]=automate_image_threads(grid_x,grid_y,filenamelist);

% Code to process images in two threads
% Programmed by Chris
% Last revision: 12/28/06

% The automation function is the central function and processes all markers and 
% images by the use of the matlab function cpcorr.m. 
% Therefore the Current directory in matlab has to be the folder where 
% automate_image_twothreads.m finds the filenamelist.mat, grid_x.dat and grid_y.dat as well 
% as the images specified in filenamelist.mat. Just type automate_image_twothreads; and 
% press ENTER at the command line of matlab. 
% At first, automate_image_twothreads.m will open the first image in the filenamelist.mat and 
% plot the grid as green crosses on top. The next step will need some time since 
% all markers in that image have to be processed for the first image. After correlating 
% image one and two the new raster positions will be plotted as red crosses. On top 
% of the image and the green crosses. The time it will take to process 
% all images will be plotted on the figure but can easily be estimated by knowing the 
% raster point processing speed of your hardware. 
% Depending on the number of images and markers you are tracking, this process 
% can take between seconds and days. For 100 images and 200 markers a decent 
% computer should need 200 seconds. To get a better resolution you can always 
% run jobs overnight (e.g. 6000 markers in 1000 images) with higher resolutions. 
% Keep in mind that CORRSIZE which you changed in cpcorr.m will limit your 
% resolution. If you chose to use the 15 pixel as suggested a marker distance of 
% 30 pixel will lead to a full cover of the strain field. Choosing smaller marker 
% distances will lead to an interpolation since two neighboring markers share 
% pixels. Nevertheless a higher marker density can reduce the noise of the strain field.
% After all images are processed, automate_image_twothreads will write the files 
% validx.dat and validy.dat. The *.dat text files are meant to store the result in a 
% format which can be accessed by other programs also in the future.

clear 

% Load necessary files
if exist('grid_x')==0;
    load('grid_x.dat');              % file with x position, created by grid_generator.m
end
if exist('grid_y')==0;
    load('grid_y.dat');              % file with y position, created by grid_generator.m
end
if exist('filenamelist')==0;
    load('filenamelist');            % file with the list of filenames to be processed
end

% split up the marker matrix
[grid_x1,grid_x2,grid_y1,grid_y2]=splitmatrix(grid_x,grid_y);

% Save the current work directory and start two threads of matlab to
% process the images

workdirectory=pwd;
cd(matlabroot);
cd('work');
save workdirectory.dat workdirectory -ascii;
!matlabsessions

cd(char(workdirectory));

% Wait for the two threads to finish their task and load the files to merge
while exist('end1.txt','file') ==0;
        pause(1);
end
pause(1)

while exist('validx1.dat')==0;
    pause(1);
end
load('validx1.dat');
while exist('validy1.dat')==0;
    pause(1);
end
load('validy1.dat');
delete('end1.txt');

while exist('end2.txt','file') ==0;
        pause(1);
end

pause(1);
while exist('validx2.dat')==0;
    pause(1);
end
load('validx2.dat');
while exist('validy2.dat')==0;
    pause(1);
end
load('validy2.dat');
delete('end2.txt');

[validx, validy]=mergevalidxy(validx1,validx2,validy1,validy2);

%---------------------------------------------

function [validx, validy]=mergevalidxy(validx1,validx2,validy1,validy2);

% Written by Chris.

% After processig the marker grid, split by splitmatrix.m and processing
% all images with automate_image_session1.m and automate_image_session2.m
% you have to merge the results to one validx and one validy to process the
% results with displacement.m

if exist('validx1')==0;
load('validx1.dat');
end

if exist('validx2')==0;
load('validx2.dat');
end

if exist('validy1')==0;
load('validy1.dat');
end

if exist('validy2')==0;
load('validy2.dat');
end

validx=[validx1;validx2];
validy=[validy1;validy2];

save validx.dat validx -ascii -tabs;
save validy.dat validy -ascii -tabs;

%------------------------------------

function [grid_x1,grid_x2,grid_y1,grid_y2]=splitmatrix(grid_x,grid_y);

% This functions splits up the grid_x and the grid_y matrix of markers
% created by grid_generator.m. You can now start automate_image_session1.m
% and automate_image_session2.m in two matlab sessions to use more two
% processors ore dual processors. 
% After processiong all images you have to merge the matrices to get validx
% and validy

if exist('grid_x')==0;
    load('grid_x.dat');
end
if exist('grid_y')==0;
    load('grid_y.dat');
end
gridx=reshape(grid_x,[],1);
gridy=reshape(grid_y,[],1);
[gridlength gridwidth]=size(gridx);
grid_x1=gridx(1:round(gridlength/2),1);
grid_x2=gridx((round(gridlength/2)+1):gridlength,1);
grid_y1=gridy(1:round(gridlength/2),1);
grid_y2=gridy((round(gridlength/2)+1):gridlength,1);
save grid_x1.dat grid_x1 -ascii -tabs;
save grid_x2.dat grid_x2 -ascii -tabs;
save grid_y1.dat grid_y1 -ascii -tabs;
save grid_y2.dat grid_y2 -ascii -tabs;

Contact us