bzr branch
http://darksoft.org/webbzr/normxcorr/trunk
41
by Suren A. Chilingaryan
Synchronize with Chris version, set precision to 1, initial implementation of labview wrapper |
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.
|
|
7 |
||
8 |
function [marker_displacementx marker_displacementy gradientx gradienty]=... |
|
9 |
local_strainx(validx, validy) |
|
10 |
||
11 |
if exist('validx')==0 |
|
12 |
[validx,Pathvalidx] = uigetfile('*.dat','Open validx.dat'); |
|
13 |
cd(Pathvalidx); |
|
14 |
validx=importdata(validx,'\t'); |
|
15 |
end
|
|
16 |
if exist('validy')==0 |
|
17 |
[validy,Pathvalidy] = uigetfile('*.dat','Open validy.dat'); |
|
18 |
cd(Pathvalidy); |
|
19 |
validy=importdata(validy,'\t'); |
|
20 |
end
|
|
21 |
||
22 |
sizevalidx=size(validx); |
|
23 |
sizevalidy=size(validy); |
|
24 |
looppoints=sizevalidx(1,1); |
|
25 |
loopimages=sizevalidx(1,2); |
|
26 |
||
27 |
displacementx=(mean(validx(:,1))-mean(validx)); |
|
28 |
displacementy=(mean(validy(:,1))-mean(validy)); |
|
29 |
||
30 |
||
31 |
prompt = {'From which image do you want to select markers?'}; |
|
32 |
dlg_title = 'Marker selection'; |
|
33 |
num_lines= 1; |
|
34 |
defaultimage=1; |
|
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; |
|
40 |
end
|
|
41 |
if selectedimage<1 |
|
42 |
selectedimage=1; |
|
43 |
end
|
|
44 |
||
45 |
h=figure; |
|
46 |
||
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.')) |
|
49 |
hold on |
|
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') |
|
54 |
||
55 |
[x(2,1),y(2,1)]=ginput(1); |
|
56 |
hold on |
|
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') |
|
60 |
||
61 |
xmin = min(x); |
|
62 |
xmax = max(x); |
|
63 |
ymin = min(y); |
|
64 |
ymax = max(y); |
|
65 |
||
66 |
lowerline=[xmin ymin; xmax ymin]; |
|
67 |
upperline=[xmin ymax; xmax ymax]; |
|
68 |
leftline=[xmin ymin; xmin ymax]; |
|
69 |
rightline=[xmax ymin; xmax ymax]; |
|
70 |
||
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') |
|
75 |
||
76 |
selectpoints=find(validx(:,selectedimage)>min(x) & validx(:,selectedimage)<max(x) & validy(:,selectedimage)<max(y) & validy(:,selectedimage)>min(y)); |
|
77 |
||
78 |
validx_new=validx(selectpoints,:); |
|
79 |
validy_new=validy(selectpoints,:); |
|
80 |
||
81 |
hold on |
|
82 |
||
83 |
plot(validx_new(:,selectedimage),validy_new(:,selectedimage),'+g') |
|
84 |
title(sprintf('Red dots represent your new raster.')) |
|
85 |
hold off |
|
86 |
drawnow
|
|
87 |
||
88 |
||
89 |
% --------------------------------- |
|
90 |
gridselection1 = menu(sprintf('Do you want to use the green highlighted markers?'),... |
|
91 |
'Yes','No'); |
|
92 |
||
93 |
if gridselection1==2 |
|
94 |
return
|
|
95 |
end
|
|
96 |
||
97 |
%% here you can input into how many areas you would like the strain to be
|
|
98 |
% split up
|
|
99 |
||
100 |
prompt = {'Into how many areas do you want to split the markers?'}; |
|
101 |
dlg_title = 'Divide markers'; |
|
102 |
num_lines= 1; |
|
103 |
defaultsplit=10; |
|
104 |
def = {num2str(defaultsplit)}; |
|
105 |
answer = inputdlg(prompt,dlg_title,num_lines,def); |
|
106 |
selectesplit = str2num(cell2mat(answer(1,1))); |
|
107 |
||
108 |
||
109 |
if selectesplit<1 |
|
110 |
selectesplit=20; |
|
111 |
end
|
|
112 |
clear marker_displacement |
|
113 |
||
114 |
hold on |
|
115 |
for i=1:selectesplit |
|
116 |
clear validx_plot |
|
117 |
clear validy_plot |
|
118 |
clear selectmarkers |
|
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') |
|
125 |
drawnow
|
|
126 |
clear validy_local |
|
127 |
validy_local=validy_plot; |
|
128 |
marker_displacementy(:,i)=mean(validy_local)'; |
|
129 |
clear validx_local |
|
130 |
validx_local=validx_plot; |
|
131 |
marker_displacementx(:,i)=mean(validx_local)'; |
|
132 |
plot(validx_local(:,selectedimage),validy_local(:,selectedimage),'xg') |
|
133 |
drawnow
|
|
134 |
drawnow
|
|
135 |
end
|
|
136 |
||
137 |
hold off |
|
138 |
||
139 |
%% save everything
|
|
140 |
||
141 |
save marker_displacementx.txt marker_displacementx -ASCII |
|
142 |
save marker_displacementy.txt marker_displacementy -ASCII |
|
143 |
||
144 |
sizemvalidx=size(marker_displacementx); |
|
145 |
clear mdisplx; |
|
146 |
clear mdisply; |
|
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; |
|
151 |
clear mvalidxfirst |
|
152 |
clear mvalidyfirst |
|
153 |
||
154 |
grad_mdisplx=gradient(mdisplx); |
|
155 |
grad_mdisply=gradient(mdisply); |
|
156 |
||
157 |
grad_marker_displacementx=gradient(marker_displacementx); |
|
158 |
grad_marker_displacementy=gradient(marker_displacementy); |
|
159 |
||
160 |
gradientx=grad_mdisplx./grad_marker_displacementx; |
|
161 |
gradienty=grad_mdisply./grad_marker_displacementy; |
|
162 |
||
163 |
save gradientx.txt gradientx -ASCII |
|
164 |
save gradienty.txt gradienty -ASCII |
|
165 |
||
166 |
%% Here you can let the function plot the displacement
|
|
167 |
||
168 |
checkdisplacement = menu(sprintf('Do you want to check the displacement x?'),... |
|
169 |
'Yes','No'); |
|
170 |
||
171 |
if checkdisplacement==1 |
|
172 |
||
173 |
||
174 |
minmeanx=min(min(marker_displacementx)); |
|
175 |
maxmeanx=max(max(marker_displacementx)); |
|
176 |
minmdisplx=min(min(mdisplx)); |
|
177 |
maxmdisplx=max(max(mdisplx)); |
|
178 |
||
179 |
figure
|
|
180 |
for i=1:loopimages |
|
181 |
plot(marker_displacementx(i,:),mdisplx(i,:),'.r') |
|
182 |
title(['Displacement',sprintf(' (Current image #: %1g)',i)]) |
|
183 |
axis([minmeanx maxmeanx minmdisplx maxmdisplx]) |
|
184 |
drawnow
|
|
185 |
end
|
|
186 |
end
|
|
187 |
||
188 |
||
189 |
%% Here, you can let the function plot the strainx
|
|
190 |
checkdisplacement = menu(sprintf('Do you want to check the local strain x?'),... |
|
191 |
'Yes','No'); |
|
192 |
videoselection = menu(sprintf('Do you want to create a video?'),'Yes','No'); |
|
193 |
if videoselection==1 |
|
194 |
close all |
|
195 |
mkdir('video_local_strain') |
|
196 |
cd('video_local_strain'); |
|
197 |
Vid='Vid'; |
|
198 |
end
|
|
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)); |
|
204 |
H=figure; |
|
205 |
for i=1:loopimages |
|
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 [ ]') |
|
211 |
drawnow
|
|
212 |
||
213 |
if videoselection==1 |
|
214 |
u=i+10000; |
|
215 |
ustr=num2str(u); |
|
216 |
videoname=[Vid ustr '.jpg']; |
|
217 |
saveas(h,videoname,'jpg'); |
|
218 |
end
|
|
219 |
% pause(0.1) |
|
220 |
end
|
|
221 |
if videoselection==1 |
|
222 |
cd('..') |
|
223 |
end
|
|
224 |
end
|
|
225 |