├── Matlab Code ├── 2D_stack01.mat ├── DIC_simulator.fig └── DIC_simulator.m └── README.md /Matlab Code/2D_stack01.mat: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FranckLab/DIC-Simulator/44509bc70d76e581f86d7ca3be09d104490e2ab7/Matlab Code/2D_stack01.mat -------------------------------------------------------------------------------- /Matlab Code/DIC_simulator.fig: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FranckLab/DIC-Simulator/44509bc70d76e581f86d7ca3be09d104490e2ab7/Matlab Code/DIC_simulator.fig -------------------------------------------------------------------------------- /Matlab Code/DIC_simulator.m: -------------------------------------------------------------------------------- 1 | function varargout = DIC_simulator(varargin) 2 | %This program is intended to evaluate the quality of a given DIC image by 3 | %using simulated deformation fields and analyzing the computed 4 | %displacements given the known deformations and speckles of the 5 | %particular-user loaded image 6 | %This program was developed by C. Franck (Brown University), 02/2012 7 | % DIC_SIMULATOR M-file for DIC_simulator.fig 8 | % DIC_SIMULATOR, by itself, creates a new DIC_SIMULATOR or raises the existing 9 | % singleton*. 10 | % 11 | % H = DIC_SIMULATOR returns the handle to a new DIC_SIMULATOR or the handle to 12 | % the existing singleton*. 13 | % 14 | % DIC_SIMULATOR('CALLBACK',hObject,eventData,handles,...) calls the local 15 | % function named CALLBACK in DIC_SIMULATOR.M with the given input arguments. 16 | % 17 | % DIC_SIMULATOR('Property','Value',...) creates a new DIC_SIMULATOR or raises the 18 | % existing singleton*. Starting from the left, property value pairs are 19 | % applied to the GUI before DIC_simulator_OpeningFcn gets called. An 20 | % unrecognized property name or invalid value makes property application 21 | % stop. All inputs are passed to DIC_simulator_OpeningFcn via varargin. 22 | % 23 | % *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one 24 | % instance to run (singleton)". 25 | % 26 | % See also: GUIDE, GUIDATA, GUIHANDLES 27 | 28 | % Edit the above text to modify the response to help DIC_simulator 29 | 30 | % Last Modified by GUIDE v2.5 16-Sep-2015 16:39:40 31 | 32 | % Begin initialization code - DO NOT EDIT 33 | gui_Singleton = 1; 34 | gui_State = struct('gui_Name', mfilename, ... 35 | 'gui_Singleton', gui_Singleton, ... 36 | 'gui_OpeningFcn', @DIC_simulator_OpeningFcn, ... 37 | 'gui_OutputFcn', @DIC_simulator_OutputFcn, ... 38 | 'gui_LayoutFcn', [] , ... 39 | 'gui_Callback', []); 40 | if nargin && ischar(varargin{1}) 41 | gui_State.gui_Callback = str2func(varargin{1}); 42 | end 43 | 44 | if nargout 45 | [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); 46 | else 47 | gui_mainfcn(gui_State, varargin{:}); 48 | end 49 | % End initialization code - DO NOT EDIT 50 | 51 | function cmap = CMRmap(M) 52 | % REFERENCE 53 | % 54 | % [1] Rappaport, C. 2002: "A Color Map for Effective 55 | % Black-and-White Rendering of Color Scale Images", IEEE 56 | % Antenna's and Propagation Magazine, Vol.44, No.3, 57 | % pp.94-96 (June). 58 | % 59 | % See also GRAY. 60 | % !--- 61 | % ========================================================== 62 | % Last changed: $Date: 2012-12-20 14:18:42 +0000 (Thu, 20 Dec 2012) $ 63 | % Last committed: $Revision: 232 $ 64 | % Last changed by: $Author: ch0022 $ 65 | % ========================================================== 66 | % !--- 67 | 68 | % default colormap size 69 | if nargin < 1, M = size(get(gcf,'colormap'),1); end 70 | 71 | % reference colour map 72 | % adapted from article to produce more linear luminance 73 | CMRref=... 74 | [0 0 0; 75 | 0.1 0.1 0.35; 76 | 0.3 0.15 0.65; 77 | 0.6 0.2 0.50; 78 | 1 0.25 0.15; 79 | 0.9 0.55 0; 80 | 0.9 0.75 0.1; 81 | 0.9 0.9 0.5; 82 | 1 1 1]; 83 | 84 | % Interpolate colormap to colormap size 85 | cmap = zeros(M,3); 86 | for c = 1:3 87 | cmap(:,c) = interp1((1:9)',CMRref(:,c),linspace(1,9,M)','spline'); 88 | end 89 | 90 | % Limit to range [0,1] 91 | cmap = cmap-min(cmap(:)); 92 | cmap = cmap./max(cmap(:)); 93 | 94 | % --- Executes just before DIC_simulator is made visible. 95 | function DIC_simulator_OpeningFcn(hObject, eventdata, handles, varargin) 96 | % This function has no output args, see OutputFcn. 97 | % hObject handle to figure 98 | % eventdata reserved - to be defined in a future version of MATLAB 99 | % handles structure with handles and user data (see GUIDATA) 100 | % varargin command line arguments to DIC_simulator (see VARARGIN) 101 | 102 | % Choose default command line output for DIC_simulator 103 | handles.output = hObject; 104 | 105 | % define everything here 106 | %handles.input = varargin{1}; %this is the first input into the function 107 | %handles.input2 = varargin{2}; 108 | % [x,y] = meshgrid(1:32:512,1:32:512); 109 | % handles.x = x; 110 | % handles.y = y; 111 | % handles.displ = 0.1*x - 0.05*y; 112 | % handles.u = 0.1*x; 113 | % handles.v = -0.05*y; 114 | % 115 | % 116 | handles.dicw = 64; 117 | handles.dicd = 16; 118 | handles.trans = 7; 119 | handles.epp = 0.02; 120 | 121 | 122 | % Update handles structure 123 | guidata(hObject, handles); 124 | 125 | % UIWAIT makes DIC_simulator wait for user response (see UIRESUME) 126 | % uiwait(handles.figure1); 127 | 128 | % --- Outputs from this function are returned to the command line. 129 | function varargout = DIC_simulator_OutputFcn(hObject, eventdata, handles) 130 | % varargout cell array for returning output args (see VARARGOUT); 131 | % hObject handle to figure 132 | % eventdata reserved - to be defined in a future version of MATLAB 133 | % handles structure with handles and user data (see GUIDATA) 134 | 135 | % Get default command line output from handles structure 136 | varargout{1} = handles.output; 137 | 138 | 139 | % --- Executes on button press in loadimage. 140 | function loadimage_Callback(hObject, ~, handles) 141 | % hObject handle to loadimage (see GCBO) 142 | % eventdata reserved - to be defined in a future version of MATLAB 143 | % handles structure with handles and user data (see GUIDATA) 144 | [filename, pathname] = uigetfile({'*.tif';'*.png';'*.mat';'*.jpg'},'Select your DIC Image') 145 | % if isequal(filename,0) 146 | % disp('User selected Cancel') 147 | % else 148 | % disp(['User selected', fullfile(pathname, filename)]) 149 | % end 150 | % dvc_file = load(filename); 151 | % handles.pic = dvc_file.vol_stack; 152 | handles.pic = importdata([pathname,filename]); 153 | handles.pic = flip(handles.pic,1); %corrects for import flipping 154 | axes(handles.axes1); 155 | imagesc(handles.pic); set(gca,'YDir','normal'); 156 | set(gca,'fontweight','b','FontSize',12,'xcolor','w','ycolor','w'); 157 | [m,n,p] = size(handles.pic); 158 | if p ~= 1, 159 | handles.pic = squeeze(sum(handles.pic(:,:,1:p),3)); 160 | end 161 | colormap(handles.axes1,'gray'); 162 | colormap(handles.axes2,CMRmap(256)); 163 | colormap(handles.axes3,CMRmap(256)); 164 | 165 | guidata(hObject,handles); 166 | 167 | 168 | function dicw_Callback(hObject, eventdata, handles) 169 | % hObject handle to dicw (see GCBO) 170 | % eventdata reserved - to be defined in a future version of MATLAB 171 | % handles structure with handles and user data (see GUIDATA) 172 | 173 | % Hints: get(hObject,'String') returns contents of dicw as text 174 | % str2double(get(hObject,'String')) returns contents of dicw as a double 175 | w = str2double(get(hObject, 'String')); 176 | if isnan(w) 177 | set(hObject, 'String', 0); 178 | errordlg('Input must be a number','Error'); 179 | end 180 | 181 | % Save the new density value 182 | handles.dicw = w; 183 | guidata(hObject,handles); 184 | 185 | % --- Executes during object creation, after setting all properties. 186 | function dicw_CreateFcn(hObject, eventdata, handles) 187 | % hObject handle to dicw (see GCBO) 188 | % eventdata reserved - to be defined in a future version of MATLAB 189 | % handles empty - handles not created until after all CreateFcns called 190 | 191 | % Hint: edit controls usually have a white background on Windows. 192 | % See ISPC and COMPUTER. 193 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 194 | set(hObject,'BackgroundColor','white'); 195 | end 196 | handles.dicw = 64; 197 | guidata(hObject,handles); 198 | 199 | 200 | 201 | function dicd_Callback(hObject, eventdata, handles) 202 | % hObject handle to dicd (see GCBO) 203 | % eventdata reserved - to be defined in a future version of MATLAB 204 | % handles structure with handles and user data (see GUIDATA) 205 | 206 | % Hints: get(hObject,'String') returns contents of dicd as text 207 | % str2double(get(hObject,'String')) returns contents of dicd as a double 208 | d = str2double(get(hObject, 'String')); 209 | if isnan(d) 210 | set(hObject, 'String', 0); 211 | errordlg('Input must be a number','Error'); 212 | end 213 | 214 | % Save the new density value 215 | handles.dicd = d; 216 | guidata(hObject,handles); 217 | 218 | % --- Executes during object creation, after setting all properties. 219 | function dicd_CreateFcn(hObject, eventdata, handles) 220 | % hObject handle to dicd (see GCBO) 221 | % eventdata reserved - to be defined in a future version of MATLAB 222 | % handles empty - handles not created until after all CreateFcns called 223 | 224 | % Hint: edit controls usually have a white background on Windows. 225 | % See ISPC and COMPUTER. 226 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 227 | set(hObject,'BackgroundColor','white'); 228 | end 229 | handles.dicd = 16; 230 | guidata(hObject,handles); 231 | 232 | 233 | 234 | function epp_Callback(hObject, eventdata, handles) 235 | % hObject handle to epp (see GCBO) 236 | % eventdata reserved - to be defined in a future version of MATLAB 237 | % handles structure with handles and user data (see GUIDATA) 238 | 239 | % Hints: get(hObject,'String') returns contents of epp as text 240 | % str2double(get(hObject,'String')) returns contents of epp as a double 241 | epp = str2double(get(hObject, 'String')); 242 | if isnan(epp) 243 | set(hObject, 'String', 0); 244 | errordlg('Input must be a number','Error'); 245 | end 246 | 247 | % Save the new density value 248 | handles.epp = epp; 249 | guidata(hObject,handles); 250 | 251 | % --- Executes during object creation, after setting all properties. 252 | function epp_CreateFcn(hObject, eventdata, handles) 253 | % hObject handle to epp (see GCBO) 254 | % eventdata reserved - to be defined in a future version of MATLAB 255 | % handles empty - handles not created until after all CreateFcns called 256 | 257 | % Hint: edit controls usually have a white background on Windows. 258 | % See ISPC and COMPUTER. 259 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 260 | set(hObject,'BackgroundColor','white'); 261 | end 262 | handles.epp = 0.02; 263 | guidata(hObject,handles); 264 | 265 | 266 | 267 | function trans_Callback(hObject, eventdata, handles) 268 | % hObject handle to trans (see GCBO) 269 | % eventdata reserved - to be defined in a future version of MATLAB 270 | % handles structure with handles and user data (see GUIDATA) 271 | 272 | % Hints: get(hObject,'String') returns contents of trans as text 273 | % str2double(get(hObject,'String')) returns contents of trans as a double 274 | trans = str2double(get(hObject, 'String')); 275 | if isnan(trans) 276 | set(hObject, 'String', 0); 277 | errordlg('Input must be a number','Error'); 278 | end 279 | 280 | % Save the new density value 281 | handles.trans = trans; 282 | guidata(hObject,handles); 283 | 284 | % --- Executes during object creation, after setting all properties. 285 | function trans_CreateFcn(hObject, eventdata, handles) 286 | % hObject handle to trans (see GCBO) 287 | % eventdata reserved - to be defined in a future version of MATLAB 288 | % handles empty - handles not created until after all CreateFcns called 289 | 290 | % Hint: edit controls usually have a white background on Windows. 291 | % See ISPC and COMPUTER. 292 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 293 | set(hObject,'BackgroundColor','white'); 294 | end 295 | handles.trans = 7; 296 | guidata(hObject,handles); 297 | 298 | % --- Executes on button press in gobutton. 299 | function gobutton_Callback(hObject, eventdata, handles) 300 | % hObject handle to gobutton (see GCBO) 301 | % eventdata reserved - to be defined in a future version of MATLAB 302 | % handles structure with handles and user data (see GUIDATA) 303 | 304 | % axes(handles.axes1); 305 | % handles.x; 306 | % handles.y; 307 | % handles.displ; 308 | % contourf(handles.x, handles.y,handles.displ); 309 | 310 | %Simulate deformed speckle images 311 | handles.epp; 312 | [handles.tpic handles.strpic handles.shpic handles.ppic dispp] = speckles(handles.epp, handles.trans, handles.pic); 313 | 314 | %Execute 2D DIC code ******************************************************* 315 | %handles.inc=0; 316 | %Translation 317 | [ut vt] = run2dic(handles.dicw,handles.dicd,handles.pic,handles.tpic); 318 | [dudxt, dudyt, dvdxt, dvdyt]=grad2d(ut,vt,1,1,handles.dicd*0.35,handles.dicd*0.35); 319 | handles.ut = ut; 320 | handles.vt = vt; 321 | handles.e11t = dudxt; 322 | handles.e22t = dvdyt; 323 | handles.e12t = dudyt; 324 | handles.e21t = dvdxt; 325 | 326 | %Uniaxal Tension 327 | [ua va] = run2dic(handles.dicw,handles.dicd,handles.pic,handles.strpic); 328 | [dudxa, dudya, dvdxa, dvdya]=grad2d(ua,va,1,1,handles.dicd*0.35,handles.dicd*0.35); 329 | handles.ua = ua; 330 | handles.va = va; 331 | handles.e11a = dudxa; 332 | handles.e22a = dvdya; 333 | handles.e12a = dudya; 334 | handles.e21a = dvdxa; 335 | 336 | %Pure Shear 337 | [us vs] = run2dic(handles.dicw,handles.dicd,handles.pic,handles.shpic); 338 | [dudxs, dudys, dvdxs, dvdys]=grad2d(us,vs,1,1,handles.dicd*0.35,handles.dicd*0.35); 339 | handles.us = us; 340 | handles.vs = vs; 341 | handles.e11s = dudxs; 342 | handles.e22s = dvdys; 343 | handles.e12s = dudys; 344 | handles.e21s = dvdxs; 345 | 346 | %Point Force 347 | [up vp] = run2dic(handles.dicw,handles.dicd,handles.pic,handles.ppic); 348 | [dudxp, dudyp, dvdxp, dvdyp]=grad2d(up,vp,1,1,handles.dicd*0.35,handles.dicd*0.35); 349 | handles.up = up; 350 | handles.vp = vp; 351 | handles.e11p = dudxp; 352 | handles.e22p = dvdyp; 353 | handles.e12p = dudyp; 354 | handles.e21p = dvdxp; 355 | 356 | [M,N]=size(handles.pic);%Find the size of the confocal image 357 | %w0=64;d0=16; %w0:Subset size & d0:Subset spacing, 358 | %For example, when M=N=P=512, (w0=64,d0=32) gives 15x15x15 data points for correlations 359 | x0=N/2;y0=M/2; %find the center of the image 360 | d0=handles.dicd; 361 | %y0=256;x0=256;z0=256; %Manually select center 362 | m=round(M/2/d0)-1;n=round(N/2/d0)-1;% number of correlation points in half of the image (any integer) 363 | [x,y]=meshgrid([-n:n]*d0+x0,[-m:m]*d0+y0);% 364 | handles.x = x; 365 | handles.y = y; 366 | 367 | if handles.popup == 1, 368 | handles.u = handles.ut; 369 | handles.v = handles.vt; 370 | handles.e11 = handles.e11t; 371 | handles.e22 = handles.e22t; 372 | handles.e12 = handles.e12t; 373 | handles.e21 = handles.e21t; 374 | end 375 | if handles.popup == 2, 376 | handles.u = handles.ua; 377 | handles.v = handles.va; 378 | handles.e11 = handles.e11a; 379 | handles.e22 = handles.e22a; 380 | handles.e12 = handles.e12a; 381 | handles.e21 = handles.e21a; 382 | end 383 | if handles.popup == 3, 384 | handles.u = handles.us; 385 | handles.v = handles.vs; 386 | handles.e11 = handles.e11s; 387 | handles.e22 = handles.e22s; 388 | handles.e12 = handles.e12s; 389 | handles.e21 = handles.e21s; 390 | end 391 | 392 | handles.displ = sqrt(handles.u.^2 + handles.v.^2); 393 | 394 | axes(handles.axes2); 395 | %im(handles.tpic); 396 | handles.x; 397 | handles.y; 398 | %handles.displ; 399 | contourf(handles.x, handles.y,handles.u); colorbar; 400 | h = colorbar; 401 | set(get(h,'title'),'string',' Pixel','fontweight','b','fontsize',12,'color','w'); 402 | set(h,'fontweight','b', 'fontsize',12); 403 | grid on 404 | axis tight 405 | set(gca,'fontweight','b','FontSize',12,'xcolor','w','ycolor','w'); 406 | 407 | 408 | axes(handles.axes3); 409 | handles.x; 410 | handles.y; 411 | %handles.displ; 412 | contourf(handles.x, handles.y,handles.v); colorbar; 413 | h = colorbar; 414 | set(get(h,'title'),'string',' Pixel','fontweight','b','fontsize',12,'color','w'); 415 | set(h,'fontweight','b', 'fontsize',12); 416 | grid on 417 | axis tight 418 | set(gca,'fontweight','b','FontSize',12,'xcolor','w','ycolor','w'); 419 | 420 | 421 | axes(handles.axes5); 422 | clear err; 423 | err = (handles.ut - dispp.ut2)./dispp.ut2*100; 424 | err = err(:); 425 | hist(err,20); 426 | set(gca,'fontweight','b','FontSize',10,'xcolor','k','ycolor','k'); 427 | %xlabel('difference (pixel)','fontweight','b','FontSize',10); 428 | ylabel('u_1','fontweight','b','FontSize',10); 429 | 430 | axes(handles.axes6); 431 | %Construct the solution right here: 432 | [M,N]=size(handles.tpic); 433 | x0=N/2;y0=M/2; %find the center of the image 434 | d0 = handles.dicd; 435 | m=round(M/2/d0)-1;n=round(N/2/d0)-1;% number of correlation points in half of the image (any integer) 436 | [x,y]=meshgrid([-n:n]*d0+x0,[-m:m]*d0+y0); 437 | strain = handles.epp; 438 | ua = strain*x; % apply strain along x-direction 439 | va = -strain/2*y; % Poisson's contraction with nu = 0.5 440 | err = (handles.ua - ua)./ua*100; 441 | err = err(:); 442 | hist(err,20); 443 | set(gca,'fontweight','b','FontSize',10,'xcolor','k','ycolor','k'); 444 | %xlabel('difference (pixel)','fontweight','b','FontSize',10); 445 | %ylabel('Frequency','fontweight','b','FontSize',10); 446 | 447 | axes(handles.axes7); 448 | us = strain*y; % shear in x 449 | vs = strain*x; % shear in y 450 | err = (handles.us - us)./us*100; 451 | err = err(:); 452 | hist(err,20); 453 | set(gca,'fontweight','b','FontSize',10,'xcolor','k','ycolor','k'); 454 | %xlabel('difference (pixel)','fontweight','b','FontSize',10); 455 | %ylabel('Frequency','fontweight','b','FontSize',10); 456 | 457 | axes(handles.axes8); 458 | % generate point force image 459 | nu = 0.45; 460 | E = 1000; 461 | Fx = E*strain; 462 | [m,n] = size(x); 463 | 464 | x = x-round(N/2); 465 | y = y - round(M/2); 466 | r = sqrt(x.^2 + y.^2); 467 | ind = find(r == 0); %Exclude the singularity at r = 0 468 | r(ind) = 5*10^-4; 469 | 470 | coeff = (1+nu)/(2*pi*E); 471 | z = 0; Fz = 0; Fy = Fx; 472 | up = coeff*( (x.*z./r.^3 - (1-2*nu)*x./( r.*(r + z)))*Fz... 473 | + (2*(1-nu)*r + z)./(r.*(r + z))*Fx... 474 | + (2*r.*(nu*r + z) + z.^2).*x./(r.^3.*(r + z).^2).*(x*Fx + y*Fy)); 475 | 476 | vp = coeff*( (y.*z./r.^3 - (1-2*nu)*y./( r.*(r + z)))*Fz... 477 | + (2*(1-nu)*r + z)./(r.*(r + z))*Fy... 478 | + (2*r.*(nu*r + z) + z.^2).*y./(r.^3.*(r + z).^2).*(x*Fx + y*Fy)); 479 | err = (handles.up - up)./up*100; 480 | err = err(:); 481 | hist(err,20); 482 | set(gca,'fontweight','b','FontSize',10,'xcolor','k','ycolor','k'); 483 | %xlabel('difference (pixel)','fontweight','b','FontSize',10); 484 | %ylabel('Frequency','fontweight','b','FontSize',10); 485 | 486 | axes(handles.axes9); 487 | if dispp.vt2 == 0, 488 | err = (handles.vt); 489 | else 490 | err = (handles.vt - dispp.vt2)./dispp.vt2*100; 491 | end 492 | err = err(:); 493 | hist(err,20); 494 | set(gca,'fontweight','b','FontSize',10,'xcolor','k','ycolor','k'); 495 | %xlabel('difference (pixel)','fontweight','b','FontSize',10); 496 | ylabel('u_2','fontweight','b','FontSize',10); 497 | 498 | axes(handles.axes10); 499 | err = (handles.va - va)./va*100; 500 | err = err(:); 501 | hist(err,20); 502 | set(gca,'fontweight','b','FontSize',10,'xcolor','k','ycolor','k'); 503 | %xlabel('difference (pixel)','fontweight','b','FontSize',10); 504 | %ylabel('Frequency','fontweight','b','FontSize',10); 505 | 506 | axes(handles.axes11); 507 | err = (handles.vs - vs)./vs*100; 508 | err = err(:); 509 | hist(err,20); 510 | set(gca,'fontweight','b','FontSize',10,'xcolor','k','ycolor','k'); 511 | %xlabel('difference (pixel)','fontweight','b','FontSize',10); 512 | %ylabel('Frequency','fontweight','b','FontSize',10); 513 | 514 | axes(handles.axes12); 515 | err = (handles.vp - vp)./vp*100; 516 | err = err(:); 517 | hist(err,20); 518 | set(gca,'fontweight','b','FontSize',10,'xcolor','k','ycolor','k'); 519 | %xlabel('difference (pixel)','fontweight','b','FontSize',10); 520 | %ylabel('Frequency','fontweight','b','FontSize',10); 521 | 522 | 523 | % handles.x; 524 | % handles.x; 525 | % handles.x; 526 | % handles.x; 527 | % handles.x; 528 | % handles.y; 529 | % handles.u; 530 | % handles.v; 531 | % quiver(handles.x, handles.y,handles.u,handles.v); 532 | % Update handles structure 533 | guidata(hObject, handles); 534 | 535 | 536 | 537 | % --- Executes on button press in magu. 538 | function magu_Callback(hObject, eventdata, handles) 539 | % hObject handle to magu (see GCBO) 540 | % eventdata reserved - to be defined in a future version of MATLAB 541 | % handles structure with handles and user data (see GUIDATA) 542 | if handles.popup == 1, 543 | handles.u = handles.ut; 544 | handles.v = handles.vt; 545 | end 546 | if handles.popup == 2, 547 | handles.u = handles.ua; 548 | handles.v = handles.va; 549 | end 550 | if handles.popup == 3, 551 | handles.u = handles.us; 552 | handles.v = handles.vs; 553 | end 554 | if handles.popup == 4, 555 | handles.u = handles.up; 556 | handles.v = handles.vp; 557 | end 558 | handles.displ = sqrt(handles.u.^2 + handles.v.^2); 559 | 560 | axes(handles.axes2); 561 | cla; 562 | contourf(handles.x, handles.y,handles.displ); 563 | h = colorbar; 564 | set(get(h,'title'),'string',' Pixel','fontweight','b','fontsize',12,'color','w'); 565 | set(h,'fontweight','b', 'fontsize',12); 566 | grid on 567 | axis tight 568 | set(gca,'fontweight','b','FontSize',12,'xcolor','w','ycolor','w'); 569 | 570 | axes(handles.axes3); 571 | cla; 572 | contourf(handles.x, handles.y,handles.displ); 573 | hold on; 574 | quiver(handles.x, handles.y,handles.u,handles.v,'w'); 575 | h = colorbar; 576 | set(get(h,'title'),'string',' Pixel','fontweight','b','fontsize',12,'color','w'); 577 | set(h,'fontweight','b', 'fontsize',12); 578 | grid on 579 | axis tight 580 | set(gca,'fontweight','b','FontSize',12,'xcolor','w','ycolor','w'); 581 | % Hint: get(hObject,'Value') returns toggle state of magu 582 | 583 | 584 | % --- Executes on button press in ucomp. 585 | function ucomp_Callback(hObject, eventdata, handles) 586 | % hObject handle to ucomp (see GCBO) 587 | % eventdata reserved - to be defined in a future version of MATLAB 588 | % handles structure with handles and user data (see GUIDATA) 589 | if handles.popup == 1, 590 | handles.u = handles.ut; 591 | handles.v = handles.vt; 592 | end 593 | if handles.popup == 2, 594 | handles.u = handles.ua; 595 | handles.v = handles.va; 596 | end 597 | if handles.popup == 3, 598 | handles.u = handles.us; 599 | handles.v = handles.vs; 600 | end 601 | if handles.popup == 4, 602 | handles.u = handles.up; 603 | handles.v = handles.vp; 604 | end 605 | 606 | axes(handles.axes2); 607 | cla; 608 | contourf(handles.x, handles.y,handles.u); 609 | h = colorbar; 610 | set(get(h,'title'),'string',' Pixel','fontweight','b','fontsize',12,'color','w'); 611 | set(h,'fontweight','b', 'fontsize',12); 612 | grid on 613 | axis tight 614 | set(gca,'fontweight','b','FontSize',12,'xcolor','w','ycolor','w'); 615 | 616 | axes(handles.axes3); 617 | cla; 618 | contourf(handles.x, handles.y,handles.v); 619 | h = colorbar; 620 | set(get(h,'title'),'string',' Pixel','fontweight','b','fontsize',12,'color','w'); 621 | set(h,'fontweight','b', 'fontsize',12); 622 | grid on 623 | axis tight 624 | set(gca,'fontweight','b','FontSize',12,'xcolor','w','ycolor','w'); 625 | % Hint: get(hObject,'Value') returns toggle state of ucomp 626 | 627 | %------------------------------------------------------ 628 | function [tpic strpic shpic ppic dispp] = speckles(strain, trans, pic); 629 | 630 | %General image warping based on deformation field 631 | C= pic; % test image 632 | [x, y] = meshgrid(1:size(C,2), 1:size(C,1)); 633 | 634 | % generate translated image 635 | u = trans; % x-translation 636 | v = 0; % y-translation 637 | dispp.ut2 = u; 638 | dispp.vt2 = v; 639 | tpic = interp2(double(C), x-u, y-v); 640 | %figure,im(tpic); 641 | clear u; clear v; 642 | 643 | % generate uniaxially stretched image 644 | u = strain*x; % apply strain along x-direction 645 | v = -strain/2*y; % Poisson's contraction with nu = 0.5 646 | dispp.ua2 = u; 647 | dispp.va2 = v; 648 | strpic = interp2(double(C), x-u, y-v); 649 | %figure,im(strpic); 650 | clear u; clear v; 651 | 652 | % generate pure sheared image 653 | u = strain*y; % shear in x 654 | v = strain*x; % shear in y 655 | dispp.us2 = u; 656 | dispp.vs2 = v; 657 | % compute the warped image - the subtractions are because we're specifying 658 | % where in the original image each pixel in the new image comes from 659 | shpic = interp2(double(C), x-u, y-v); 660 | %figure,im(shpic); 661 | clear u; clear v; 662 | 663 | % generate point force image 664 | nu = 0.45; 665 | E = 1000; 666 | Fx = E*strain; 667 | [m,n] = size(x); 668 | 669 | x = x-round(size(C,2)/2); 670 | y = y - round(size(C,1)/2); 671 | r = sqrt(x.^2 + y.^2); 672 | ind = find(r == 0); %Exclude the singularity at r = 0 673 | r(ind) = 5*10^-4; 674 | 675 | coeff = (1+nu)/(2*pi*E); 676 | z = 0; Fz = 0; Fy = Fx; 677 | u = coeff*( (x.*z./r.^3 - (1-2*nu)*x./( r.*(r + z)))*Fz... 678 | + (2*(1-nu)*r + z)./(r.*(r + z))*Fx... 679 | + (2*r.*(nu*r + z) + z.^2).*x./(r.^3.*(r + z).^2).*(x*Fx + y*Fy)); 680 | 681 | v = coeff*( (y.*z./r.^3 - (1-2*nu)*y./( r.*(r + z)))*Fz... 682 | + (2*(1-nu)*r + z)./(r.*(r + z))*Fy... 683 | + (2*r.*(nu*r + z) + z.^2).*y./(r.^3.*(r + z).^2).*(x*Fx + y*Fy)); 684 | max(u(:)); 685 | dispp.up2 = u; 686 | dispp.vp2 = v; 687 | % compute the warped image - the subtractions are because we're specifying 688 | % where in the original image each pixel in the new image comes from 689 | ppic = interp2(x,y,double(C), x-u, y-v); 690 | %figure,im(pic); 691 | %figure,im(ppic); 692 | v; 693 | 694 | 695 | 696 | %---------------------------------------------------------- 697 | 698 | % --- Executes on selection change in output_selection. 699 | function output_selection_Callback(hObject, eventdata, handles) 700 | % hObject handle to output_selection (see GCBO) 701 | % eventdata reserved - to be defined in a future version of MATLAB 702 | % handles structure with handles and user data (see GUIDATA) 703 | 704 | % Hints: contents = get(hObject,'String') returns output_selection contents as cell array 705 | % contents{get(hObject,'Value')} returns selected item from output_selection 706 | popup_sel_index = get(handles.output_selection, 'Value'); 707 | handles.popup = popup_sel_index; 708 | guidata(hObject, handles); 709 | 710 | % --- Executes during object creation, after setting all properties. 711 | function output_selection_CreateFcn(hObject, eventdata, handles) 712 | % hObject handle to output_selection (see GCBO) 713 | % eventdata reserved - to be defined in a future version of MATLAB 714 | % handles empty - handles not created until after all CreateFcns called 715 | 716 | % Hint: popupmenu controls usually have a white background on Windows. 717 | % See ISPC and COMPUTER. 718 | if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) 719 | set(hObject,'BackgroundColor','white'); 720 | end 721 | handles.popup = 1; 722 | guidata(hObject, handles); 723 | 724 | % --- Executes on button press in diagstrains. 725 | function diagstrains_Callback(hObject, eventdata, handles) 726 | % hObject handle to diagstrains (see GCBO) 727 | % eventdata reserved - to be defined in a future version of MATLAB 728 | % handles structure with handles and user data (see GUIDATA) 729 | if handles.popup == 1, 730 | handles.e11 = handles.e11t; 731 | handles.e22 = handles.e22t; 732 | end 733 | if handles.popup == 2, 734 | handles.e11 = handles.e11a; 735 | handles.e22 = handles.e22a; 736 | end 737 | if handles.popup == 3, 738 | handles.e11 = handles.e11s; 739 | handles.e22 = handles.e22s; 740 | end 741 | if handles.popup == 4, 742 | handles.e11 = handles.e11p; 743 | handles.e22 = handles.e22p; 744 | end 745 | % Hint: get(hObject,'Value') returns toggle state of diagstrains 746 | axes(handles.axes2); 747 | cla; 748 | contourf(handles.x, handles.y,handles.e11); 749 | h = colorbar; 750 | set(get(h,'title'),'string',' Pixel','fontweight','b','fontsize',12,'color','w'); 751 | set(h,'fontweight','b', 'fontsize',12); 752 | grid on 753 | axis tight 754 | set(gca,'fontweight','b','FontSize',12,'xcolor','w','ycolor','w'); 755 | 756 | axes(handles.axes3); 757 | cla; 758 | contourf(handles.x, handles.y,handles.e22); 759 | h = colorbar; 760 | set(get(h,'title'),'string',' Pixel','fontweight','b','fontsize',12,'color','w'); 761 | set(h,'fontweight','b', 'fontsize',12); 762 | grid on 763 | axis tight 764 | set(gca,'fontweight','b','FontSize',12,'xcolor','w','ycolor','w'); 765 | 766 | % --- Executes on button press in divstrains. 767 | function divstrains_Callback(hObject, eventdata, handles) 768 | % hObject handle to divstrains (see GCBO) 769 | % eventdata reserved - to be defined in a future version of MATLAB 770 | % handles structure with handles and user data (see GUIDATA) 771 | 772 | % Hint: get(hObject,'Value') returns toggle state of divstrains 773 | if handles.popup == 1, 774 | handles.e12 = handles.e12t; 775 | handles.e21 = handles.e21t; 776 | end 777 | if handles.popup == 2, 778 | handles.e12 = handles.e12a; 779 | handles.e21 = handles.e21a; 780 | end 781 | if handles.popup == 3, 782 | handles.e12 = handles.e12s; 783 | handles.e21 = handles.e21s; 784 | end 785 | if handles.popup == 4, 786 | handles.e12 = handles.e12p; 787 | handles.e21 = handles.e21p; 788 | end 789 | 790 | axes(handles.axes2); 791 | cla; 792 | contourf(handles.x, handles.y,handles.e12); 793 | h = colorbar; 794 | set(get(h,'title'),'string',' Pixel','fontweight','b','fontsize',12,'color','w'); 795 | set(h,'fontweight','b', 'fontsize',12); 796 | grid on 797 | axis tight 798 | set(gca,'fontweight','b','FontSize',12,'xcolor','w','ycolor','w'); 799 | 800 | axes(handles.axes3); 801 | cla; 802 | contourf(handles.x, handles.y,handles.e21); 803 | h = colorbar; 804 | set(get(h,'title'),'string',' Pixel','fontweight','b','fontsize',12,'color','w'); 805 | set(h,'fontweight','b', 'fontsize',12); 806 | grid on 807 | axis tight 808 | set(gca,'fontweight','b','FontSize',12,'xcolor','w','ycolor','w'); 809 | 810 | %*****************************************************************RUN DIC 811 | 812 | %This is a 2D correlation code derived from the 3D code 813 | 814 | function [ud vd] = run2dic(w0,d0,ia,ib); 815 | 816 | inc = 0; stack = 1; 817 | 818 | %--------------------------Construct 2d grid points for measurements----------- 819 | [M,N]=size(ia);%Find the size of the confocal image 820 | %w0=64;d0=16; %w0:Subset size & d0:Subset spacing, 821 | %For example, when M=N=P=512, (w0=64,d0=32) gives 15x15x15 data points for correlations 822 | x0=N/2;y0=M/2; %find the center of the image 823 | %y0=256;x0=256;z0=256; %Manually select center 824 | m=round(M/2/d0)-1;n=round(N/2/d0)-1;% number of correlation points in half of the image (any integer) 825 | [x,y]=meshgrid([-n:n]*d0+x0,[-m:m]*d0+y0);%construct a set of 3d grid points centered at the center of the confocal image. 826 | ua=zeros(size(x));va=ua;%initialize displacement variables, size(x) is odd number 827 | [ud,vd]=dvc_full_2d(ia,ib,x,y,ua,va,w0,inc); 828 | 829 | %--------FFT-based correlation --------------------------- 830 | 831 | function [u,v]=dvc_full_2d(m0,m1,x0,y0,ua,va,w0,inc) 832 | [M N]=size(m0); 833 | [m n]=size(x0); 834 | u=zeros(m,n)*nan;v=u; 835 | %u2=zeros(m,n)*nan;v2=u2; 836 | x0=round(x0);y0=round(y0); 837 | x1=x0+round(ua);y1=y0+round(va); 838 | if inc == 1, 839 | x0 = x1; y0 = y1; 840 | ua=zeros(size(x0));va=ua; 841 | end 842 | h = waitbar(0,'Running 2D DIC Code... '); 843 | for i=1:m, 844 | waitbar(i/m,h); 845 | for j=1:n, 846 | i0=(y0(i,j)-w0/2+1); i1=y0(i,j)+w0/2; 847 | j0=(x0(i,j)-w0/2+1); j1=x0(i,j)+w0/2; 848 | p0=(y1(i,j)-w0/2+1); p1=y1(i,j)+w0/2; 849 | q0=(x1(i,j)-w0/2+1); q1=x1(i,j)+w0/2; 850 | if i0>=1 & i0<=M & j0>=1 & j0<=N & ... 851 | i1>=1 & i1<=M & j1>=1 & j1<=N & ... 852 | p0>=1 & p0<=M & q0>=1 & q0<=N & ... 853 | p1>=1 & p1<=M & q1>=1 & q1<=N, 854 | dm0=m0(i0:i1,j0:j1); 855 | dm1=m1(p0:p1,q0:q1); 856 | [du dv dc]=decorr2a(dm0,dm1); 857 | %[du,dv] = normxcorr2D(dm0,dm1); 858 | if(length(du)*length(dv)==1) 859 | % x(i,j,k)=(j-1)*d+d/2; 860 | % y(i,j,k)=(i-1)*d+d/2; 861 | % z(i,j,k)=(k-1)*d+d/2; 862 | u(i,j)=round(ua(i,j))+du; 863 | v(i,j)=round(va(i,j))+dv; 864 | end 865 | end 866 | end 867 | end 868 | close(h); 869 | 870 | %----------------------------------- 871 | function [dudx, dudy, dvdx, dvdy]=grad2d(u,v,ucal,vcal,xcal,ycal) 872 | [M N]=size(u); 873 | 874 | [dx,dy]=meshgrid(-[-1:1]/18,-[-1:1]/18); 875 | dudx=ones(M,N)*nan; 876 | dudy=dudx; 877 | dvdx=dudx; 878 | dvdy=dudx; 879 | 880 | dudx(2:M-1,2:N-1)=convn(u,dx,'valid')*ucal/xcal; 881 | dudy(2:M-1,2:N-1)=convn(u,dy,'valid')*ucal/ycal; 882 | 883 | dvdx(2:M-1,2:N-1)=convn(v,dx,'valid')*vcal/xcal; 884 | dvdy(2:M-1,2:N-1)=convn(v,dy,'valid')*vcal/ycal; 885 | 886 | %----------------------------------- 887 | 888 | function [du,dv,dc]=decorr2a(dm0,dm1) 889 | [M,N]=size(dm0); 890 | dm0=double(dm0); dm1=double(dm1); 891 | c=abs(fftshift(ifft2(conj(fft2(dm0)).*fft2(dm1)))); 892 | cn=abs(fftshift(ifft2(conj(fft2(dm0))./abs(fft2(dm0)).*fft2(dm1)./abs(fft2(dm1))))); 893 | cc=sum(sum((dm0-dm1).*(dm0-dm1))); 894 | if cc==0 | isnan(sum(c(:))), 895 | du=nan; 896 | dv=nan; 897 | dc=nan; 898 | else 899 | [dv,du]=find(c==max(c(:))); 900 | 901 | if dv==1|dv==M|du==1|du==N, 902 | du=nan; 903 | dv=nan; 904 | dc=nan; 905 | else 906 | cc=c(dv-1:dv+1,du-1:du+1); 907 | [mm,nn]=size(cc); 908 | [xx,yy]=meshgrid(-(mm-1)/2:(mm-1)/2,-(nn-1)/2:(nn-1)/2); 909 | xx2=xx.*xx; 910 | yy2=yy.*yy; 911 | A= [sum(sum(xx2.*xx2)) sum(sum(xx2.*yy2)) 0 0 sum(sum(xx2)); 912 | sum(sum(xx2.*yy2)) sum(sum(yy2.*yy2)) 0 0 sum(sum(yy2)); 913 | 0 0 sum(sum(xx2)) 0 0; 914 | 0 0 0 sum(sum(yy2)) 0; 915 | sum(sum(xx2)) sum(sum(yy2)) 0 0 sum(sum(ones(mm,nn)))]; 916 | y=[sum(sum(xx2.*cc)) sum(sum(yy2.*cc)) sum(sum(xx.*cc)) sum(sum(yy.*cc)) sum(sum(cc))]'; 917 | x=A\y; 918 | x0=-x(3)/2/x(1); 919 | y0=-x(4)/2/x(2); 920 | dc=sqrt(x(1)^2+x(2)^2); 921 | 922 | du=du+x0-(N/2+1); 923 | dv=dv+y0-(M/2+1); 924 | end 925 | end 926 | 927 | 928 | % --- Executes on button press in viewdef. 929 | function viewdef_Callback(hObject, eventdata, handles) 930 | % hObject handle to viewdef (see GCBO) 931 | % eventdata reserved - to be defined in a future version of MATLAB 932 | % handles structure with handles and user data (see GUIDATA) 933 | original_image = handles.pic; 934 | translated_image = handles.tpic; 935 | strain_image = handles.strpic; 936 | shear_image = handles.shpic; 937 | pointload_image = handles.ppic; 938 | figure; colormap gray; set(gcf,'Color','white'); 939 | subplot(1,2,1); imagesc(handles.pic); axis image; title('Original Image'); 940 | set(gca,'YDir','normal','FontName','Helvetica','fontweight','b'); 941 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 942 | subplot(1,2,2); imagesc(handles.tpic); axis image; title('Translation'); 943 | set(gca,'YDir','normal','FontName','Helvetica','fontweight','b'); 944 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 945 | 946 | figure; colormap gray; set(gcf,'Color','white'); 947 | subplot(1,2,1); imagesc(handles.pic); axis image; title('Original Image'); 948 | set(gca,'YDir','normal','FontName','Helvetica','fontweight','b'); 949 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 950 | subplot(1,2,2); imagesc(handles.strpic); axis image; title('Uniaxial Strain'); 951 | set(gca,'YDir','normal','FontName','Helvetica','fontweight','b'); 952 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 953 | 954 | figure; colormap gray; set(gcf,'Color','white'); 955 | subplot(1,2,1); imagesc(handles.pic); axis image; title('Original Image'); 956 | set(gca,'YDir','normal','FontName','Helvetica','fontweight','b'); 957 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 958 | subplot(1,2,2); imagesc(handles.shpic); axis image; title('Shear Strain'); 959 | set(gca,'YDir','normal','FontName','Helvetica','fontweight','b'); 960 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 961 | 962 | figure; colormap gray; set(gcf,'Color','white'); 963 | subplot(1,2,1); imagesc(handles.pic); axis image; title('Original Image'); 964 | set(gca,'YDir','normal','FontName','Helvetica','fontweight','b'); 965 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 966 | subplot(1,2,2); imagesc(handles.ppic); axis image; title('Point Load'); 967 | set(gca,'YDir','normal','FontName','Helvetica','fontweight','b'); 968 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 969 | 970 | imagechoice = questdlg('Would you like to save the reference and deformed images?', ... 971 | 'Save images', ... 972 | 'Save to *.tif','Save to *.mat','No','No'); 973 | % Handle response 974 | switch imagechoice 975 | case 'Save to *.tif' 976 | if isa(original_image,'uint8') 977 | imwrite(flip(original_image,1),'original_image.tif'); 978 | else 979 | imwrite(uint8(round(255*flip(original_image,1)./max(translated_image(:)))),'original_image.tif'); 980 | end 981 | imwrite(uint8(round(255*flip(translated_image,1)./max(translated_image(:)))),'translated_image.tif'); 982 | imwrite(uint8(round(255*flip(strain_image,1)./max(strain_image(:)))),'strain_image.tif'); 983 | imwrite(uint8(round(255*flip(shear_image,1)./max(shear_image(:)))),'shear_image.tif'); 984 | imwrite(uint8(round(255*flip(pointload_image,1)./max(pointload_image(:)))),'pointload_image.tif'); 985 | case 'Save to *.mat' 986 | save('imagedata.mat','original_image','translated_image','strain_image','shear_image','pointload_image'); 987 | case 'No' 988 | end 989 | 990 | u1_translation = handles.ut; u2_translation = handles.vt; 991 | u1_strain = handles.ua; u2_strain = handles.va; 992 | u1_shear = handles.us; u2_shear = handles.vs; 993 | u1_pointload = handles.up; u2_pointload = handles.vp; 994 | 995 | figure; colormap gray; set(gcf,'Color','white'); 996 | subplot(1,2,1); contourf(handles.x, handles.y, handles.ut, 10,'LineWidth',0); colorbar; h1= colorbar; 997 | set(get(h1,'title'),'string',' Pixel','fontweight','b','fontsize',12); 998 | axis image; title('u_1, Translation Case'); 999 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 1000 | subplot(1,2,2); contourf(handles.x, handles.y, handles.vt, 10,'LineWidth',0); colorbar; h2= colorbar; 1001 | set(get(h2,'title'),'string',' Pixel','fontweight','b','fontsize',12); 1002 | axis image; title('u_2, Translation Case'); 1003 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 1004 | 1005 | 1006 | figure; colormap gray; set(gcf,'Color','white'); 1007 | subplot(1,2,1); contourf(handles.x, handles.y, handles.ua, 10,'LineWidth',0); colorbar; h3= colorbar; 1008 | set(get(h3,'title'),'string',' Pixel','fontweight','b','fontsize',12); 1009 | axis image; title('u_1, Uniaxial Strain Case'); 1010 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 1011 | subplot(1,2,2); contourf(handles.x, handles.y, handles.va, 10,'LineWidth',0); colorbar; h4= colorbar; 1012 | set(get(h4,'title'),'string',' Pixel','fontweight','b','fontsize',12); 1013 | axis image; title('u_2, Uniaxial Strain Case'); 1014 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 1015 | 1016 | figure; colormap gray; set(gcf,'Color','white'); 1017 | subplot(1,2,1); contourf(handles.x, handles.y, handles.us, 10,'LineWidth',0); colorbar; h5= colorbar; 1018 | set(get(h5,'title'),'string',' Pixel','fontweight','b','fontsize',12); 1019 | axis image; title('u_1, Shear Case'); 1020 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 1021 | subplot(1,2,2); contourf(handles.x, handles.y, handles.vs, 10,'LineWidth',0); colorbar; h6= colorbar; 1022 | set(get(h6,'title'),'string',' Pixel','fontweight','b','fontsize',12); 1023 | axis image; title('u_2, Shear Case'); 1024 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 1025 | 1026 | figure; colormap gray; set(gcf,'Color','white'); 1027 | subplot(1,2,1); contourf(handles.x, handles.y, handles.up, 10,'LineWidth',0); colorbar; h7= colorbar; 1028 | set(get(h7,'title'),'string',' Pixel','fontweight','b','fontsize',12); 1029 | axis image; title('u_1, Point Load Case'); 1030 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 1031 | subplot(1,2,2); contourf(handles.x, handles.y, handles.vp, 10,'LineWidth',0); colorbar; h8= colorbar; 1032 | set(get(h8,'title'),'string',' Pixel','fontweight','b','fontsize',12); 1033 | axis image; title('u_2, Point Load Case'); 1034 | xlabel('x_1 (Pixel)','fontweight','normal'); ylabel('x_2 (Pixel)','fontweight','normal'); 1035 | 1036 | displchoice = questdlg('Would you like to save the displacement fields?', ... 1037 | 'Save displacements', ... 1038 | 'Save to *.tif','Save to *.mat','No','No'); 1039 | % Handle response 1040 | switch displchoice 1041 | case 'Save to *.tif' 1042 | imwrite(uint8(255*(u1_translation-min(u1_translation(:)))/(max(u1_translation(:))-min(u1_translation(:)))),'u1_translation.tif'); 1043 | imwrite(uint8(255*(u2_translation-min(u2_translation(:)))/(max(u2_translation(:))-min(u2_translation(:)))),'u2_translation.tif'); 1044 | imwrite(uint8(255*(u1_strain-min(u1_strain(:)))/(max(u1_strain(:))-min(u1_strain(:)))),'u1_strain.tif'); 1045 | imwrite(uint8(255*(u2_strain-min(u2_strain(:)))/(max(u2_strain(:))-min(u2_strain(:)))),'u2_strain.tif'); 1046 | imwrite(uint8(255*(u1_shear-min(u1_shear(:)))/(max(u1_shear(:))-min(u1_shear(:)))),'u1_shear.tif'); 1047 | imwrite(uint8(255*(u2_shear-min(u2_shear(:)))/(max(u2_shear(:))-min(u2_shear(:)))),'u2_shear.tif'); 1048 | imwrite(uint8(255*(u1_pointload-min(u1_pointload(:)))/(max(u1_pointload(:))-min(u1_pointload(:)))),'u1_pointload.tif'); 1049 | imwrite(uint8(255*(u2_pointload-min(u2_pointload(:)))/(max(u2_pointload(:))-min(u2_pointload(:)))),'u2_pointload.tif'); 1050 | case 'Save to *.mat' 1051 | save('dispdata.mat','u1_translation','u2_translation','u1_strain','u2_strain','u1_shear','u2_shear','u1_pointload','u2_pointload'); 1052 | case 'No' 1053 | end 1054 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ## Important pages 2 | * [Download latest version v1.1!](https://github.com/FranckLab/DIC-Simulator/releases) 3 | * [FAQ](https://github.com/FranckLab/DIC-Simulator/blob/master/README.md#faq) 4 | * [Questions/Issues](https://github.com/FranckLab/DIC-Simulator/issues) 5 | * [Cite](https://github.com/FranckLab/DIC-Simulator/blob/master/README.md#cite) 6 | * [Franck Lab](http://franck.engin.brown.edu) 7 | 8 | ## Purpose 9 | The Digital Image Correlation (DIC) simulator is a Matlab-based GUI that assesses how “well” a particular user-provided image correlates given 4 different simulated displacement fields. The purpose of the simulator is to allow the user to optimize the speckle and intensity patterns in an image, without having to run experimentally-based calibration tests, but rather have Matlab simulate them. The DIC simulator performs the following steps: 10 | 11 | 1. User loads DIC image of interest 12 | 13 | 2. Matlab maps the intensities in the uploaded image (undeformed configuration) into a set of 4 different analytically predetermined deformation fields 14 | 15 | 3. A standard DIC algorithm correlates each image pair (deformed-undeformed config.) per given deformation field and returns the displacement matrices u1 and u2 16 | 17 | 4. The Matlab-GUI plots the determined displacement field as color contours, and as histograms of the error difference between the analytically-prescribed and DIC correlated displacement fields 18 | 19 | **Health Warning!** 20 | 21 | The algorithm expects the speckle pattern to cover the entire field-of-view of the image and will either error out or provide eroneous result if this is not the case. 22 | 23 | ## FAQ 24 | **The GUI looks squashed and button don't appear properly, what should I do?** 25 | 26 | The GUI in newer versions of Matlab and high resolution screens, can sometimes get squashed with various buttons and icons not appearing properly. The easiest way to solve this issue is to resize the GUI layout manually on your computer. Use the command `guide DIC_simulator.fig` and resize the buttons. 27 | 28 | 29 | **What is the recommended minimum size of the input image stack?** 30 | 31 | We recommend that the input image stack should have at least have 96 pixels in each dimension. 32 | 33 | 34 | ## Cite 35 | If used please cite: 36 | [Estrada, J., Franck, C.,”Intuitive Interface for the Quantitative Evaluation of Speckle Patterns for Use in Digital Image and Volume Correlation Techniques”, J. Applied Mechanics, 2015.](https://appliedmechanics.asmedigitalcollection.asme.org/article.aspx?articleid=2336782) 37 | 38 | ```bibtex 39 | @article{estrada2015intuitive, 40 | title={Intuitive Interface for the Quantitative Evaluation of Speckle Patterns for Use in Digital Image and Volume Correlation Techniques}, 41 | author={Estrada, Jonathan B and Franck, Christian}, 42 | journal={Journal of Applied Mechanics}, 43 | volume={82}, 44 | number={9}, 45 | pages={095001}, 46 | year={2015}, 47 | publisher={American Society of Mechanical Engineers} 48 | } 49 | ``` 50 | 51 | ## Contact and support 52 | For questions, please first refer to [FAQ](https://github.com/FranckLab/DIC-Simulator/blob/master/README.md#faq) and [Questions/Issues](https://github.com/FranckLab/DIC-Simulator/issues). Add a new question if similar issue hasn't been reported. We shall help you at the earliest. The author's contact information can be found at [Franck Lab](http://franck.engin.brown.edu). 53 | --------------------------------------------------------------------------------