1
function [validx, validy, displx, disply]=RTCorrCode(grid_x,grid_y,straindir,Firstimagename)
3
% Real time Correlation Code
7
RTselection = menu(sprintf('End processing by end.txt or by last image?'),...
8
'Stop with end.txt','Stop with image check','Exit');
23
if exist('Firstimagename')==0
24
[Firstimagename ImageFolder]=uigetfile('*.tif','Open First Image');
31
% Get the number of image name
32
letters=isletter(Firstimagename);
33
Pointposition=findstr(Firstimagename,'.');
34
Firstimagenamesize=size(Firstimagename);
35
counter=Pointposition-1;
39
letterstest=letters(counter);
43
Numberpos(counterpos)=counter;
45
counterpos=counterpos+1;
51
Filename_first = Firstimagename(1:min(Numberpos)-1);
52
Firstfilenumber=Firstimagename(min(Numberpos):max(Numberpos));
53
Lastname_first = Firstimagename(max(Numberpos)+1:Firstimagenamesize(1,2));
54
Firstfilenumbersize=size(Firstfilenumber);
55
onemore=10^(Firstfilenumbersize(1,2));
56
filenamelist(1,:)=Firstimagename;
60
Filelist=[Firstimagename;Firstimagename];
62
[grid_x,grid_y]=grid_generator(Firstimagename,ImageFolder);
63
[processingtime]=fpstestfunc(grid_x,grid_y,Filelist);
64
fpstest = menu(sprintf(['Processing the selected grid will allow ' , num2str(1/processingtime),' frames per second' ]),'Try again','Use the grid');
66
clear grid_x; clear grid_y;
71
Firstfilenumber=str2num(Firstfilenumber);
72
u=1+onemore+Firstfilenumber;
74
filenamelist(2,:)=[Filename_first ustr(2:Firstfilenumbersize(1,2)+1) Lastname_first];
79
input_points_x=grid_x;
80
input_points_y=grid_y;
83
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
84
numberofmarkers=max(size(grid_x))*min(size(grid_x));
85
validx(:,1)=reshape(grid_x,[],1);
86
displx=zeros(numberofmarkers,1);
87
validy(:,1)=reshape(grid_y,[],1);
88
disply=zeros(numberofmarkers,1);
91
while exist('end.txt','file') ==0;
94
if exist(filenamelist((counter+1),:),'file') ==2;
95
warning(['# Processed Images: ', num2str(numberofimages-1),'; # markers:',num2str(numberofmarkers), '; Processing Image: ',filenamelist(counter+1,:)]) % plot a title onto the image
97
input = mean(double(imread(filenamelist((counter+1),:))),3); % read in the image which has to be correlated
99
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
100
input_points_for(:,2)=reshape(input_points_y,[],1);
101
base_points_for(:,1)=reshape(base_points_x,[],1);
102
base_points_for(:,2)=reshape(base_points_y,[],1);
103
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
104
input_correl_x=input_correl(:,1); % the results we get from cpcorr for the x-direction
105
input_correl_y=input_correl(:,2); % the results we get from cpcorr for the y-direction
107
validx(:,counter+1)=input_correl_x; % lets save the data
108
savelinex=input_correl_x';
109
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 ;-)
111
validy(:,counter+1)=input_correl_y;
112
saveliney=input_correl_y';
113
dlmwrite('resultsimcorry.txt', saveliney , 'delimiter', '\t', '-append');
115
base_points_x=grid_x;
116
base_points_y=grid_y;
117
input_points_x=input_correl_x;
118
input_points_y=input_correl_y;
121
imshow(filenamelist(counter+1,:)) % update image
123
plot(grid_x,grid_y,'g+') % plot start position of raster
124
plot(input_correl_x,input_correl_y,'r+') % plot actual postition of raster
128
displx(:,counter+1)=validx(:,counter+1)-validx(:,1);
129
disply(:,counter+1)=validy(:,counter+1)-validy(:,1);
132
xdata=validx(:,counter+1);
133
ydata=displx(:,counter+1);
138
[x,resnormx,residual,exitflagx,output] = lsqcurvefit(@linearfit, [x(1) x(2)], xdata, ydata);
139
plot(xdata,ydata,'.');
141
ydatafit=x(1)*xdata+x(2);
142
plot(xdata,ydatafit,'r');
144
xlabel('x-pos [pixel]')
145
ylabel('x-displ [pixel]')
146
title('x displ. versus x pos. in [pixel]')
148
slopex(counter,:)=[i x(1) x(2)];
151
xdata=validy(:,counter+1);
152
ydata=disply(:,counter+1);
157
[y,resnormx,residual,exitflagx,output] = lsqcurvefit(@linearfit, [y(1) y(2)], xdata, ydata);
158
plot(xdata,ydata,'.g');
160
ydatafit=y(1)*xdata+y(2);
161
plot(xdata,ydatafit,'r');
163
xlabel('y-pos [pixel]')
164
ylabel('y-displ [pixel]')
165
title('y displ. versus y pos. in [pixel]')
167
slopey(counter,:)=[i y(1) y(2)];
170
plot(slopex(:,2),'-b')
172
plot(slopey(:,2),'-g')
174
xlabel('Image # [ ]')
175
ylabel('x- and y-strain [ ]')
176
title('Strain in x and y direction versus Image #')
182
filenamelist(counter+1,:)=[Filename_first ustr(2:Firstfilenumbersize(1,2)+1) Lastname_first];
183
[numberofmarkers numberofimages]=size(validx);
186
if exist(filenamelist((counter+1),:),'file') ==0;
187
save validx.dat validx -ascii -tabs
188
save validy.dat validy -ascii -tabs
189
warning('Last image detected, RTCorrCode stopped')
195
subplot(2,2,1),title(['# Processed Images: ', num2str(numberofimages-1),'; fps: ', num2str((numberofimages-1)/toc),'; # markers:',num2str(numberofmarkers), '; Waiting for Image: ',filenamelist(counter+1,:)]) % plot a title onto the image
200
save validx.dat validx -ascii -tabs
201
save validy.dat validy -ascii -tabs
202
msgboxwicon=msgbox('end.txt file detected, RTCorrCode stopped','Processing stopped!')
203
warning('end.txt file detected, RTCorrCode stopped')
206
%----------------------------------
209
function [processingtime]=fpstestfunc(grid_x,grid_y,filenamelist)
212
input_points_x=grid_x;
213
base_points_x=grid_x;
215
input_points_y=grid_y;
216
base_points_y=grid_y;
218
% [row,col]=size(base_points_x); % this will determine the number of rasterpoints we have to run through
219
% [r,c]=size(filenamelist); % this will determine the number of images we have to loop through
221
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
222
input = uint8(mean(double(imread(filenamelist(2,:))),3)); % read in the image which has to be correlated
224
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
225
input_points_for(:,2)=reshape(input_points_y,[],1);
226
base_points_for(:,1)=reshape(base_points_x,[],1);
227
base_points_for(:,2)=reshape(base_points_y,[],1);
228
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
229
input_correl_x=input_correl(:,1); % the results we get from cpcorr for the x-direction
230
input_correl_y=input_correl(:,2); % the results we get from cpcorr for the y-direction
b'\\ No newline at end of file'