from HighCorr High Temperature Digital Image Correlation Software by Robert Thompson
Software optimized to measure the coefficient of thermal expansion using digital image correlation.

RJT_strain_1D.m
% Code to calculate the 1D strain from the 2D displacement field
% Programmed by Rob
% Last revision: 4/15/2007


clear all;
clc;


% Close the current figure if open and caution user

caut_selection = menu(sprintf('Caution:  After this prompt, Matlab may appear unresponsive for a few seconds while the data is being loaded and analyzed.\n  Minimizing the Matlab Command Window, so information regarding the status of the fit is suppressed, will make the analysis run considerably faster.\n  In any event, please be patient.  If no results are shown after 30 seconds, then use Control-C to restart the analysis.'),'OK');
close(gcf);

% Load the valid displacement field data and temperature_image files

load validx.txt;
load displx.txt;
load filenamelist;
load temperature_image.txt;

[imagenumber filename_string_length] = size(filenamelist);

% Initialize figure

x5 = figure;
set(x5,'Position',[150,50,800,600]);   % [left bottom width height]

% Perform a robust and a least squares linear fit of u vs. x to find du/dx, which is the x component of strain

minmindisplx = min(min(displx));
maxmaxdisplx = max(max(displx));

for i = 1:imagenumber;

    plot(validx(:,i),displx(:,i),'.r');
    axis([0 3000 minmindisplx maxmaxdisplx]);
    axis 'auto x';
    validx(:,i) = validx(:,i);
    displx(:,i) = displx(:,i);

    % First do the robust fit (and plot); then provide initial guesses and do the lsq (poly) fit (do not plot...slows down analysis)

    w = robustfit(validx(:,i),displx(:,i));
    ydatafit = w(2)*validx(:,i)+w(1);
    slope_robust(i) = w(2)*100; % Keep strain in units of [%] always

    x = polyfit(validx(:,i),displx(:,i),1);
    hold on;

    plot(validx(:,i),ydatafit,'k','linewidth',2);
    xlabel('x-Location on Image [Pixels]');
    ylabel('x-Component of Displacement [Pixels]');
    box on;
    drawnow;
    hold off;
    title([sprintf('Strain Calculation for Image: %10s',filenamelist(i,:)),'      Temperature [\circC]: ',num2str(temperature_image(i,2),'%10.1f')]); % ,'fontsize',18,'fontweight','bold')
    drawnow;
    slope_lsq(i) = x(1)*100; % Keep strain in units of [%] always

    % Save either a selected group (if imagenumber > 10) or all fitting results

    if imagenumber <= 10;

        fig_save_string = ['displacement_fit_',num2str(i),'.fig'];
        tiff_save_string = ['displacement_fit_',num2str(i)];

        saveas(gcf,fig_save_string);
        print('-dtiff','-r300',tiff_save_string);

    else;

        v = round(imagenumber/3)-1;

        if i == 1;

            saveas(gcf,'displacement_fit_1.fig');
            print -dtiff -r300 displacement_fit_1;
        end;

        if i == v;

            saveas(gcf,'displacement_fit_2.fig');
            print -dtiff -r300 displacement_fit_2;
        end;

        if i == 2*v;

            saveas(gcf,'displacement_fit_3.fig');
            print -dtiff -r300 displacement_fit_3;
        end;

        if i == 3*v;

            saveas(gcf,'displacement_fit_4.fig');
            print -dtiff -r300 displacement_fit_4;
        end;

        if i == imagenumber;

            saveas(gcf,'displacement_fit_5.fig');
            print -dtiff -r300 displacement_fit_5;
        end;
    end;
end;

% Plot and then save the raw thermal strain vs. temperature results

R_temp = figure;
AH = axes('fontsize',18,'fontweight','bold');
hold on;
set(R_temp,'Position',[150,50,800,600]); % [left bottom width height]
plot(temperature_image(:,2),slope_robust,'.g');
plot(temperature_image(:,2),slope_lsq,'.b');
xlabel('Temperature [\circC]');
ylabel('Thermal Strain [%]');
title('Raw Correlation Strain Output');
legend('Robust Fit','LSQ Fit',2);
box on;

% Prompt user for what strain data to save

robust_lsq_selection = menu(sprintf('Would you like to use the strain data from the Robust or the LSQ fit?'),'Robust','LSQ');

if robust_lsq_selection == 1;

    strain_temperature_data_x = [temperature_image(:,2) slope_robust'];
    save raw_strain_temperature.txt strain_temperature_data_x -ascii -tabs;
end;

if robust_lsq_selection == 2;

    strain_temperature_data_x = [temperature_image(:,2) slope_lsq'];
    save raw_strain_temperature.txt strain_temperature_data_x -ascii -tabs;
end;

close(gcf);

% Fit a line to the selected strain results and then replot

warning off MATLAB:polyfit:RepeatedPointsOrRescale;
line_coeffs = polyfit(strain_temperature_data_x(:,1),strain_temperature_data_x(:,2),1);
strain_line_fit = polyval(line_coeffs,strain_temperature_data_x(:,1));

R = figure;
AH = axes('fontsize',18,'fontweight','bold');
hold on;
set(R,'Position',[150,50,800,600]); % [left bottom width height]
plot(temperature_image(:,2),slope_robust,'.g');
plot(temperature_image(:,2),slope_lsq,'.b');
plot(temperature_image(:,2),strain_line_fit,'k','linewidth',1);
xlabel('Temperature [\circC]');
ylabel('Thermal Strain [%]');
title('Raw Correlation Strain Output');
legend('Robust','LSQ',['Linear Fit Slope: ',num2str(round(1e6*line_coeffs(:,1))/1e6)],2);
box on;

saveas(R,'strain_temperature_robust_lsq.fig');
print -dtiff -r300 strain_temperature_robust_lsq;

Contact us at files@mathworks.com