bzr branch
http://suren.me/webbzr/normxcorr/trunk
1
by Suren A. Chilingaryan
Initial import |
1 |
function [validx,validy]=strain_lineprofile_marker; |
2 |
||
3 |
%Code to use ISDG markers for 1-D Matlab DIC strain measurement
|
|
4 |
%Programmed by Dan and Rob
|
|
5 |
%Changed by Chris
|
|
6 |
%Last revision: 3. February 2008
|
|
7 |
||
8 |
||
9 |
%Load the filenames to analyze
|
|
10 |
load('filenamelist') |
|
11 |
[r,c]=size(filenamelist); |
|
12 |
||
13 |
%Open base image
|
|
14 |
[FileNameBase,PathNameBase] = uigetfile( ... |
|
15 |
{'*.bmp;*.tif;*.jpg;*.TIF;*.BMP;*.JPG','Image files (*.bmp,*.tif,*.jpg)';'*.*', 'All Files (*.*)'}, ... |
|
16 |
'Open base image for marker selection (color image best)'); |
|
17 |
cd(PathNameBase); |
|
18 |
im_base = imread(FileNameBase); |
|
19 |
im_basetemp=mean(double(im_base),3); |
|
20 |
im_base=im_basetemp; |
|
21 |
||
22 |
maxcolor=max(max(im_base)); |
|
23 |
mincolor=min(min(im_base)); |
|
24 |
caxis([mincolor maxcolor]); |
|
25 |
imagesc(im_base); |
|
26 |
||
27 |
[imr,imc]=size(im_base); |
|
28 |
||
29 |
%Select point in middle of marker
|
|
30 |
xlabel('Location On Image [Pixels]') |
|
31 |
ylabel('Location On Image [Pixels]') |
|
32 |
title(sprintf('Click on the center of one marker.')) |
|
33 |
marker_pt=round(ginput(1)); |
|
34 |
x_mark = marker_pt(1); |
|
35 |
y_mark = marker_pt(2); |
|
36 |
||
37 |
%Prompt for integration width
|
|
38 |
prompt = {'Enter integration width [Pixels]:'}; |
|
39 |
dlg_title = 'Input integration width for the analysis'; |
|
40 |
num_lines= 1; |
|
41 |
def = {'40'}; |
|
42 |
answer = inputdlg(prompt,dlg_title,num_lines,def); |
|
43 |
int_width = str2num(cell2mat(answer(1))); |
|
44 |
||
45 |
%Calculate line profile data
|
|
46 |
xdata = [1:1:imc]; |
|
47 |
ydata= sum(im_base((y_mark-int_width/2):(y_mark+int_width/2),:),1)/int_width; |
|
48 |
||
49 |
h=figure; |
|
50 |
set(h,'Position',[150,50,800,600]) |
|
51 |
plot(xdata,ydata) |
|
52 |
xlabel('Location On Image [Pixels]') |
|
53 |
ylabel('Pixel Intensity Value') |
|
54 |
title(sprintf('First, single click at the base and middle of the LEFT PEAK (vertically even with the flat data).\n Then, single click on the max point of the RIGHT PEAK.')) |
|
55 |
[xprof, yprof]=ginput(2); |
|
56 |
mu1_guess = xprof(1,1); |
|
57 |
mu2_guess = xprof(2,1); |
|
58 |
back_guess = yprof(1,1); |
|
59 |
amp_guess1 = yprof(2,1); |
|
60 |
amp_guess2 = yprof(2,1); |
|
61 |
sig1_guess = 3; |
|
62 |
sig2_guess = 3; |
|
63 |
||
64 |
%Save figure
|
|
65 |
saveas(h,'center_select.fig') |
|
66 |
||
67 |
%Close all open images
|
|
68 |
close all |
|
69 |
||
70 |
%Initialize status bar and figure
|
|
71 |
k=figure; |
|
72 |
g=waitbar(0,'Processing the images...'); |
|
73 |
set(g,'Position',[275,50,275,50]) %[left bottom width height] |
|
74 |
% results_prof = zeros(r,2);
|
|
75 |
tic; |
|
76 |
% peaklength=40;
|
|
77 |
validx=zeros(2,r); |
|
78 |
validy=zeros(2,r); |
|
79 |
||
80 |
for i=1:(r-1) |
|
81 |
||
82 |
waitbar(i/(r-1)); |
|
83 |
||
84 |
%Read in images from filenamelist
|
|
85 |
im_input = mean(double(imread(filenamelist(i,:))),3); |
|
86 |
||
87 |
%Generate greyscale data (y-values)
|
|
88 |
ydata= sum(im_input((int8(y_mark-int_width/2)):(int8(y_mark+int_width/2)),:),1)/int_width; |
|
89 |
warning off all |
|
90 |
||
91 |
%Fit gaussian function to peaks
|
|
92 |
[x,resnorm,residual,exitflag,output] = lsqcurvefit(@gauss_twopk, [amp_guess1 mu1_guess sig1_guess amp_guess2 mu2_guess sig2_guess back_guess], xdata, ydata); |
|
93 |
||
94 |
%plot fit and data
|
|
95 |
xtest = [0:0.1:imc]; |
|
96 |
ytest = (x(1)*exp((-(xtest-x(2)).^2)./(2.*x(3).^2))) + (x(4)*exp((-(xtest-x(5)).^2)./(2.*x(6).^2))) + x(7); |
|
97 |
plot(xdata,ydata,'.') |
|
98 |
axis([0 imc 0 (max(ydata)*1.1)]) |
|
99 |
xlabel('Location On Image [Pixels]') |
|
100 |
ylabel('Pixel Intensity Value') |
|
101 |
title('Pixel Intensity Value Fit vs. Location On Image') |
|
102 |
hold on; |
|
103 |
plot(xtest,ytest,'r') |
|
104 |
hold off; |
|
105 |
||
106 |
%Write results to matrix
|
|
107 |
results_prof(i+1,1) = x(2); |
|
108 |
results_prof(i+1,2) = x(5); |
|
109 |
results_prof(1,1) = results_prof(2,1); |
|
110 |
results_prof(1,2) = results_prof(2,2); |
|
111 |
||
112 |
validx(:,i)=[x(2) x(5)]; |
|
113 |
validy(:,i)=[y_mark y_mark]; |
|
114 |
||
115 |
%Update guesses
|
|
116 |
amp_guess1 = x(1); mu1_guess = x(2); sig1_guess = x(3); amp_guess2 = x(4); mu2_guess = x(5); sig2_guess = x(6); back_guess = x(7); |
|
117 |
||
118 |
end
|
|
119 |
toc
|
|
120 |
close(g) |
|
121 |
||
122 |
%Save figure
|
|
123 |
saveas(k,'peak_fit.fig') |
|
124 |
||
125 |
%Save locations of two peaks for all images and save integration width
|
|
126 |
save raw_peak_results.dat results_prof -ascii -tabs |
|
127 |
save int_width_y_mark.dat int_width y_mark -ascii -tabs |
|
128 |
save validx_line_profile.dat validx -ascii -tabs |
|
129 |
save validy_line_profile.dat validy -ascii -tabs |
|
130 |
||
131 |
line_visual(filenamelist,results_prof,[int_width; y_mark]); |