1
%% This function calculates the local resolved strain in the horizontal or
2
% x-direction. It is recommended to run displacement.m first to clean up
3
% your validx.dat and validy.dat. local_displacement.m allows you to
4
% define e.g. 20 regions along x where the function calculates the gradient
5
% (strainx) and plots it for each image. The gradientx e.g. contains the
6
% strainx in the columns for each image in rows.
8
function [marker_displacementx marker_displacementy gradientx gradienty]=...
9
local_strainx(validx, validy)
12
[validx,Pathvalidx] = uigetfile('*.dat','Open validx.dat');
14
validx=importdata(validx,'\t');
17
[validy,Pathvalidy] = uigetfile('*.dat','Open validy.dat');
19
validy=importdata(validy,'\t');
22
sizevalidx=size(validx);
23
sizevalidy=size(validy);
24
looppoints=sizevalidx(1,1);
25
loopimages=sizevalidx(1,2);
27
displacementx=(mean(validx(:,1))-mean(validx));
28
displacementy=(mean(validy(:,1))-mean(validy));
31
prompt = {'From which image do you want to select markers?'};
32
dlg_title = 'Marker selection';
35
def = {num2str(defaultimage)};
36
answer = inputdlg(prompt,dlg_title,num_lines,def);
37
selectedimage = str2num(cell2mat(answer(1,1)));
38
if selectedimage>loopimages
39
selectedimage=loopimages;
47
plot(validx(:,selectedimage),validy(:,selectedimage),'+b');
48
title(sprintf('Define the region of interest. Pick (single click) a point in the LOWER LEFT region of the gage section.\n Do the same for a point in the UPPER RIGHT portion of the gage section.'))
50
[x(1,1),y(1,1)]=ginput(1);
51
plot(x(1,1),y(1,1),'+b')
52
plot([min(validx(:,selectedimage)); max(validx(:,selectedimage))], [y(1,1); y(1,1)],'-r')
53
plot([x(1,1),x(1,1)], [min(validy(:,selectedimage)),max(validy(:,selectedimage))],'-r')
55
[x(2,1),y(2,1)]=ginput(1);
57
plot(x(2,1),y(2,1),'+b')
58
plot([min(validx(:,selectedimage)); max(validx(:,selectedimage))], [y(2,1); y(2,1)],'-r')
59
plot([x(2,1),x(2,1)], [min(validy(:,selectedimage)),max(validy(:,selectedimage))],'-r')
66
lowerline=[xmin ymin; xmax ymin];
67
upperline=[xmin ymax; xmax ymax];
68
leftline=[xmin ymin; xmin ymax];
69
rightline=[xmax ymin; xmax ymax];
71
plot(lowerline(:,1),lowerline(:,2),'-g')
72
plot(upperline(:,1),upperline(:,2),'-g')
73
plot(leftline(:,1),leftline(:,2),'-g')
74
plot(rightline(:,1),rightline(:,2),'-g')
76
selectpoints=find(validx(:,selectedimage)>min(x) & validx(:,selectedimage)<max(x) & validy(:,selectedimage)<max(y) & validy(:,selectedimage)>min(y));
78
validx_new=validx(selectpoints,:);
79
validy_new=validy(selectpoints,:);
83
plot(validx_new(:,selectedimage),validy_new(:,selectedimage),'+g')
84
title(sprintf('Red dots represent your new raster.'))
89
% ---------------------------------
90
gridselection1 = menu(sprintf('Do you want to use the green highlighted markers?'),...
97
%% here you can input into how many areas you would like the strain to be
100
prompt = {'Into how many areas do you want to split the markers?'};
101
dlg_title = 'Divide markers';
104
def = {num2str(defaultsplit)};
105
answer = inputdlg(prompt,dlg_title,num_lines,def);
106
selectesplit = str2num(cell2mat(answer(1,1)));
112
clear marker_displacement
119
posx(i)=xmin+((xmax-xmin)/selectesplit)*i;
120
plot([posx(i);posx(i)], [ymin; ymax],'-m')
121
selectmarkers=find(validx_new(:,selectedimage)>(xmin+((xmax-xmin)/selectesplit)*(i-1)) & validx_new(:,selectedimage)<(xmin+((xmax-xmin)/selectesplit)*(i)));
122
validx_plot=validx_new(selectmarkers,:);
123
validy_plot=validy_new(selectmarkers,:);
124
plot(validx_plot(:,selectedimage),validy_plot(:,selectedimage),'+r')
127
validy_local=validy_plot;
128
marker_displacementy(:,i)=mean(validy_local)';
130
validx_local=validx_plot;
131
marker_displacementx(:,i)=mean(validx_local)';
132
plot(validx_local(:,selectedimage),validy_local(:,selectedimage),'xg')
141
save marker_displacementx.txt marker_displacementx -ASCII
142
save marker_displacementy.txt marker_displacementy -ASCII
144
sizemvalidx=size(marker_displacementx);
147
mvalidxfirst=ones(sizemvalidx(1,1),1)*marker_displacementx(1,:);
148
mdisplx=marker_displacementx-mvalidxfirst;
149
mvalidyfirst=ones(sizemvalidx(1,1),1)*marker_displacementy(1,:);
150
mdisply=marker_displacementy-mvalidyfirst;
154
grad_mdisplx=gradient(mdisplx);
155
grad_mdisply=gradient(mdisply);
157
grad_marker_displacementx=gradient(marker_displacementx);
158
grad_marker_displacementy=gradient(marker_displacementy);
160
gradientx=grad_mdisplx./grad_marker_displacementx;
161
gradienty=grad_mdisply./grad_marker_displacementy;
163
save gradientx.txt gradientx -ASCII
164
save gradienty.txt gradienty -ASCII
166
%% Here you can let the function plot the displacement
168
checkdisplacement = menu(sprintf('Do you want to check the displacement x?'),...
171
if checkdisplacement==1
174
minmeanx=min(min(marker_displacementx));
175
maxmeanx=max(max(marker_displacementx));
176
minmdisplx=min(min(mdisplx));
177
maxmdisplx=max(max(mdisplx));
181
plot(marker_displacementx(i,:),mdisplx(i,:),'.r')
182
title(['Displacement',sprintf(' (Current image #: %1g)',i)])
183
axis([minmeanx maxmeanx minmdisplx maxmdisplx])
189
%% Here, you can let the function plot the strainx
190
checkdisplacement = menu(sprintf('Do you want to check the local strain x?'),...
192
videoselection = menu(sprintf('Do you want to create a video?'),'Yes','No');
195
mkdir('video_local_strain')
196
cd('video_local_strain');
199
if checkdisplacement==1
200
minmeanx=min(min(marker_displacementx));
201
maxmeanx=max(max(marker_displacementx));
202
min_marker_gradx=min(min(gradientx));
203
max_marker_gradx=max(max(gradientx));
206
plot(marker_displacementx(i,:),gradientx(i,:),'.-b')
207
title(['Gradient of Displacement',sprintf(' (Current image #: %1g)',i)])
208
axis([minmeanx maxmeanx min_marker_gradx max_marker_gradx])
209
xlabel('Position in Pixel [ ]')
210
ylabel('Local Displacement Gradient [ ]')
216
videoname=[Vid ustr '.jpg'];
217
saveas(h,videoname,'jpg');