Code covered by the BSD License  

Highlights from
Improved Digital Image Correlation (DIC)

5.0 | 8 ratings Rate this file 236 Downloads (last 30 days) File Size: 11.8 MB File ID: #43073 Version: 4.2
image thumbnail

Improved Digital Image Correlation (DIC)



14 Aug 2013 (Updated )

Calculate full-field displacements and strains from a set of images with a random speckle pattern.

| Watch this File

File Information

Digital Image Correlation (DIC) is an optical, non-contact method to measure full-field displacements and strains. The only requirement is that the test specimen has a random speckle pattern on its surface, either generated by the experimentalist (i.e. random paint pattern) or occurring naturally (i.e. surface texture at large magnifications). There is no inherent length scale to DIC - by choosing the appropriate magnification of images and the corresponding speckle size, DIC can be used to measure displacements from the meter scale to the micron scale.
This set of Matlab .m files forms a complete DIC code. Given a set of images taken periodically during deformation of a specimen, this code will analyze the images and output full-field displacements and full field strains over the field of view captured in the images. In contrast to commercially available DIC software, this code can be fully customized by the user by editing the .m files directly.
Comments and questions about the code are welcomed. Please contact the author, Elizabeth Jones, at
If you would like to cite this code, please use the following two citations. The first is a peer-reviewed article in Experimental Mechanics that describes the basic algorithms used in the code. The second refers readers to this website, so that this DIC code can be more freely disseminated.
Jones E.M.C., Silberstein M.N., White, S.R., Sottos, N.R. In Situ Measurements of Strains in Composite Battery Electrodes during Electrochemical Cycling. Experimental Mechanics (2014) 54:971-985
Jones E.M.C. Improved digital image correlation (2013).


Matlab Parfor Progress2, Freeze Colors / Unfreeze Colors, and Digital Image Correlation And Tracking inspired this file.

Required Products Image Processing Toolbox
Parallel Computing Toolbox
Statistics and Machine Learning Toolbox
MATLAB release MATLAB 8.4 (R2014b)
MATLAB Search Path
/DIC files
Other requirements Version 1: Mac R2011a, PC with R2011a, PC with R2012b. Versions 2 & 3: PC with R2012b and R2014b. Version 4: PC with R2014b.
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (35)
22 May 2015 Elizabeth Jones


In addition to fixing the bug with movie_GUI, V4b also includes a compatibility feature so that images correlated in V3 can be viewed using the V4 of the visualize_data_GUI function.

Though the images do not need to be recorrlated (i.e. correlate_images_GUI does not need to be re-run in V4 if it was previously run in V3), the function compute_data_GUI must be re-run in V4 first.

All other aspects of V4b are the same as V4.

Comment only
22 May 2015 Elizabeth Jones

Version 4b of the code fixes a bug in movie_GUI that resulted from moving from V3 to V4. All other aspects of V4b are the same as V4.

Comment only
01 May 2015 Elizabeth Jones

Hi Matthieu,

I think I have fixed a couple of key functions that will allow you to use V4 "visualize_data_GUI" to look at data correlated with V3. If you send me an email, I'll send you the updated files for you to try out. If there are not further bugs with them, I'll post them online for everyone.


Comment only
01 May 2015 Elizabeth Jones

Hi Matthieu,

Thanks for your question. Did you correlate the images with V3 of the code, and then use V4 to visualize the data? If so, the issue is that V4 is not compatible with data correlated with V3. To confirm this is the issue, load the file "disp_reduced_data" from the correlation output. If the variables "dispx_reduced" and "dispy_reduced" load into the workspace, then you used V3 (or older) to correlate the images. You need the variables "dispx_reduced_raw", "dispx_reduced_interp", etc. (with the "_raw" or "_inter"), as these are the file that V4 is expecting. To fix it, you can either re-correlate the images with V4 of the code, or you can trick the code into thinking you have correct variables, by renaming "dispx_reduced" to "dispx_reduced_raw" and creating an empty variable for "dispx_reduced_interp" and then resaving the file "disp_reduced_data". Please let me know if this fixes the problem or if you have further questions.


Comment only
30 Apr 2015 Matthieu Roché

Under OSX 10.10.3. Hopefully I told you everything this time :)

Comment only
30 Apr 2015 Matthieu Roché

Forgot to tell you that I run the code with MatLab 2014b.

Comment only
30 Apr 2015 Matthieu Roché

Dear Elisabeth,

I have just downloaded v4 of the code, and I get a bug when I want to use visualize_data_GUI. I am told the following:

Error in load_computed_data (line 10)
try %Try loading the smoothed data and strains

Output argument "dispx_reduced_raw" (and maybe others) not assigned during call to
"/Users/matthieu/Documents/MATLAB/DIC/DIC files/load_computed_data.m>load_computed_data".

Error in visualize_data_GUI>visualize_data_GUI_OpeningFcn (line 83)

Error in gui_mainfcn (line 220)
feval(gui_State.gui_OpeningFcn, gui_hFigure, [], guidata(gui_hFigure), varargin{:});

Error in visualize_data_GUI (line 42)
gui_mainfcn(gui_State, varargin{:});

Before this, I have used the image_setup_GUI and the correlate_images_GUI to get an idea of how well the images correlate. I am basically following the steps of your tutorial.

Is the error I experience a bug or am I doing somethig wrong? Note that these steps worked with V3.

Thanks in advance!

Best regards


Comment only
22 Apr 2015 Elizabeth Jones

Version 4 uploaded on 22 April 2015 fixes an error with plotting contour plots over a background image and an error with plotting strain contours specifically over a deformed grid (opposed to reference grid). V4 also improves the correlation of reduced images. See documentation for more details.

Comment only
28 Jan 2015 Elizabeth Jones

An error was discovered in Version 2 of the code involving smoothing the displacements after deleting some grid points using the "delete_data_GUI". Specifically, the following error would arise if two or more complete rows of grid points were deleted from the bottom of the region of interest:

Error using smooth_moving_average_V2>smooth_moving_average_loop (line 187). Index exceeds matrix dimensions.

This error was related to a typographical error in the function "pad_disp_setup." In Version 2, line 66 erroneously read:

Btemp = find(ind_col == B);

In Version 3, this line was corrected to read:

Btemp = find(ind_row == B);

Current users of Version 2 of the code can fix this error by simply changing line 66 of "pad_disp_setup" as outlined above, without needing to download and install Version 3 of the code.

Thank you,

Comment only
28 Jan 2015 Elizabeth Jones

Hi Wenxue,

I have not generated simulated speckle patterns before. When I evaluated the accuracy and precision of my DIC code, I used images generated for the DIC Challenge sponsored by the Society of Experimental Mechanics (SEM).

Thank you,

Comment only
28 Jan 2015 Elizabeth Jones

Hi Salman,

I apologize for the delayed response; I did not receive email notification that a new comment had been posted on File Exchange.

My code is designed to work best with rectangular regions of interest (ROI), but with a little extra work, you can create a roughly circular ROI. When you run "correlate_images_GUI", first define a rectangular ROI that entirely encompasses the desired circular ROI. When the dialog box appears asking what you'd like to do with the grid, select "Remove points." Then delete groups of points that lie outside the circular ROI. The code will then compute the displacements on the remaining grid points that are within the circular ROI. Because removing groups of points like this can be a tedious process, you may consider modifying the function "grid_generator_GUI_compatible_3" in order to define a circular ROI a priori if you will be requiring a circular ROI frequently.

Thank you,

Comment only
28 Jan 2015 Elizabeth Jones

Hi Irene,

You may set the search zone to any integer value in the "correlate_images_GUI." See Sec. 8.2.3 in the documentation for my recommendations and suggestions regarding changing the search zone size versus correlating reduced images in order to capture large displacements.

Regarding the subset size, I believe the code would produce the same results if it cropped a small subset in the deformed image and a larger subset in the reference image (as it is programmed now) or if it did the reverse and cropped a small subset in the reference image and a larger subset in the deformed image. The difference would be accounted for in the calculation of the displacements. If you would like to discuss this subtlety further, I would be happy to correspond by email.

Thank you,

Comment only
17 Jan 2015 Wenxue Zhang

Dear Elizabeth Jones
I'm a student studying DIC algorithm not too long.
I want to know how to generate the simulated speckle images,with different displacment field.
Thanks for your enthusiastic help.

29 Dec 2014 Irene

Irene (view profile)

Dear Elizabeth Jones,
I'm a student using your useful code, but I have some questions.

I would like to know if one can change the size of the SEARCH ZONE and how to do this.

Moreover, I've read on your documentation that during the correlation process this code takes A SUBSET of pixels around the control point in the DEFORMED IMAGE and a LARGER SUBSET around the corresponding control point in the REFERENCE IMAGE. That's true? So the code starts from the deformed image and ''goes back'' to the reference image. I don't understand this process...
I asked you this because I knew that the correlation process starts from a subset around the control point in the reference image and then a larger subset is taken around the corresponding control point in the deformed image.
Is there a difference between this two proceedings?

Thank you for your help,

Comment only
29 Nov 2014 salman

salman (view profile)

Dear Elizabeth Jones,

I was trying to find a matlab code for the bulging test using DIC and I came across your code.

I really liked your work.

Could you please help me, I wanted to know how to implement this code for circular cross sections ?

It would be of great help.

Thank you,
Salman Khaleeq

Comment only
11 Sep 2014 Elizabeth Jones

Hi Jorge,

Yes, you can get the average values from the plot generated using the "Spatial Average" function. Simply save the plot, close out of the GUI, open the plot, and then use the following code:

ax = gca; %Gets the current axis
objs = get(ax,'children'); %Gets the objects of the current axis
y_data = get(objs,'ydata'); %Gets the y-data from the objects, i.e. the average strain values

The above method is a general method that you can use to get the data from any plot in Matlab. I have considered making an option directly in the GUI to save the data as a .mat file in addition to plotting the data, but as of now, I have not implemented this functionality. However, the method described above will work with little extra effort.


Comment only
10 Sep 2014 jorge

jorge (view profile)

Hello Elizabeth,

I would like to know if it´s possible to get a list of average values of strain over entire images. i mean, can i get the values of the average strain plotted in spatial Average plots?

Comment only
14 May 2014 Alberto

Yes, thank you very much Elizabeth! More or less I've managed to get what I wanted.



13 May 2014 Elizabeth Jones

Hi Alberto,

I am not familiar with the PIVMat Toolbox, so I am not sure what the best way is to reformat the data from my DIC code for use with the PIVMat Toolbox. However, from your description, it looks like you need the x- and y-coordinates of the control points and the u- and v- components of the displacements. (I assume you want the displacement components when you say velocity components?) The grid coordinates are found in the .mat file “grid_data”, and the displacement components are found in the .mat file “disp_raw_data” (for the raw correlation data) and “disp_smooth_data” (for the smoothed displacement field, if you have run “compute_data_GUI”). Does this provide the information you need?


Comment only
07 May 2014 Alberto

Hi Elizabeth!

I am using your code so as to then post process the vector field with PIVMat Toolbox to reconstruct the height of the surface, but the latter (in particular, the function 'plotvec.m') requires an specific format for the .mat files to work. It includes the x and y coordinates, the x and y velocity components, etc. :

For vector fields, the PIVMat structure F contains the following fields:
x,y vectors containing the X and Y coordinates
vx,vy (vz) matrices of the x, y (and z) components of the velocity
ysign string, upward or downward Y axis
namevx, unitvx, namex, unitx... strings
name name of the VEC/VC7 file from which originates V
setname name of the parent directory (called 'SET' in DaVis)
Attributes Additional informations from DaVis (see getattribute)
choice An array of 6 integers, giving the 1st, 2nd, 3rd, 4th choice vectors, the number of filled/processed vectors and the number of missing vectors.
history Remind from which command V has been obtained

Do you know if there is a simple way to get this format from the files your code provide? If not, could you tell me in which files I can find the information I need?

Thank you in advance.

Best regards,


22 Apr 2014 Deborah

Thank you very much Elizabeth!

Comment only
18 Apr 2014 Elizabeth Jones

Hi Deborah,

Poisson's ratio is the negative of the ratio of the axial strain to the transverse strain when a specimen is undergoing uniaxial tension or uniaxial compression. If the direction of force is, for example, in the y-direction, then Poisson's ratio = -e_yy / e_xx. Assuming you don't have plastic deformation, using the large strains (E_yy and E_xx) will give the same result.

To access the small and large strains, load "DU_data" into your workspace. All of the strain matrices are in the structures "large_strain" and "small_strain".


Comment only
17 Apr 2014 Deborah

Hi Elizabeth!

I wanted to know if it is possible to calculate the poisson's ratio from the large strain and small strain values, Exx, Eyy and exx, eyy.

hope to hear from you soon!

thank you,

11 Apr 2014 Marcraven

Hi again Elisabeth,

Thank you for your previous answer, that was exactly what I needed.

I expose my new doubts:

In the dispx_raw and dispy_raw matrixes, the element number 1 is the top left and the last is the bottom right of the correlation? If so: The sequence is row by row or column by column?

I am trying to remove the rigid body displacement from my correlation by taking the first element displacement and substract it from every other element displacement in every image.
This would theoretically give me just the relative displacement between the first element and the rest. Am I right?

Best regards,

Comment only
11 Apr 2014 Marcraven  
11 Mar 2014 Di

Di (view profile)

02 Jan 2014 Elizabeth Jones

Hi Stephen,

You have the choice to run the code in serial mode or in parallel mode. The benefit to running the code in parallel mode is the reduced computation time, but it does require the Parallel Computing Toolbox. If you do not have the Parallel Computing Toolbox, you may run the code in serial mode. You'll get the same results, but it will take longer to process large batches of images.


Comment only
02 Jan 2014 Stephen


I am using a student license of MATLAB, and I do not have the parallel computing toolbox. Is the parallel computing merely an option, or will I require the toolbox to run the code at all?


Comment only
04 Dec 2013 Elizabeth Jones

Hi Marcraven,

Thanks for your interest in my DIC code. There are two principle displacement data files. The first, disp_raw_data.mat, is generated when you run “correlate_images_GUI”, and is a calculation of the displacements before any smoothing has been done. These displacements are in terms of pixels. The second, disp_smooth_data.mat, is generated when you run “compute_data_GUI.” These displacements are scaled and smoothed according to the parameters you set in “compute_data_GUI.”

To work with the raw displacements, type “load disp_raw_data” in the command window. Two variables, dispx_raw and dispy_raw, should now be in your workspace. These matrices are the horizontal (x) and vertical (y) displacements respectively. The rows of the matrices represent the control points from your correlation, and the columns represent the images that you correlated. For example, the x-displacements for image 5 would be the entire column 5 of dispx_raw.

Similarly, to work with the scaled and smoothed displacements, type “load disp_smooth_data” into the command window, and the two variables dispx_smooth and dispy_smooth will be in your workspace.

Please let me know if you have further questions.


Comment only
27 Nov 2013 Marcraven

Hello Elizabeth!

I have been using your code for the last two weeks and it is great! Thanks a lot.

By the way, I would like to use the displacement matrix to calculate the error of the correlation (max error and average). How is the displacement matrix called in your code?

Thanks a lot

26 Nov 2013 Elizabeth Jones

Hi Mikhail,

Thank you for your comments and suggestions. Most of the areas you suggest for improvement are parts of the code that I personally don’t use frequently (such as the delete_data_GUI, any stress calculations, correcting for rigid body motion in the displacements), and therefore they have not received as much attention as other portions of the code. You are always welcome to modify the code yourself, and if you’d like, I’d be happy to post any improvements to this site, so that other users can benefit as well.

Concerning your first comment, you need to be careful when performing multiple correlations on one set of images. You always need to set your working directory to the folder containing the images you wish to correlate, but after a correlation is complete, you can move all the data files generated during the correlation to a new folder. I recommend always starting a correlation with no files from previous correlations in the working folder. This will prevent you from seeing results from a previous correlation when you are trying to view results from a current correlation. Please let me know if you have further questions regarding this part of the code.

Thank you,

Comment only
17 Nov 2013 Mikhail Seleznev

Hello, Elizabeth!

Thank you very much for this work, you've done a great job!

I just wanted to add some notes/questions as a "non-professional" user, so may be someone will have a time for code improvement. Or find what I've didn't.

1. When you want to see the full-image correlation results (after initial guess finding), Visualize_data_GUI shows the results of previous calculations. So you have to start compute_data_GUI "blind", then visualize_data_GUI switch to the new result.

2 . There is no possibility of displacement correction (this function is present, for example, in VEDDAC software). It allows to remove the object moving component from the displacement data and consider only deformation-related displacement. Of course this function does not affect the calculation of deformation, but you can't estimate the deformation-related displacement, which is negligibly small against sample shift.

3 . Code delete_data_GUI is not very convenient to use:
- can't undo the action: one mistake and you have to start over;
- There is only one tool removing items - a task corners of the rectangle ;
- can't zoom in ;
- The images are not visible behind a dense grid;

4 It would be great to count stress tensor in the end. The code should be easy: we just need a strain tensor, Young's modulus and Poisson coefficient

Best regards,

17 Sep 2013 Elizabeth Jones

For users of Matlab 2013a and 2013b:

A change between Matlab 2012b, which was used to write this code, and 2013a/b causes the progress bar during the correlation of the images to not work properly when operating in parallel mode. To fix this issue, please download the latest version of the progress bar code from File Exchange number 35609 ( and replace the progress bar files included with the DIC codes with the new ones.


Comment only
11 Sep 2013 Elizabeth Jones

Hi Miguel,

We talked via email, but I wanted to share my comments with other users of this code.

1. Concerning choosing an appropriate subset size when using DIC, it is typically a subjective process, like I described in Sec. 5.3 and Sec. 6.4 of the documentation included with this code. There are, however, research efforts that look into more objective methods for determining the appropriate subset size, such as the references shown below. Note that this is not an exhaustive reference list on this topic.

Yaofeng, S. and Pang, J.H.L. Optics and Lasers in Engineering 45 (2007) 967-974

Pan, B., et. al. Optics Express 16 (2008) 7037-7048

2. If your sample does not cover the entire image, then you can select your grid of control points only over your region of interest. There is no reason to have control points on the image background.

3. The coefficient of thermal expansion of a material is a material property. I do not understand your comment about adjusting the CTE of copper.


Comment only
05 Sep 2013 Miguelcm90

Dear Friends,

I am a student user of this code. I would like to have more information about how it is the best way to decide the subset size. I am measuring the coeficient of thermal expansion of diferent materials, and this code is useful to calculate the displacements. It shows me clearly how are the displacements, but I have not too much idea how to decide and adapt the subset.

I am using pictures of 4272x2482 px Resolution.

In this picture is located the sample, so the grid is not in full picture. Should I do another thing instead correlate the full picture?.

Also, I know the CTE of Copper, which is 16 ppm/K but to be honest, I do not know how to adjust this parameter, or I have to correlate in another way.

Any help is welcome, and heartfelt thanks,


Comment only
15 Aug 2013 1.2

130814 - Edited the acknowledgements.

23 Sep 2014 1.4

130814 - Edited the acknowledgements.

11 Nov 2014 1.5

Version 2 of the code was released on 11 November 2014 and contains many improvements. See the "Updates" section of the documentation for more information.

12 Nov 2014 1.6

Version 2 of the code was released on 11 November 2014 and contains many improvements. See the "Updates" section of the documentation for more information.

28 Jan 2015 1.7

Version 3 corrects a typographical error in the function "pad_disp_setup." See updated documentation for more details.

22 Apr 2015 1.8

1) Fixed error when plotting contours over a background image. 2) Fixed error when plotting strain contour over a deformed grid. 3) Improved correlation of reduced images.

22 May 2015 4.2

V4.2 fixes a small bug in the movie_GUI that resulted from moving between V3 and V4. All other aspects of V4.2 are identical to V4.

22 May 2015 4.2

V4b fixes a bug in movie_GUI that resulted from moving from V3 to V4. It also includes a compatibility feature so that images correlated in V3 can be viewed using the V4 of the visualize_data_GUI function.

Contact us