1
function [validx,validy]=automate_image(grid_x,grid_y,filenamelist,validx,validy);
3
% Code to start actual image correlation
4
% Programmed by Chris and Rob
5
% Last revision: 09/10/08
7
% The automation function is the central function and processes all markers and
8
% images by the use of the matlab function cpcorr.m.
9
% Therefore the Current directory in matlab has to be the folder where
10
% automate_image.m finds the filenamelist.mat, grid_x.dat and grid_y.dat as well
11
% as the images specified in filenamelist.mat. Just type automate_image; and
12
% press ENTER at the command line of matlab.
13
% At first, automate_image.m will open the first image in the filenamelist.mat and
14
% plot the grid as green crosses on top. The next step will need some time since
15
% all markers in that image have to be processed for the first image. After correlating
16
% image one and two the new raster positions will be plotted as red crosses. On top
17
% of the image and the green crosses. The next dialog will ask you if you want to
18
% continue with this correlation or cancel. If you press continue, automate_image.m
19
% will process all images in the filenamelist.mat. The time it will take to process
20
% all images will be plotted on the figure but can easily be estimated by knowing the
21
% raster point processing speed (see processing speed).
22
% Depending on the number of images and markers you are tracking, this process
23
% can take between seconds and days. For 100 images and 200 markers a decent
24
% computer should need 200 seconds. To get a better resolution you can always
25
% run jobs overnight (e.g. 6000 markers in 1000 images) with higher resolutions.
26
% Keep in mind that CORRSIZE which you changed in cpcorr.m will limit your
27
% resolution. If you chose to use the 15 pixel as suggested a marker distance of
28
% 30 pixel will lead to a full cover of the strain field. Choosing smaller marker
29
% distances will lead to an interpolation since two neighboring markers share
30
% pixels. Nevertheless a higher marker density can reduce the noise of the strain field.
31
% When all images are processed, automate_image will write the files validx.mat,
32
% validy.mat, validx.txt and validy.txt. The text files are meant to store the result in a
33
% format which can be accessed by other programs also in the future.
35
% Minor changes by Suren A. Chilingaryan <csa@dside.dyndns.org> to look for data
36
% files in sub directories.
41
% exist('filenamelist')
46
if exist('data', 'dir')
52
if exist('images', 'dir')
58
% Load necessary files
60
load([datadir, 'grid_x.dat']) % file with x position, created by grid_generator.m
63
load([datadir, 'grid_y.dat']) % file with y position, created by grid_generator.m
65
if exist('filenamelist')==0
66
load([datadir, 'filenamelist']) % file with the list of filenames to be processed
72
[Rasternum Imagenum]=size(validx);
77
% Initialize variables
78
input_points_x=grid_x;
81
input_points_y=grid_y;
85
input_points_x=validx(:,Imagenum);
86
input_points_y=validy(:,Imagenum);
90
[row,col]=size(base_points_x); % this will determine the number of rasterpoints we have to run through
91
[r,c]=size(filenamelist); % this will determine the number of images we have to loop through
94
% Open new figure so previous ones (if open) are not overwritten
96
imshow([imagedir, filenamelist(1,:)]) % show the first image
97
title('Initial Grid For Image Correlation (Note green crosses)') % put a title
99
plot(grid_x,grid_y,'g+') % plot the grid onto the image
102
% Start image correlation using cpcorr.m
103
g = waitbar(0,sprintf('Processing images')); % initialize the waitbar
104
set(g,'Position',[275,50,275,50]) % set the position of the waitbar [left bottom width height]
108
firstimage=Imagenum+1
111
for i=firstimage:(r-1) % run through all images
114
tic % start the timer
115
base = uint8(mean(double(imread([imagedir, 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
116
input = uint8(mean(double(imread([imagedir, filenamelist((i+1),:)])),3)); % read in the image which has to be correlated
118
input_points_for(:,1)=reshape(input_points_x,[],1); % we reshape the input points to one row of values since this is the shape cpcorr will accept
119
input_points_for(:,2)=reshape(input_points_y,[],1);
120
base_points_for(:,1)=reshape(base_points_x,[],1);
121
base_points_for(:,2)=reshape(base_points_y,[],1);
122
input_correl(:,:)=cpcorr(input_points_for, 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
123
input_correl_x=input_correl(:,1); % the results we get from cpcorr for the x-direction
124
input_correl_y=input_correl(:,2); % the results we get from cpcorr for the y-direction
127
validx(:,i)=input_correl_x; % lets save the data
128
savelinex=input_correl_x';
129
dlmwrite([datadir, '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 ;-)
131
validy(:,i)=input_correl_y;
132
saveliney=input_correl_y';
133
dlmwrite([datadir, 'resultsimcorry.txt'], saveliney , 'delimiter', '\t', '-append');
135
waitbar(i/(r-1)) % update the waitbar
137
% Update base and input points for cpcorr.m
138
base_points_x=grid_x;
139
base_points_y=grid_y;
140
input_points_x=input_correl_x;
141
input_points_y=input_correl_y;
143
imshow([imagedir, filenamelist(i+1,:)]) % update image
145
plot(grid_x,grid_y,'g+') % plot start position of raster
146
plot(input_correl_x,input_correl_y,'r+') % plot actual postition of raster
149
time(i)=toc; % take time
150
estimatedtime=sum(time)/i*(r-1); % estimate time to process
151
title(['# Im.: ', num2str((r-1)),'; Proc. Im. #: ', num2str((i)),'; # Rasterp.:',num2str(row*col), '; Est. Time [s] ', num2str(round(estimatedtime)), '; Elapsed Time [s] ', num2str(round(sum(time)))]); % plot a title onto the image
161
save ([datadir, 'time.dat'], 'time', '-ascii', '-tabs')
162
save ([datadir, 'validx.dat'], 'validx', '-ascii', '-tabs')
163
save ([datadir, 'validy.dat'], 'validy', '-ascii', '-tabs')