1
function [validx,validy]=automate_image_mp_2009b(grid_x,grid_y,filenamelist,validx,validy);
3
%% Coarse grained multi core code to start actual image correlation
4
% Be aware that you will need the Parallel Computing Toolbox and at least
5
% Matlab 2009b, all earlier version do not work. Experience shows that
6
% logical processor cores as available within the Core i7 series of Intel
7
% do not accelerate the code much. this seems to be due to the highly
8
% optimized fft code of matlab and the extensive memory bandwidth needed.
10
% Last change by Chris
12
% Last revision: 9/8/10
15
% The automation function is the central function and processes all markers and
16
% images by the use of the matlab function cpcorr.m.
17
% Therefore the Current directory in matlab has to be the folder where
18
% automate_image.m finds the filenamelist.mat, grid_x.dat and grid_y.dat as well
19
% as the images specified in filenamelist.mat. Just type automate_image; and
20
% press ENTER at the command line of matlab.
21
% At first, automate_image.m will open the first image in the filenamelist.mat and
22
% plot the grid as green crosses on top. The next step will need some time since
23
% all markers in that image have to be processed for the first image. After correlating
24
% image one and two the new raster positions will be plotted as red crosses. On top
25
% of the image and the green crosses. The next dialog will ask you if you want to
26
% continue with this correlation or cancel. If you press continue, automate_image.m
27
% will process all images in the filenamelist.mat. The time it will take to process
28
% all images will be plotted on the figure but can easily be estimated by knowing the
29
% raster point processing speed (see processing speed).
30
% Depending on the number of images and markers you are tracking, this process
31
% can take between seconds and days. For 100 images and 200 markers a decent
32
% computer should need 200 seconds. To get a better resolution you can always
33
% run jobs overnight (e.g. 6000 markers in 1000 images) with higher resolutions.
34
% Keep in mind that CORRSIZE which you changed in cpcorr.m will limit your
35
% resolution. If you chose to use the 15 pixel as suggested a marker distance of
36
% 30 pixel will lead to a full cover of the strain field. Choosing smaller marker
37
% distances will lead to an interpolation since two neighboring markers share
38
% pixels. Nevertheless a higher marker density can reduce the noise of the strain field.
39
% When all images are processed, automate_image will write the files validx.mat,
40
% validy.mat, validx.txt and validy.txt. The text files are meant to store the result in a
41
% format which can be accessed by other programs also in the future.
46
% exist('filenamelist')
50
% Load necessary files
52
load('grid_x.dat') % file with x position, created by grid_generator.m
55
load('grid_y.dat') % file with y position, created by grid_generator.m
57
if exist('filenamelist')==0
58
load('filenamelist') % file with the list of filenames to be processed
64
[Rasternum Imagenum]=size(validx);
70
% Initialize variables
71
input_points_x=grid_x;
74
input_points_y=grid_y;
78
[row,col]=size(base_points_x); % this will determine the number of rasterpoints we have to run through
79
[r,c]=size(filenamelist); % this will determine the number of images we have to loop through
81
%% multicore part, here we start the matlabpool and the matlab workers
82
% after checking if there is a matlabpool available it starts a local one.
83
% If you want to limit the number of workers to the real core count (not
84
% the logical ones, you can add the number in line 94 (e.g. matlabpool 4)
89
matlabpool %start a new matlabpool
94
grid_x=reshape(grid_x,[],1);
95
grid_y=reshape(grid_y,[],1);
97
numberperlab=length(grid_x)/poolsize;
99
% single program multiple data - here we distribute the work between the
103
input_points_x=grid_x(1+(labindex-1)*fix(numberperlab):(labindex)*fix(numberperlab),1);
105
input_points_x=grid_x(1+(labindex-1)*fix(numberperlab):length(grid_x),1);
107
base_points_x=input_points_x;
111
input_points_y=grid_y(1+(labindex-1)*fix(numberperlab):(labindex)*fix(numberperlab),1);
113
input_points_y=grid_y(1+(labindex-1)*fix(numberperlab):length(grid_x),1);
115
base_points_y=input_points_y;
118
%% Open new figure so previous ones (if open) are not overwritten
120
imshow(filenamelist(1,:)) % show the first image
121
title('Initial Grid For Image Correlation (Note green crosses)') % put a title
123
plot(grid_x,grid_y,'g+') % plot the grid onto the image
126
% Start image correlation using cpcorr.m
127
g = waitbar(0,sprintf('Processing images')); % initialize the waitbar
128
set(g,'Position',[275,50,275,50]) % set the position of the waitbar [left bottom width height]
131
base = uint8(mean(double(imread(filenamelist(1,:))),3)); % read in the base image ( which is always image number one. You might want to change that to improve correlation results in case the light conditions are changing during the experiment
133
for i=firstimage:(r-1) % run through all images
136
tic; % start the timer
137
input = uint8(mean(double(imread(filenamelist((i+1),:))),3)); % read in the image which has to be correlated
139
% here we send of the image to the individual workers which will work
140
% on their specific markers
142
input_points_for=[input_points_x input_points_y];
143
base_points_for=[base_points_x base_points_y];
144
% rounding the input and base points gives much better resolution -
145
% seems to be a imcrop problem but I'm still investigating
146
input_correl(:,:)=cpcorr(round(input_points_for),round(base_points_for), input, base); % here we go and give all the markers and images to process to cpcorr.m which ic a function provided by the matlab image processing toolbox
147
input_correl_x=input_correl(:,1); % the results we get from cpcorr for the x-direction
148
input_points_x=input_correl_x;
149
input_correl_y=input_correl(:,2); % the results we get from cpcorr for the y-direction
150
input_points_y=input_correl_y;
153
% we need to collect all the data from our workers
154
for j=1:numel(input_correl_x)
155
lengthx(j,:)=size(input_correl_x{j});
158
for j=1:numel(input_correl_x)
160
bis=bis+lengthx(j,1);
161
validx_temp(von:bis,:)=input_correl_x{j};
162
validy_temp(von:bis,:)=input_correl_y{j};
165
validx(:,i)=validx_temp; % lets save the data
166
savelinex=validx_temp';
167
dlmwrite('resultsimcorrx.txt', savelinex , 'delimiter', '\t', '-append'); % Here we save the result from each image; if you are desperately want to run this function with e.g. matlab 6.5 then you should comment this line out. If you do that the data will be saved at the end of the correlation step - good luck ;-)
169
validy(:,i)=validy_temp;
170
saveliney=validy_temp';
171
dlmwrite('resultsimcorry.txt', saveliney , 'delimiter', '\t', '-append');
173
waitbar(i/(r-1)) ; % update the waitbar
175
imshow(filenamelist(i+1,:)) ; % update image
177
plot(grid_x,grid_y,'g+'); % plot start position of raster
178
plot(validx_temp,validy_temp,'r+'); % plot actual postition of raster
181
time(i)=toc; % take time
182
estimatedtime=sum(time)/i*(r-1); % estimate time to process
183
title(['# Im.: ', num2str((r-1)),'; Proc. Im. #: ', num2str((i)),'; # Rasterp.:',num2str(row*col), '; Est. Time [s] ', num2str(estimatedtime), '; Elapsed Time [s] ', num2str(sum(time))]); % plot a title onto the image
194
save time.dat time -ascii -tabs
195
save validx.dat validx -ascii -tabs
196
save validy.dat validy -ascii -tabs