3
% updated last 9/8/2010
4
% this function allows to track multiple peaks along one axis. The
5
% resolution can be much higher than the cross correlation methods of
6
% digital image correlation.
9
function [validx,validy]=multipeak_tracking;
11
%% Load image and ask for orientation and pos/neg
13
if exist('filenamelist')==0
14
load('filenamelist') % file with the list of filenames to be processed
17
filenumber=size(filenamelist);
18
filenumber=filenumber(1);
21
imshow(filenamelist(1,:)) % show the first image
22
title('First Image') % put a title
24
ImageA=(uint8(mean(double(imread(filenamelist(1,:))),3)));
26
sel_pos_neg = menu(sprintf('Do you want use the negative image for analysis?'),...
27
'As is', 'Negativ', 'Cancel')
34
imshow(ImageA) % show the first image
41
sel_horz_vert = menu(sprintf('Do you want to measure horizontal or vertical?'),...
42
'Horizontal', 'Vertical', 'Cancel')
49
imshow(ImageA) % show the first image
56
[imr,imc]=size(ImageA);
59
%% select path for displacement extraction along markers
60
%Select point in middle of marker
61
xlabel('Location On Image [Pixels]')
62
ylabel('Location On Image [Pixels]')
63
title(['Click on the center of the sample. Width: ', num2str(imc),...
64
'; Height: ',num2str(imr)])
65
marker_pt=round(ginput(1));
66
x_mark = marker_pt(1);
67
y_mark = marker_pt(2);
69
line([1 imc],[y_mark y_mark],'Color','r')
72
%Prompt for integration width
73
prompt = {'Enter integration width [Pixels]:'};
74
dlg_title = 'Input integration width for the analysis';
77
answer = inputdlg(prompt,dlg_title,num_lines,def);
78
int_width = str2num(cell2mat(answer(1)));
80
line([1 imc],[y_mark-int_width/2 y_mark-int_width/2],'Color','g')
81
line([1 imc],[y_mark+int_width/2 y_mark+int_width/2],'Color','g')
84
%% Calculate line profile data and select peaks
86
ydata= sum(ImageA((y_mark-int_width/2):(y_mark+int_width/2),:),1)/int_width;
90
xlabel('Location On Image [Pixels]')
91
ylabel('Pixel Intensity Value')
93
sel_peakselect = menu(sprintf('Do you want to select single or all peaks?')...
94
,'Single Select', 'All Select', 'Cancel')
100
% If single peaks should be chosen
105
while sel_peakselect_2==1
106
title('Click on the left of the chosen peak.')
107
marker_pt=round(ginput(1));
108
x_peak_left = marker_pt(1);
109
y_peak_left = marker_pt(2);
110
line([x_peak_left x_peak_left], [1 max(ydata)],'Color','r')
112
title('Click on the right of the chosen peak.')
113
marker_pt=round(ginput(1));
114
x_peak_right = marker_pt(1);
115
y_peak_right = marker_pt(2);
116
line([x_peak_right x_peak_right], [1 max(ydata)],'Color','r')
118
plot(xdata(x_peak_left:x_peak_right),ydata(x_peak_left:x_peak_right),'k')
119
peak_pos(i,:)=[x_peak_left x_peak_right];
122
sel_peakselect_2 = menu(sprintf('Do you want to select another peak?')...
123
,'One more', 'No, lets process')
127
% If all peaks should be found automatically
132
%% Start first fitting
133
fitcountertemp=size(peak_pos); % number off peaks to cycle through
134
fitcounter=fitcountertemp(1,1); % number off peaks to cycle through
136
for c=1:fitcounter %start the loop to process all points
137
fitdatax=xdata(peak_pos(c,1):peak_pos(c,2));
138
fitdatay=ydata(peak_pos(c,1):peak_pos(c,2));
140
% fitting in x-direction
141
% guess some parameters for the fitting routine --> bad guesses lead to
142
% an error message which stops the fitting
144
back_guess=(ydata(peak_pos(c,2))+ydata(peak_pos(c,2)))/2; % guess for the background level - average of the first and last greyvalue
145
sig1_guess=(peak_pos(c,2)-peak_pos(c,1))/2; % guess for the peak width - take half of the cropping width
146
amp_guess1=max(fitdatay); % guess for the amplitude - take the greyvalue at the peak position
147
mu1_guess=(peak_pos(c,2)+peak_pos(c,1))/2; % guess for the position of the peak - take the position from bwlabel
149
% start fitting routine
150
[x,resnormx,residual,exitflagx,output] = lsqcurvefit(@gauss_onepk, [amp_guess1 mu1_guess sig1_guess back_guess], fitdatax, fitdatay); %give the initial guesses and data to the gauss fitting routine
152
% show the fitting results
153
xtest = fitdatax; % x values for the plot of the fitting result
154
ytest = (x(1)*exp((-(xtest-x(2)).^2)./(2.*x(3).^2))) + x(4); % y values of the fitting result
155
yguess=(amp_guess1*exp((-(xtest-mu1_guess).^2)./(2.*sig1_guess.^2))) + back_guess; %y values for the guess plot
156
plot(xtest,ytest,'r') % plot the fitted function
157
plot(xtest,yguess,'b') % plot the guessed function
163
sel_go = menu(sprintf('Do you want proceed?')...
164
,'Do it!', 'No, stop!')
171
cutout=peak_pos(:,2)-peak_pos(:,1)
173
for m=1:(filenumber-1) % loop through all images
174
ImageA=((mean(double(imread(filenamelist(m,:))),3)));
178
imshow(ImageA) % show the first image
183
imshow(ImageA) % show the first image
190
ydata= sum(ImageA((y_mark-int_width/2):(y_mark+int_width/2),:),1)/int_width;
193
title(['Image Number: ', num2str(m)])
197
for c=1:fitcounter %start the loop to process all points
199
if (peaks(c,m,2)+cutout(c)/2)>imc
200
fitdatax=xdata((imc-cutout(c)):imc);
201
fitdatay=ydata((imc-cutout(c)):imc);
203
fitdatax=xdata((peaks(c,m,2)-cutout(c)/2):(peaks(c,m,2)+cutout(c)/2));
204
fitdatay=ydata((peaks(c,m,2)-cutout(c)/2):(peaks(c,m,2)+cutout(c)/2));
207
% fitting in x-direction
208
% guess some parameters for the fitting routine --> bad guesses lead to
209
% an error message which stops the fitting
211
back_guess=peaks(c,m,4); % guess for the background level - average of the first and last greyvalue
212
sig1_guess=peaks(c,m,3); % guess for the peak width - take half of the cropping width
213
amp_guess1=peaks(c,m,1); % guess for the amplitude - take the greyvalue at the peak position
214
mu1_guess=peaks(c,m,2); % guess for the position of the peak - take the position from bwlabel
216
% start fitting routine
217
[x,resnormx,residual,exitflagx,output] = lsqcurvefit(@gauss_onepk, [amp_guess1 mu1_guess sig1_guess back_guess], fitdatax, fitdatay); %give the initial guesses and data to the gauss fitting routine
218
% show the fitting results
219
xtest = fitdatax; % x values for the plot of the fitting result
220
ytest = (x(1)*exp((-(xtest-x(2)).^2)./(2.*x(3).^2))) + x(4); % y values of the fitting result
221
yguess=(amp_guess1*exp((-(xtest-mu1_guess).^2)./(2.*sig1_guess.^2))) + back_guess; %y values for the guess plot
222
plot(xtest,ytest,'r') % plot the fitted function
223
plot(xtest,yguess,'g') % plot the guessed function
228
Amplitude=peaks(:,m,1)';
229
Peakposition=peaks(:,m,2)';
230
Peakwidth=peaks(:,m,3)';
231
Background=peaks(:,m,4)';
232
dlmwrite('backupPeakposition.txt', Peakposition' , '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 ;-)
233
dlmwrite('backupAmplitude.txt', Amplitude' , '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 ;-)
234
dlmwrite('backupPeakwidth.txt', Peakwidth' , '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 ;-)
235
dlmwrite('backupBackground.txt', Background' , '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 ;-)
242
Amplitude=peaks(:,:,1)';
243
Peakposition=peaks(:,:,2)';
244
Peakwidth=peaks(:,:,3)';
245
Background=peaks(:,:,4)';
248
save Amplitude.dat Amplitude -ascii -tabs;
249
save Peakposition.dat Peakposition -ascii -tabs;
250
save Peakwidth.dat Peakwidth -ascii -tabs;
251
save Background.dat Background -ascii -tabs;
252
save validx_mp.dat validx -ascii -tabs;
253
save validy_mp.dat validy -ascii -tabs;
b'\\ No newline at end of file'