How to measure deformation/elongation between different images?

27 vues (au cours des 30 derniers jours)
Astrit Imeri
Astrit Imeri le 18 Oct 2021
Commenté : Image Analyst le 18 Oct 2021
Hello all,
I am video recording deformation/elongation testing of a "dog-bone" plastic specimen and then converting it to pictures. I want to measure the elongation at each picture in reference with the first picture. However, I want to track only the changes in the narrow area i.e the rectangular part. Because of deformation, that narrow area elongates in one side and shorten in the other one. My question is how to extract only this narrow area, and how to track elongation of the narrow area. Further I want to automate this process for all of the picture.
Attached you will find two frames from the testing. One is at the beginning, i.e my reference picture and the other is just before final rupture.

Réponses (1)

Image Analyst
Image Analyst le 18 Oct 2021
Try this:
% Demo by Image Analyst
clc; % Clear the command window.
close all; % Close all figures (except those of imtool.)
clear; % Erase all existing variables. Or clearvars if you want.
workspace; % Make sure the workspace panel is showing.
format long g;
format compact;
fontSize = 20;
markerSize = 40;
%--------------------------------------------------------------------------------------------------------
% READ IN IMAGE
fileName = 'Frame 0358.png';
grayImage = imread(fileName);
% Get the dimensions of the image.
% numberOfColorChannels should be = 1 for a gray scale image, and 3 for an RGB color image.
[rows, columns, numberOfColorChannels] = size(grayImage)
if numberOfColorChannels > 1
% It's not really gray scale like we expected - it's color.
% Extract the red channel (so the magenta lines will be white).
grayImage = grayImage(:, :, 1);
end
%--------------------------------------------------------------------------------------------------------
% Display the image.
subplot(2, 3, 1);
imshow(grayImage, []);
impixelinfo;
axis('on', 'image');
title('Original Image', 'FontSize', fontSize, 'Interpreter', 'None');
hold on
drawnow;
% Maximize window.
g = gcf;
g.WindowState = 'maximized'
drawnow;
% Get rid of garbage in last two rows because the poster posted
% a screenshot instead of the actual image.
grayImage(end - 1, :) = grayImage(end - 2, :);
grayImage(end, :) = grayImage(end - 2, :);
% Extract the middle
col1 = 300;
col2 = 400;
xline(col1, 'Color', 'r', 'LineWidth', 2)
xline(col2, 'Color', 'r', 'LineWidth', 2)
grayImage = grayImage(:, col1:col2);
% Display the image.
subplot(2, 3, 2);
imshow(grayImage, []);
impixelinfo;
axis('on', 'image');
title('Cropped Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Need to background correct so we can do a global threshold.
verticalProfile = mean(grayImage, 2);
subplot(2, 3, 3);
plot(verticalProfile, 'b-', 'LineWidth', 2);
grid on;
hold on;
verticalProfile = movmax(verticalProfile, 13);
plot(verticalProfile, 'r-', 'LineWidth', 2);
% Fit to a quadratic.
xFit = 1 : length(verticalProfile);
coefficients = polyfit(xFit, verticalProfile, 6)
[rows, columns] = size(grayImage );
yFit = polyval(coefficients, xFit);
plot(yFit, 'g-', 'LineWidth', 2);
% Divide image by the background.
backgroundImage = repmat(yFit(:), [1, columns]);
% Display the image.
subplot(2, 3, 4);
imshow(backgroundImage, [0, 255]);
impixelinfo;
axis('on', 'image');
title('Background Image', 'FontSize', fontSize, 'Interpreter', 'None');
% Display the background corrected image.
subplot(2, 3, 5);
grayImage = uint8(max(backgroundImage(:)) * double(grayImage) ./ backgroundImage);
imshow(grayImage, [0, 255]);
impixelinfo;
axis('on', 'image');
title('Background Corrected Image', 'FontSize', fontSize, 'Interpreter', 'None');
verticalProfile = mean(grayImage, 2);
subplot(2, 3, 6);
plot(verticalProfile, 'b-', 'LineWidth', 2);
grid on;
% Find where the intensity falls below threshold.
threshold = 175;
row1 = find(verticalProfile < threshold, 1, 'first')
row2 = find(verticalProfile < threshold, 1, 'last')
width = row2 - row1;
caption = sprintf('Width = %d rows', width);
title(caption, 'FontSize', fontSize, 'Interpreter', 'None');
% Draw on image #2
subplot(2, 3, 2);
yline(row1, 'Color', 'r', 'LineWidth', 2)
yline(row2, 'Color', 'r', 'LineWidth', 2)
  2 commentaires
Astrit Imeri
Astrit Imeri le 18 Oct 2021
Thank you for your reply. Could I make so the two red vertical always hit on the tangent between the curvature and the straight part? Picture attached.
Image Analyst
Image Analyst le 18 Oct 2021
Sure. You'd have to then binarize the image and find the top and bottom rows at each column and fit the middle part to a line. Then find out where the actual deviates from the fit by more than your tolerance.

Connectez-vous pour commenter.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by